aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-05-01 23:23:17 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-05-01 23:23:17 -0400
commit7c8c03bfc7b9f5211d8a69eab7fee99c9fb4f449 (patch)
treea5cee67325e50e893bf0cc0a0d060983a0df6653 /tools
parent6dc2cce9321198172cd96f955a5fc798a4cc35a6 (diff)
parentfd7647979a3948dae4fc6f25dbbdf9ba269bed78 (diff)
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates from Ingo Molnar: "The main changes in this cycle were: Kernel side changes: - Kprobes and uprobes changes: - Make their trampolines read-only while they are used - Make UPROBES_EVENTS default-y which is the distro practice - Apply misc fixes and robustization to probe point insertion. - add support for AMD IOMMU events - extend hw events on Intel Goldmont CPUs - ... plus misc fixes and updates. Tooling side changes: - support s390 jump instructions in perf annotate (Christian Borntraeger) - vendor hardware events updates (Andi Kleen) - add argument support for SDT events in powerpc (Ravi Bangoria) - beautify the statx syscall arguments in 'perf trace' (Arnaldo Carvalho de Melo) - handle inline functions in callchains (Jin Yao) - enable sorting by srcline as key (Milian Wolff) - add 'brstackinsn' field in 'perf script' to reuse the x86 instruction decoder used in the Intel PT code to study hot paths to samples (Andi Kleen) - add PERF_RECORD_NAMESPACES so that the kernel can record information required to associate samples to namespaces, helping in container problem characterization. (Hari Bathini) - allow sorting by symbol_size in 'perf report' and 'perf top' (Charles Baylis) - in perf stat, make system wide (-a) the default option if no target was specified and one of following conditions is met: - no workload specified (current behaviour) - a workload is specified but all requested events are system wide ones, like uncore ones. (Jiri Olsa) - ... plus lots of other updates, enhancements, cleanups and fixes" * 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (235 commits) perf tools: Fix the code to strip command name tools arch x86: Sync cpufeatures.h tools arch: Sync arch/x86/lib/memcpy_64.S with the kernel tools: Update asm-generic/mman-common.h copy from the kernel perf tools: Use just forward declarations for struct thread where possible perf tools: Add the right header to obtain PERF_ALIGN() perf tools: Remove poll.h and wait.h from util.h perf tools: Remove string.h, unistd.h and sys/stat.h from util.h perf tools: Remove stale prototypes from builtin.h perf tools: Remove string.h from util.h perf tools: Remove sys/ioctl.h from util.h perf tools: Remove a few more needless includes from util.h perf tools: Include sys/param.h where needed perf callchain: Move callchain specific routines from util.[ch] perf tools: Add compress.h for the *_decompress_to_file() headers perf mem: Fix display of data source snoop indication perf debug: Move dump_stack() and sighandler_dump_stack() to debug.h perf kvm: Make function only used by 'perf kvm' static perf tools: Move timestamp routines from util.h to time-utils.h perf tools: Move units conversion/formatting routines to separate object ...
Diffstat (limited to 'tools')
-rw-r--r--tools/arch/arm/include/uapi/asm/kvm.h13
-rw-r--r--tools/arch/arm64/include/uapi/asm/kvm.h13
-rw-r--r--tools/arch/powerpc/include/uapi/asm/kvm.h22
-rw-r--r--tools/arch/x86/include/asm/atomic.h7
-rw-r--r--tools/arch/x86/include/asm/cmpxchg.h89
-rw-r--r--tools/arch/x86/include/asm/cpufeatures.h9
-rw-r--r--tools/arch/x86/lib/memcpy_64.S2
-rw-r--r--tools/build/Makefile.feature1
-rw-r--r--tools/build/feature/Makefile18
-rw-r--r--tools/build/feature/test-all.c5
-rw-r--r--tools/build/feature/test-sched_getcpu.c7
-rw-r--r--tools/include/asm-generic/atomic-gcc.h8
-rw-r--r--tools/include/linux/atomic.h6
-rw-r--r--tools/include/linux/bug.h10
-rw-r--r--tools/include/linux/compiler-gcc.h7
-rw-r--r--tools/include/linux/compiler.h9
-rw-r--r--tools/include/linux/hashtable.h4
-rw-r--r--tools/include/linux/kernel.h7
-rw-r--r--tools/include/linux/log2.h3
-rw-r--r--tools/include/linux/refcount.h151
-rw-r--r--tools/include/linux/types.h1
-rw-r--r--tools/include/uapi/linux/fcntl.h72
-rw-r--r--tools/include/uapi/linux/perf_event.h33
-rw-r--r--tools/include/uapi/linux/stat.h177
-rw-r--r--tools/lib/api/fs/fs.c29
-rw-r--r--tools/lib/api/fs/fs.h1
-rw-r--r--tools/lib/subcmd/help.h1
-rw-r--r--tools/lib/symbol/kallsyms.c1
-rw-r--r--tools/objtool/builtin-check.c3
-rw-r--r--tools/objtool/objtool.c3
-rw-r--r--tools/perf/.gitignore2
-rw-r--r--tools/perf/Build1
-rw-r--r--tools/perf/Documentation/perf-ftrace.txt18
-rw-r--r--tools/perf/Documentation/perf-list.txt8
-rw-r--r--tools/perf/Documentation/perf-record.txt3
-rw-r--r--tools/perf/Documentation/perf-report.txt13
-rw-r--r--tools/perf/Documentation/perf-sched.txt4
-rw-r--r--tools/perf/Documentation/perf-script.txt16
-rw-r--r--tools/perf/Documentation/perf-stat.txt6
-rw-r--r--tools/perf/Documentation/perf-trace.txt3
-rw-r--r--tools/perf/Documentation/perf.data-file-format.txt19
-rw-r--r--tools/perf/MANIFEST5
-rw-r--r--tools/perf/Makefile.config39
-rw-r--r--tools/perf/arch/arm/util/cs-etm.c1
-rw-r--r--tools/perf/arch/arm/util/dwarf-regs.c4
-rw-r--r--tools/perf/arch/arm/util/unwind-libdw.c1
-rw-r--r--tools/perf/arch/arm64/util/dwarf-regs.c5
-rw-r--r--tools/perf/arch/arm64/util/unwind-libunwind.c2
-rw-r--r--tools/perf/arch/common.c2
-rw-r--r--tools/perf/arch/powerpc/util/dwarf-regs.c5
-rw-r--r--tools/perf/arch/powerpc/util/kvm-stat.c1
-rw-r--r--tools/perf/arch/powerpc/util/perf_regs.c112
-rw-r--r--tools/perf/arch/powerpc/util/sym-handling.c14
-rw-r--r--tools/perf/arch/s390/annotate/instructions.c30
-rw-r--r--tools/perf/arch/s390/util/kvm-stat.c1
-rw-r--r--tools/perf/arch/x86/entry/syscalls/syscall_64.tbl1
-rw-r--r--tools/perf/arch/x86/tests/intel-cqm.c3
-rw-r--r--tools/perf/arch/x86/tests/perf-time-to-tsc.c2
-rw-r--r--tools/perf/arch/x86/util/auxtrace.c1
-rw-r--r--tools/perf/arch/x86/util/intel-bts.c1
-rw-r--r--tools/perf/arch/x86/util/intel-pt.c1
-rw-r--r--tools/perf/arch/x86/util/kvm-stat.c1
-rw-r--r--tools/perf/arch/x86/util/perf_regs.c227
-rw-r--r--tools/perf/arch/x86/util/unwind-libdw.c1
-rw-r--r--tools/perf/bench/bench.h20
-rw-r--r--tools/perf/bench/futex-hash.c4
-rw-r--r--tools/perf/bench/futex-lock-pi.c4
-rw-r--r--tools/perf/bench/futex-requeue.c4
-rw-r--r--tools/perf/bench/futex-wake-parallel.c4
-rw-r--r--tools/perf/bench/futex-wake.c4
-rw-r--r--tools/perf/bench/futex.h10
-rw-r--r--tools/perf/bench/mem-functions.c5
-rw-r--r--tools/perf/bench/numa.c7
-rw-r--r--tools/perf/bench/sched-messaging.c3
-rw-r--r--tools/perf/bench/sched-pipe.c2
-rw-r--r--tools/perf/builtin-annotate.c6
-rw-r--r--tools/perf/builtin-bench.c12
-rw-r--r--tools/perf/builtin-buildid-cache.c5
-rw-r--r--tools/perf/builtin-buildid-list.c4
-rw-r--r--tools/perf/builtin-c2c.c12
-rw-r--r--tools/perf/builtin-config.c2
-rw-r--r--tools/perf/builtin-data.c9
-rw-r--r--tools/perf/builtin-diff.c5
-rw-r--r--tools/perf/builtin-evlist.c2
-rw-r--r--tools/perf/builtin-ftrace.c157
-rw-r--r--tools/perf/builtin-help.c25
-rw-r--r--tools/perf/builtin-inject.c20
-rw-r--r--tools/perf/builtin-kallsyms.c3
-rw-r--r--tools/perf/builtin-kmem.c10
-rw-r--r--tools/perf/builtin-kvm.c39
-rw-r--r--tools/perf/builtin-list.c16
-rw-r--r--tools/perf/builtin-lock.c32
-rw-r--r--tools/perf/builtin-mem.c12
-rw-r--r--tools/perf/builtin-probe.c12
-rw-r--r--tools/perf/builtin-record.c44
-rw-r--r--tools/perf/builtin-report.c17
-rw-r--r--tools/perf/builtin-sched.c37
-rw-r--r--tools/perf/builtin-script.c326
-rw-r--r--tools/perf/builtin-stat.c224
-rw-r--r--tools/perf/builtin-timechart.c28
-rw-r--r--tools/perf/builtin-top.c6
-rw-r--r--tools/perf/builtin-trace.c95
-rw-r--r--tools/perf/builtin-version.c6
-rw-r--r--tools/perf/builtin.h62
-rwxr-xr-xtools/perf/check-headers.sh2
-rw-r--r--tools/perf/command-list.txt1
-rw-r--r--tools/perf/perf.c129
-rw-r--r--tools/perf/perf.h1
-rw-r--r--tools/perf/pmu-events/arch/x86/broadwell/uncore.json278
-rw-r--r--tools/perf/pmu-events/arch/x86/broadwellde/uncore-cache.json28
-rw-r--r--tools/perf/pmu-events/arch/x86/broadwellde/uncore-memory.json29
-rw-r--r--tools/perf/pmu-events/arch/x86/broadwellde/uncore-power.json26
-rw-r--r--tools/perf/pmu-events/arch/x86/broadwellx/uncore-cache.json28
-rw-r--r--tools/perf/pmu-events/arch/x86/broadwellx/uncore-interconnect.json6
-rw-r--r--tools/perf/pmu-events/arch/x86/broadwellx/uncore-memory.json21
-rw-r--r--tools/perf/pmu-events/arch/x86/broadwellx/uncore-power.json26
-rw-r--r--tools/perf/pmu-events/arch/x86/haswell/uncore.json374
-rw-r--r--tools/perf/pmu-events/arch/x86/haswellx/uncore-cache.json28
-rw-r--r--tools/perf/pmu-events/arch/x86/haswellx/uncore-interconnect.json6
-rw-r--r--tools/perf/pmu-events/arch/x86/haswellx/uncore-memory.json21
-rw-r--r--tools/perf/pmu-events/arch/x86/haswellx/uncore-power.json26
-rw-r--r--tools/perf/pmu-events/arch/x86/ivybridge/uncore.json314
-rw-r--r--tools/perf/pmu-events/arch/x86/ivytown/uncore-cache.json22
-rw-r--r--tools/perf/pmu-events/arch/x86/ivytown/uncore-interconnect.json12
-rw-r--r--tools/perf/pmu-events/arch/x86/ivytown/uncore-memory.json19
-rw-r--r--tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json53
-rw-r--r--tools/perf/pmu-events/arch/x86/jaketown/uncore-cache.json13
-rw-r--r--tools/perf/pmu-events/arch/x86/jaketown/uncore-interconnect.json12
-rw-r--r--tools/perf/pmu-events/arch/x86/jaketown/uncore-memory.json21
-rw-r--r--tools/perf/pmu-events/arch/x86/jaketown/uncore-power.json53
-rw-r--r--tools/perf/pmu-events/arch/x86/mapfile.csv1
-rw-r--r--tools/perf/pmu-events/arch/x86/sandybridge/uncore.json314
-rw-r--r--tools/perf/pmu-events/arch/x86/skylake/uncore.json254
-rw-r--r--tools/perf/pmu-events/jevents.c28
-rw-r--r--tools/perf/pmu-events/jevents.h3
-rw-r--r--tools/perf/pmu-events/pmu-events.h2
-rw-r--r--tools/perf/tests/Build1
-rw-r--r--tools/perf/tests/attr.c6
-rw-r--r--tools/perf/tests/backward-ring-buffer.c1
-rw-r--r--tools/perf/tests/bpf.c4
-rw-r--r--tools/perf/tests/builtin-test.c9
-rw-r--r--tools/perf/tests/clang.c1
-rw-r--r--tools/perf/tests/code-reading.c7
-rw-r--r--tools/perf/tests/cpumap.c2
-rw-r--r--tools/perf/tests/dso-data.c2
-rw-r--r--tools/perf/tests/dwarf-unwind.c1
-rw-r--r--tools/perf/tests/event-times.c3
-rw-r--r--tools/perf/tests/evsel-roundtrip-name.c2
-rw-r--r--tools/perf/tests/expr.c56
-rw-r--r--tools/perf/tests/hists_common.c2
-rw-r--r--tools/perf/tests/hists_cumulate.c1
-rw-r--r--tools/perf/tests/hists_filter.c1
-rw-r--r--tools/perf/tests/hists_link.c2
-rw-r--r--tools/perf/tests/hists_output.c1
-rw-r--r--tools/perf/tests/is_printable_array.c3
-rw-r--r--tools/perf/tests/mmap-basic.c3
-rw-r--r--tools/perf/tests/mmap-thread-lookup.c2
-rw-r--r--tools/perf/tests/openat-syscall-all-cpus.c6
-rw-r--r--tools/perf/tests/openat-syscall-tp-fields.c1
-rw-r--r--tools/perf/tests/openat-syscall.c5
-rw-r--r--tools/perf/tests/parse-events.c8
-rw-r--r--tools/perf/tests/parse-no-sample-id-all.c1
-rw-r--r--tools/perf/tests/perf-record.c2
-rw-r--r--tools/perf/tests/pmu.c2
-rw-r--r--tools/perf/tests/sample-parsing.c2
-rw-r--r--tools/perf/tests/sdt.c3
-rw-r--r--tools/perf/tests/sw-clock.c2
-rw-r--r--tools/perf/tests/switch-tracking.c1
-rw-r--r--tools/perf/tests/task-exit.c1
-rw-r--r--tools/perf/tests/tests.h1
-rw-r--r--tools/perf/tests/thread-map.c6
-rw-r--r--tools/perf/tests/thread-mg-share.c12
-rw-r--r--tools/perf/tests/unit_number__scnprintf.c3
-rw-r--r--tools/perf/tests/vmlinux-kallsyms.c1
-rw-r--r--tools/perf/trace/beauty/Build1
-rw-r--r--tools/perf/trace/beauty/beauty.h24
-rw-r--r--tools/perf/trace/beauty/signum.c1
-rw-r--r--tools/perf/trace/beauty/statx.c72
-rw-r--r--tools/perf/ui/browser.c4
-rw-r--r--tools/perf/ui/browsers/annotate.c3
-rw-r--r--tools/perf/ui/browsers/header.c2
-rw-r--r--tools/perf/ui/browsers/hists.c193
-rw-r--r--tools/perf/ui/browsers/map.c2
-rw-r--r--tools/perf/ui/gtk/annotate.c3
-rw-r--r--tools/perf/ui/gtk/hists.c2
-rw-r--r--tools/perf/ui/hist.c1
-rw-r--r--tools/perf/ui/setup.c1
-rw-r--r--tools/perf/ui/stdio/hist.c91
-rw-r--r--tools/perf/ui/tui/setup.c1
-rw-r--r--tools/perf/util/Build11
-rw-r--r--tools/perf/util/alias.c78
-rw-r--r--tools/perf/util/annotate.c89
-rw-r--r--tools/perf/util/annotate.h2
-rw-r--r--tools/perf/util/auxtrace.c10
-rw-r--r--tools/perf/util/auxtrace.h1
-rw-r--r--tools/perf/util/bpf-loader.c3
-rw-r--r--tools/perf/util/bpf-loader.h2
-rw-r--r--tools/perf/util/bpf-prologue.c1
-rw-r--r--tools/perf/util/bpf-prologue.h2
-rw-r--r--tools/perf/util/build-id.c20
-rw-r--r--tools/perf/util/build-id.h4
-rw-r--r--tools/perf/util/c++/clang-c.h1
-rw-r--r--tools/perf/util/cache.h1
-rw-r--r--tools/perf/util/callchain.c271
-rw-r--r--tools/perf/util/callchain.h3
-rw-r--r--tools/perf/util/cgroup.c11
-rw-r--r--tools/perf/util/cgroup.h4
-rw-r--r--tools/perf/util/cloexec.c1
-rw-r--r--tools/perf/util/cloexec.h6
-rw-r--r--tools/perf/util/color.h2
-rw-r--r--tools/perf/util/comm.c17
-rw-r--r--tools/perf/util/compress.h12
-rw-r--r--tools/perf/util/config.c61
-rw-r--r--tools/perf/util/counts.c2
-rw-r--r--tools/perf/util/cpumap.c65
-rw-r--r--tools/perf/util/cpumap.h5
-rw-r--r--tools/perf/util/ctype.c2
-rw-r--r--tools/perf/util/data-convert-bt.c5
-rw-r--r--tools/perf/util/data.c1
-rw-r--r--tools/perf/util/debug.c37
-rw-r--r--tools/perf/util/debug.h3
-rw-r--r--tools/perf/util/demangle-java.c2
-rw-r--r--tools/perf/util/drv_configs.c1
-rw-r--r--tools/perf/util/dso.c14
-rw-r--r--tools/perf/util/dso.h4
-rw-r--r--tools/perf/util/dump-insn.c14
-rw-r--r--tools/perf/util/dump-insn.h22
-rw-r--r--tools/perf/util/dwarf-aux.c3
-rw-r--r--tools/perf/util/dwarf-regs.c1
-rw-r--r--tools/perf/util/env.c1
-rw-r--r--tools/perf/util/event.c179
-rw-r--r--tools/perf/util/event.h22
-rw-r--r--tools/perf/util/evlist.c36
-rw-r--r--tools/perf/util/evlist.h6
-rw-r--r--tools/perf/util/evsel.c24
-rw-r--r--tools/perf/util/evsel.h5
-rw-r--r--tools/perf/util/evsel_fprintf.c2
-rw-r--r--tools/perf/util/expr.h25
-rw-r--r--tools/perf/util/expr.y173
-rw-r--r--tools/perf/util/header.c20
-rw-r--r--tools/perf/util/help-unknown-cmd.c9
-rw-r--r--tools/perf/util/hist.c18
-rw-r--r--tools/perf/util/hist.h2
-rw-r--r--tools/perf/util/intel-bts.c2
-rw-r--r--tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c26
-rw-r--r--tools/perf/util/intel-pt.c1
-rw-r--r--tools/perf/util/jitdump.c7
-rw-r--r--tools/perf/util/llvm-utils.c1
-rw-r--r--tools/perf/util/lzma.c2
-rw-r--r--tools/perf/util/machine.c47
-rw-r--r--tools/perf/util/machine.h3
-rw-r--r--tools/perf/util/map.c15
-rw-r--r--tools/perf/util/map.h10
-rw-r--r--tools/perf/util/mem-events.c3
-rw-r--r--tools/perf/util/namespaces.c37
-rw-r--r--tools/perf/util/namespaces.h26
-rw-r--r--tools/perf/util/ordered-events.c5
-rw-r--r--tools/perf/util/parse-events.c92
-rw-r--r--tools/perf/util/parse-events.h30
-rw-r--r--tools/perf/util/parse-events.y73
-rw-r--r--tools/perf/util/path.c28
-rw-r--r--tools/perf/util/path.h9
-rw-r--r--tools/perf/util/perf-hooks.c1
-rw-r--r--tools/perf/util/perf_regs.c6
-rw-r--r--tools/perf/util/perf_regs.h7
-rw-r--r--tools/perf/util/pmu.c38
-rw-r--r--tools/perf/util/pmu.h6
-rw-r--r--tools/perf/util/print_binary.c55
-rw-r--r--tools/perf/util/print_binary.h28
-rw-r--r--tools/perf/util/probe-event.c29
-rw-r--r--tools/perf/util/probe-event.h7
-rw-r--r--tools/perf/util/probe-file.c218
-rw-r--r--tools/perf/util/probe-file.h8
-rw-r--r--tools/perf/util/probe-finder.c3
-rw-r--r--tools/perf/util/probe-finder.h2
-rw-r--r--tools/perf/util/python-ext-sources2
-rw-r--r--tools/perf/util/python.c14
-rw-r--r--tools/perf/util/quote.c1
-rw-r--r--tools/perf/util/record.c1
-rw-r--r--tools/perf/util/sane_ctype.h51
-rw-r--r--tools/perf/util/scripting-engines/trace-event-perl.c1
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c2
-rw-r--r--tools/perf/util/session.c54
-rw-r--r--tools/perf/util/session.h4
-rw-r--r--tools/perf/util/sort.c109
-rw-r--r--tools/perf/util/sort.h16
-rw-r--r--tools/perf/util/srcline.c248
-rw-r--r--tools/perf/util/srcline.h34
-rw-r--r--tools/perf/util/stat-shadow.c197
-rw-r--r--tools/perf/util/stat.c2
-rw-r--r--tools/perf/util/stat.h2
-rw-r--r--tools/perf/util/strbuf.c1
-rw-r--r--tools/perf/util/strfilter.c5
-rw-r--r--tools/perf/util/string.c24
-rw-r--r--tools/perf/util/string2.h42
-rw-r--r--tools/perf/util/strlist.c1
-rw-r--r--tools/perf/util/symbol-elf.c33
-rw-r--r--tools/perf/util/symbol-minimal.c8
-rw-r--r--tools/perf/util/symbol.c3
-rw-r--r--tools/perf/util/symbol.h8
-rw-r--r--tools/perf/util/term.c6
-rw-r--r--tools/perf/util/thread-stack.c1
-rw-r--r--tools/perf/util/thread.c52
-rw-r--r--tools/perf/util/thread.h10
-rw-r--r--tools/perf/util/thread_map.c22
-rw-r--r--tools/perf/util/thread_map.h4
-rw-r--r--tools/perf/util/time-utils.c25
-rw-r--r--tools/perf/util/time-utils.h7
-rw-r--r--tools/perf/util/tool.h2
-rw-r--r--tools/perf/util/top.h2
-rw-r--r--tools/perf/util/trace-event-parse.c3
-rw-r--r--tools/perf/util/trace-event-read.c4
-rw-r--r--tools/perf/util/units.c39
-rw-r--r--tools/perf/util/units.h10
-rw-r--r--tools/perf/util/unwind-libdw.c1
-rw-r--r--tools/perf/util/unwind-libdw.h6
-rw-r--r--tools/perf/util/unwind-libunwind-local.c2
-rw-r--r--tools/perf/util/unwind.h9
-rw-r--r--tools/perf/util/util.c278
-rw-r--r--tools/perf/util/util.h273
-rw-r--r--tools/perf/util/values.c63
-rw-r--r--tools/perf/util/vdso.c2
-rw-r--r--tools/perf/util/xyarray.c2
-rw-r--r--tools/perf/util/zlib.c1
-rw-r--r--tools/scripts/Makefile.include9
325 files changed, 7363 insertions, 1753 deletions
diff --git a/tools/arch/arm/include/uapi/asm/kvm.h b/tools/arch/arm/include/uapi/asm/kvm.h
index af05f8e0903e..6ebd3e6a1fd1 100644
--- a/tools/arch/arm/include/uapi/asm/kvm.h
+++ b/tools/arch/arm/include/uapi/asm/kvm.h
@@ -181,10 +181,23 @@ struct kvm_arch_memory_slot {
181#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2 181#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2
182#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32 182#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32
183#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) 183#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)
184#define KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT 32
185#define KVM_DEV_ARM_VGIC_V3_MPIDR_MASK \
186 (0xffffffffULL << KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT)
184#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0 187#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0
185#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT) 188#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)
189#define KVM_DEV_ARM_VGIC_SYSREG_INSTR_MASK (0xffff)
186#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3 190#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3
187#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 191#define KVM_DEV_ARM_VGIC_GRP_CTRL 4
192#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5
193#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6
194#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7
195#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10
196#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \
197 (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)
198#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x3ff
199#define VGIC_LEVEL_INFO_LINE_LEVEL 0
200
188#define KVM_DEV_ARM_VGIC_CTRL_INIT 0 201#define KVM_DEV_ARM_VGIC_CTRL_INIT 0
189 202
190/* KVM_IRQ_LINE irq field index values */ 203/* KVM_IRQ_LINE irq field index values */
diff --git a/tools/arch/arm64/include/uapi/asm/kvm.h b/tools/arch/arm64/include/uapi/asm/kvm.h
index 3051f86a9b5f..c2860358ae3e 100644
--- a/tools/arch/arm64/include/uapi/asm/kvm.h
+++ b/tools/arch/arm64/include/uapi/asm/kvm.h
@@ -201,10 +201,23 @@ struct kvm_arch_memory_slot {
201#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2 201#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2
202#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32 202#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32
203#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) 203#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)
204#define KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT 32
205#define KVM_DEV_ARM_VGIC_V3_MPIDR_MASK \
206 (0xffffffffULL << KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT)
204#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0 207#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0
205#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT) 208#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)
209#define KVM_DEV_ARM_VGIC_SYSREG_INSTR_MASK (0xffff)
206#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3 210#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3
207#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 211#define KVM_DEV_ARM_VGIC_GRP_CTRL 4
212#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5
213#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6
214#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7
215#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10
216#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \
217 (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)
218#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x3ff
219#define VGIC_LEVEL_INFO_LINE_LEVEL 0
220
208#define KVM_DEV_ARM_VGIC_CTRL_INIT 0 221#define KVM_DEV_ARM_VGIC_CTRL_INIT 0
209 222
210/* Device Control API on vcpu fd */ 223/* Device Control API on vcpu fd */
diff --git a/tools/arch/powerpc/include/uapi/asm/kvm.h b/tools/arch/powerpc/include/uapi/asm/kvm.h
index 3603b6f51b11..4edbe4bb0e8b 100644
--- a/tools/arch/powerpc/include/uapi/asm/kvm.h
+++ b/tools/arch/powerpc/include/uapi/asm/kvm.h
@@ -413,6 +413,26 @@ struct kvm_get_htab_header {
413 __u16 n_invalid; 413 __u16 n_invalid;
414}; 414};
415 415
416/* For KVM_PPC_CONFIGURE_V3_MMU */
417struct kvm_ppc_mmuv3_cfg {
418 __u64 flags;
419 __u64 process_table; /* second doubleword of partition table entry */
420};
421
422/* Flag values for KVM_PPC_CONFIGURE_V3_MMU */
423#define KVM_PPC_MMUV3_RADIX 1 /* 1 = radix mode, 0 = HPT */
424#define KVM_PPC_MMUV3_GTSE 2 /* global translation shootdown enb. */
425
426/* For KVM_PPC_GET_RMMU_INFO */
427struct kvm_ppc_rmmu_info {
428 struct kvm_ppc_radix_geom {
429 __u8 page_shift;
430 __u8 level_bits[4];
431 __u8 pad[3];
432 } geometries[8];
433 __u32 ap_encodings[8];
434};
435
416/* Per-vcpu XICS interrupt controller state */ 436/* Per-vcpu XICS interrupt controller state */
417#define KVM_REG_PPC_ICP_STATE (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x8c) 437#define KVM_REG_PPC_ICP_STATE (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x8c)
418 438
@@ -613,5 +633,7 @@ struct kvm_get_htab_header {
613#define KVM_XICS_LEVEL_SENSITIVE (1ULL << 40) 633#define KVM_XICS_LEVEL_SENSITIVE (1ULL << 40)
614#define KVM_XICS_MASKED (1ULL << 41) 634#define KVM_XICS_MASKED (1ULL << 41)
615#define KVM_XICS_PENDING (1ULL << 42) 635#define KVM_XICS_PENDING (1ULL << 42)
636#define KVM_XICS_PRESENTED (1ULL << 43)
637#define KVM_XICS_QUEUED (1ULL << 44)
616 638
617#endif /* __LINUX_KVM_POWERPC_H */ 639#endif /* __LINUX_KVM_POWERPC_H */
diff --git a/tools/arch/x86/include/asm/atomic.h b/tools/arch/x86/include/asm/atomic.h
index 059e33e94260..328eeceec709 100644
--- a/tools/arch/x86/include/asm/atomic.h
+++ b/tools/arch/x86/include/asm/atomic.h
@@ -7,6 +7,8 @@
7 7
8#define LOCK_PREFIX "\n\tlock; " 8#define LOCK_PREFIX "\n\tlock; "
9 9
10#include <asm/cmpxchg.h>
11
10/* 12/*
11 * Atomic operations that C can't guarantee us. Useful for 13 * Atomic operations that C can't guarantee us. Useful for
12 * resource counting etc.. 14 * resource counting etc..
@@ -62,4 +64,9 @@ static inline int atomic_dec_and_test(atomic_t *v)
62 GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e"); 64 GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
63} 65}
64 66
67static __always_inline int atomic_cmpxchg(atomic_t *v, int old, int new)
68{
69 return cmpxchg(&v->counter, old, new);
70}
71
65#endif /* _TOOLS_LINUX_ASM_X86_ATOMIC_H */ 72#endif /* _TOOLS_LINUX_ASM_X86_ATOMIC_H */
diff --git a/tools/arch/x86/include/asm/cmpxchg.h b/tools/arch/x86/include/asm/cmpxchg.h
new file mode 100644
index 000000000000..f5253260f3cc
--- /dev/null
+++ b/tools/arch/x86/include/asm/cmpxchg.h
@@ -0,0 +1,89 @@
1#ifndef TOOLS_ASM_X86_CMPXCHG_H
2#define TOOLS_ASM_X86_CMPXCHG_H
3
4#include <linux/compiler.h>
5
6/*
7 * Non-existant functions to indicate usage errors at link time
8 * (or compile-time if the compiler implements __compiletime_error().
9 */
10extern void __cmpxchg_wrong_size(void)
11 __compiletime_error("Bad argument size for cmpxchg");
12
13/*
14 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15 * -1 because sizeof will never return -1, thereby making those switch
16 * case statements guaranteeed dead code which the compiler will
17 * eliminate, and allowing the "missing symbol in the default case" to
18 * indicate a usage error.
19 */
20#define __X86_CASE_B 1
21#define __X86_CASE_W 2
22#define __X86_CASE_L 4
23#ifdef __x86_64__
24#define __X86_CASE_Q 8
25#else
26#define __X86_CASE_Q -1 /* sizeof will never return -1 */
27#endif
28
29/*
30 * Atomic compare and exchange. Compare OLD with MEM, if identical,
31 * store NEW in MEM. Return the initial value in MEM. Success is
32 * indicated by comparing RETURN with OLD.
33 */
34#define __raw_cmpxchg(ptr, old, new, size, lock) \
35({ \
36 __typeof__(*(ptr)) __ret; \
37 __typeof__(*(ptr)) __old = (old); \
38 __typeof__(*(ptr)) __new = (new); \
39 switch (size) { \
40 case __X86_CASE_B: \
41 { \
42 volatile u8 *__ptr = (volatile u8 *)(ptr); \
43 asm volatile(lock "cmpxchgb %2,%1" \
44 : "=a" (__ret), "+m" (*__ptr) \
45 : "q" (__new), "0" (__old) \
46 : "memory"); \
47 break; \
48 } \
49 case __X86_CASE_W: \
50 { \
51 volatile u16 *__ptr = (volatile u16 *)(ptr); \
52 asm volatile(lock "cmpxchgw %2,%1" \
53 : "=a" (__ret), "+m" (*__ptr) \
54 : "r" (__new), "0" (__old) \
55 : "memory"); \
56 break; \
57 } \
58 case __X86_CASE_L: \
59 { \
60 volatile u32 *__ptr = (volatile u32 *)(ptr); \
61 asm volatile(lock "cmpxchgl %2,%1" \
62 : "=a" (__ret), "+m" (*__ptr) \
63 : "r" (__new), "0" (__old) \
64 : "memory"); \
65 break; \
66 } \
67 case __X86_CASE_Q: \
68 { \
69 volatile u64 *__ptr = (volatile u64 *)(ptr); \
70 asm volatile(lock "cmpxchgq %2,%1" \
71 : "=a" (__ret), "+m" (*__ptr) \
72 : "r" (__new), "0" (__old) \
73 : "memory"); \
74 break; \
75 } \
76 default: \
77 __cmpxchg_wrong_size(); \
78 } \
79 __ret; \
80})
81
82#define __cmpxchg(ptr, old, new, size) \
83 __raw_cmpxchg((ptr), (old), (new), (size), LOCK_PREFIX)
84
85#define cmpxchg(ptr, old, new) \
86 __cmpxchg(ptr, old, new, sizeof(*(ptr)))
87
88
89#endif /* TOOLS_ASM_X86_CMPXCHG_H */
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index 293149a1c6a1..0fe00446f9ca 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -100,7 +100,7 @@
100#define X86_FEATURE_XTOPOLOGY ( 3*32+22) /* cpu topology enum extensions */ 100#define X86_FEATURE_XTOPOLOGY ( 3*32+22) /* cpu topology enum extensions */
101#define X86_FEATURE_TSC_RELIABLE ( 3*32+23) /* TSC is known to be reliable */ 101#define X86_FEATURE_TSC_RELIABLE ( 3*32+23) /* TSC is known to be reliable */
102#define X86_FEATURE_NONSTOP_TSC ( 3*32+24) /* TSC does not stop in C states */ 102#define X86_FEATURE_NONSTOP_TSC ( 3*32+24) /* TSC does not stop in C states */
103/* free, was #define X86_FEATURE_CLFLUSH_MONITOR ( 3*32+25) * "" clflush reqd with monitor */ 103#define X86_FEATURE_CPUID ( 3*32+25) /* CPU has CPUID instruction itself */
104#define X86_FEATURE_EXTD_APICID ( 3*32+26) /* has extended APICID (8 bits) */ 104#define X86_FEATURE_EXTD_APICID ( 3*32+26) /* has extended APICID (8 bits) */
105#define X86_FEATURE_AMD_DCM ( 3*32+27) /* multi-node processor */ 105#define X86_FEATURE_AMD_DCM ( 3*32+27) /* multi-node processor */
106#define X86_FEATURE_APERFMPERF ( 3*32+28) /* APERFMPERF */ 106#define X86_FEATURE_APERFMPERF ( 3*32+28) /* APERFMPERF */
@@ -186,7 +186,8 @@
186 * 186 *
187 * Reuse free bits when adding new feature flags! 187 * Reuse free bits when adding new feature flags!
188 */ 188 */
189 189#define X86_FEATURE_RING3MWAIT ( 7*32+ 0) /* Ring 3 MONITOR/MWAIT */
190#define X86_FEATURE_CPUID_FAULT ( 7*32+ 1) /* Intel CPUID faulting */
190#define X86_FEATURE_CPB ( 7*32+ 2) /* AMD Core Performance Boost */ 191#define X86_FEATURE_CPB ( 7*32+ 2) /* AMD Core Performance Boost */
191#define X86_FEATURE_EPB ( 7*32+ 3) /* IA32_ENERGY_PERF_BIAS support */ 192#define X86_FEATURE_EPB ( 7*32+ 3) /* IA32_ENERGY_PERF_BIAS support */
192#define X86_FEATURE_CAT_L3 ( 7*32+ 4) /* Cache Allocation Technology L3 */ 193#define X86_FEATURE_CAT_L3 ( 7*32+ 4) /* Cache Allocation Technology L3 */
@@ -289,7 +290,8 @@
289#define X86_FEATURE_PKU (16*32+ 3) /* Protection Keys for Userspace */ 290#define X86_FEATURE_PKU (16*32+ 3) /* Protection Keys for Userspace */
290#define X86_FEATURE_OSPKE (16*32+ 4) /* OS Protection Keys Enable */ 291#define X86_FEATURE_OSPKE (16*32+ 4) /* OS Protection Keys Enable */
291#define X86_FEATURE_AVX512_VPOPCNTDQ (16*32+14) /* POPCNT for vectors of DW/QW */ 292#define X86_FEATURE_AVX512_VPOPCNTDQ (16*32+14) /* POPCNT for vectors of DW/QW */
292#define X86_FEATURE_RDPID (16*32+ 22) /* RDPID instruction */ 293#define X86_FEATURE_LA57 (16*32+16) /* 5-level page tables */
294#define X86_FEATURE_RDPID (16*32+22) /* RDPID instruction */
293 295
294/* AMD-defined CPU features, CPUID level 0x80000007 (ebx), word 17 */ 296/* AMD-defined CPU features, CPUID level 0x80000007 (ebx), word 17 */
295#define X86_FEATURE_OVERFLOW_RECOV (17*32+0) /* MCA overflow recovery support */ 297#define X86_FEATURE_OVERFLOW_RECOV (17*32+0) /* MCA overflow recovery support */
@@ -321,5 +323,4 @@
321#define X86_BUG_SWAPGS_FENCE X86_BUG(11) /* SWAPGS without input dep on GS */ 323#define X86_BUG_SWAPGS_FENCE X86_BUG(11) /* SWAPGS without input dep on GS */
322#define X86_BUG_MONITOR X86_BUG(12) /* IPI required to wake up remote CPU */ 324#define X86_BUG_MONITOR X86_BUG(12) /* IPI required to wake up remote CPU */
323#define X86_BUG_AMD_E400 X86_BUG(13) /* CPU is among the affected by Erratum 400 */ 325#define X86_BUG_AMD_E400 X86_BUG(13) /* CPU is among the affected by Erratum 400 */
324
325#endif /* _ASM_X86_CPUFEATURES_H */ 326#endif /* _ASM_X86_CPUFEATURES_H */
diff --git a/tools/arch/x86/lib/memcpy_64.S b/tools/arch/x86/lib/memcpy_64.S
index 49e6ebac7e73..98dcc112b363 100644
--- a/tools/arch/x86/lib/memcpy_64.S
+++ b/tools/arch/x86/lib/memcpy_64.S
@@ -286,7 +286,7 @@ ENDPROC(memcpy_mcsafe_unrolled)
286 _ASM_EXTABLE_FAULT(.L_copy_leading_bytes, .L_memcpy_mcsafe_fail) 286 _ASM_EXTABLE_FAULT(.L_copy_leading_bytes, .L_memcpy_mcsafe_fail)
287 _ASM_EXTABLE_FAULT(.L_cache_w0, .L_memcpy_mcsafe_fail) 287 _ASM_EXTABLE_FAULT(.L_cache_w0, .L_memcpy_mcsafe_fail)
288 _ASM_EXTABLE_FAULT(.L_cache_w1, .L_memcpy_mcsafe_fail) 288 _ASM_EXTABLE_FAULT(.L_cache_w1, .L_memcpy_mcsafe_fail)
289 _ASM_EXTABLE_FAULT(.L_cache_w3, .L_memcpy_mcsafe_fail) 289 _ASM_EXTABLE_FAULT(.L_cache_w2, .L_memcpy_mcsafe_fail)
290 _ASM_EXTABLE_FAULT(.L_cache_w3, .L_memcpy_mcsafe_fail) 290 _ASM_EXTABLE_FAULT(.L_cache_w3, .L_memcpy_mcsafe_fail)
291 _ASM_EXTABLE_FAULT(.L_cache_w4, .L_memcpy_mcsafe_fail) 291 _ASM_EXTABLE_FAULT(.L_cache_w4, .L_memcpy_mcsafe_fail)
292 _ASM_EXTABLE_FAULT(.L_cache_w5, .L_memcpy_mcsafe_fail) 292 _ASM_EXTABLE_FAULT(.L_cache_w5, .L_memcpy_mcsafe_fail)
diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index e3fb5ecbdcb6..523911f316ce 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -63,6 +63,7 @@ FEATURE_TESTS_BASIC := \
63 lzma \ 63 lzma \
64 get_cpuid \ 64 get_cpuid \
65 bpf \ 65 bpf \
66 sched_getcpu \
66 sdt 67 sdt
67 68
68# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list 69# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index b564a2eea039..e35e4e5ad192 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -48,21 +48,22 @@ FILES= \
48 test-get_cpuid.bin \ 48 test-get_cpuid.bin \
49 test-sdt.bin \ 49 test-sdt.bin \
50 test-cxx.bin \ 50 test-cxx.bin \
51 test-jvmti.bin 51 test-jvmti.bin \
52 test-sched_getcpu.bin
52 53
53FILES := $(addprefix $(OUTPUT),$(FILES)) 54FILES := $(addprefix $(OUTPUT),$(FILES))
54 55
55CC := $(CROSS_COMPILE)gcc -MD 56CC ?= $(CROSS_COMPILE)gcc
56CXX := $(CROSS_COMPILE)g++ -MD 57CXX ?= $(CROSS_COMPILE)g++
57PKG_CONFIG := $(CROSS_COMPILE)pkg-config 58PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
58LLVM_CONFIG ?= llvm-config 59LLVM_CONFIG ?= llvm-config
59 60
60all: $(FILES) 61all: $(FILES)
61 62
62__BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS) 63__BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
63 BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1 64 BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
64 65
65__BUILDXX = $(CXX) $(CXXFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS) 66__BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS)
66 BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1 67 BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1
67 68
68############################### 69###############################
@@ -91,6 +92,9 @@ $(OUTPUT)test-libelf.bin:
91$(OUTPUT)test-glibc.bin: 92$(OUTPUT)test-glibc.bin:
92 $(BUILD) 93 $(BUILD)
93 94
95$(OUTPUT)test-sched_getcpu.bin:
96 $(BUILD)
97
94DWARFLIBS := -ldw 98DWARFLIBS := -ldw
95ifeq ($(findstring -static,${LDFLAGS}),-static) 99ifeq ($(findstring -static,${LDFLAGS}),-static)
96DWARFLIBS += -lelf -lebl -lz -llzma -lbz2 100DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
@@ -171,7 +175,7 @@ $(OUTPUT)test-libperl.bin:
171 $(BUILD) $(FLAGS_PERL_EMBED) 175 $(BUILD) $(FLAGS_PERL_EMBED)
172 176
173$(OUTPUT)test-libpython.bin: 177$(OUTPUT)test-libpython.bin:
174 $(BUILD) 178 $(BUILD) $(FLAGS_PYTHON_EMBED)
175 179
176$(OUTPUT)test-libpython-version.bin: 180$(OUTPUT)test-libpython-version.bin:
177 $(BUILD) 181 $(BUILD)
diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c
index 699e43627397..cc6c7c01f4ca 100644
--- a/tools/build/feature/test-all.c
+++ b/tools/build/feature/test-all.c
@@ -117,6 +117,10 @@
117# include "test-pthread-attr-setaffinity-np.c" 117# include "test-pthread-attr-setaffinity-np.c"
118#undef main 118#undef main
119 119
120#define main main_test_sched_getcpu
121# include "test-sched_getcpu.c"
122#undef main
123
120# if 0 124# if 0
121/* 125/*
122 * Disable libbabeltrace check for test-all, because the requested 126 * Disable libbabeltrace check for test-all, because the requested
@@ -182,6 +186,7 @@ int main(int argc, char *argv[])
182 main_test_get_cpuid(); 186 main_test_get_cpuid();
183 main_test_bpf(); 187 main_test_bpf();
184 main_test_libcrypto(); 188 main_test_libcrypto();
189 main_test_sched_getcpu();
185 main_test_sdt(); 190 main_test_sdt();
186 191
187 return 0; 192 return 0;
diff --git a/tools/build/feature/test-sched_getcpu.c b/tools/build/feature/test-sched_getcpu.c
new file mode 100644
index 000000000000..c4a148dd7104
--- /dev/null
+++ b/tools/build/feature/test-sched_getcpu.c
@@ -0,0 +1,7 @@
1#define _GNU_SOURCE
2#include <sched.h>
3
4int main(void)
5{
6 return sched_getcpu();
7}
diff --git a/tools/include/asm-generic/atomic-gcc.h b/tools/include/asm-generic/atomic-gcc.h
index 2ba78c9f5701..5e9738f97bf3 100644
--- a/tools/include/asm-generic/atomic-gcc.h
+++ b/tools/include/asm-generic/atomic-gcc.h
@@ -60,4 +60,12 @@ static inline int atomic_dec_and_test(atomic_t *v)
60 return __sync_sub_and_fetch(&v->counter, 1) == 0; 60 return __sync_sub_and_fetch(&v->counter, 1) == 0;
61} 61}
62 62
63#define cmpxchg(ptr, oldval, newval) \
64 __sync_val_compare_and_swap(ptr, oldval, newval)
65
66static inline int atomic_cmpxchg(atomic_t *v, int oldval, int newval)
67{
68 return cmpxchg(&(v)->counter, oldval, newval);
69}
70
63#endif /* __TOOLS_ASM_GENERIC_ATOMIC_H */ 71#endif /* __TOOLS_ASM_GENERIC_ATOMIC_H */
diff --git a/tools/include/linux/atomic.h b/tools/include/linux/atomic.h
index 4e3d3d18ebab..9f21fc2b092b 100644
--- a/tools/include/linux/atomic.h
+++ b/tools/include/linux/atomic.h
@@ -3,4 +3,10 @@
3 3
4#include <asm/atomic.h> 4#include <asm/atomic.h>
5 5
6/* atomic_cmpxchg_relaxed */
7#ifndef atomic_cmpxchg_relaxed
8#define atomic_cmpxchg_relaxed atomic_cmpxchg
9#define atomic_cmpxchg_release atomic_cmpxchg
10#endif /* atomic_cmpxchg_relaxed */
11
6#endif /* __TOOLS_LINUX_ATOMIC_H */ 12#endif /* __TOOLS_LINUX_ATOMIC_H */
diff --git a/tools/include/linux/bug.h b/tools/include/linux/bug.h
new file mode 100644
index 000000000000..8e4a4f49135d
--- /dev/null
+++ b/tools/include/linux/bug.h
@@ -0,0 +1,10 @@
1#ifndef _TOOLS_PERF_LINUX_BUG_H
2#define _TOOLS_PERF_LINUX_BUG_H
3
4/* Force a compilation error if condition is true, but also produce a
5 result (of value 0 and type size_t), so the expression can be used
6 e.g. in a structure initializer (or where-ever else comma expressions
7 aren't permitted). */
8#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
9
10#endif /* _TOOLS_PERF_LINUX_BUG_H */
diff --git a/tools/include/linux/compiler-gcc.h b/tools/include/linux/compiler-gcc.h
index 48af2f10a42d..825d44f89a29 100644
--- a/tools/include/linux/compiler-gcc.h
+++ b/tools/include/linux/compiler-gcc.h
@@ -12,3 +12,10 @@
12#if GCC_VERSION >= 70000 && !defined(__CHECKER__) 12#if GCC_VERSION >= 70000 && !defined(__CHECKER__)
13# define __fallthrough __attribute__ ((fallthrough)) 13# define __fallthrough __attribute__ ((fallthrough))
14#endif 14#endif
15
16#if GCC_VERSION >= 40300
17# define __compiletime_error(message) __attribute__((error(message)))
18#endif /* GCC_VERSION >= 40300 */
19
20/* &a[0] degrades to a pointer: a different type from an array */
21#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
index 8de163b17c0d..23299d7e7160 100644
--- a/tools/include/linux/compiler.h
+++ b/tools/include/linux/compiler.h
@@ -5,6 +5,10 @@
5#include <linux/compiler-gcc.h> 5#include <linux/compiler-gcc.h>
6#endif 6#endif
7 7
8#ifndef __compiletime_error
9# define __compiletime_error(message)
10#endif
11
8/* Optimization barrier */ 12/* Optimization barrier */
9/* The "volatile" is due to gcc bugs */ 13/* The "volatile" is due to gcc bugs */
10#define barrier() __asm__ __volatile__("": : :"memory") 14#define barrier() __asm__ __volatile__("": : :"memory")
@@ -13,6 +17,11 @@
13# define __always_inline inline __attribute__((always_inline)) 17# define __always_inline inline __attribute__((always_inline))
14#endif 18#endif
15 19
20/* Are two types/vars the same type (ignoring qualifiers)? */
21#ifndef __same_type
22# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
23#endif
24
16#ifdef __ANDROID__ 25#ifdef __ANDROID__
17/* 26/*
18 * FIXME: Big hammer to get rid of tons of: 27 * FIXME: Big hammer to get rid of tons of:
diff --git a/tools/include/linux/hashtable.h b/tools/include/linux/hashtable.h
index c65cc0aa2659..251eabf2a05e 100644
--- a/tools/include/linux/hashtable.h
+++ b/tools/include/linux/hashtable.h
@@ -13,10 +13,6 @@
13#include <linux/hash.h> 13#include <linux/hash.h>
14#include <linux/log2.h> 14#include <linux/log2.h>
15 15
16#ifndef ARRAY_SIZE
17#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
18#endif
19
20#define DEFINE_HASHTABLE(name, bits) \ 16#define DEFINE_HASHTABLE(name, bits) \
21 struct hlist_head name[1 << (bits)] = \ 17 struct hlist_head name[1 << (bits)] = \
22 { [0 ... ((1 << (bits)) - 1)] = HLIST_HEAD_INIT } 18 { [0 ... ((1 << (bits)) - 1)] = HLIST_HEAD_INIT }
diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
index 28607db02bd3..73ccc48126bb 100644
--- a/tools/include/linux/kernel.h
+++ b/tools/include/linux/kernel.h
@@ -4,6 +4,11 @@
4#include <stdarg.h> 4#include <stdarg.h>
5#include <stddef.h> 5#include <stddef.h>
6#include <assert.h> 6#include <assert.h>
7#include <linux/compiler.h>
8
9#ifndef UINT_MAX
10#define UINT_MAX (~0U)
11#endif
7 12
8#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) 13#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
9 14
@@ -72,6 +77,8 @@
72int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); 77int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
73int scnprintf(char * buf, size_t size, const char * fmt, ...); 78int scnprintf(char * buf, size_t size, const char * fmt, ...);
74 79
80#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
81
75/* 82/*
76 * This looks more complex than it should be. But we need to 83 * This looks more complex than it should be. But we need to
77 * get the type for the ~ right in round_down (it needs to be 84 * get the type for the ~ right in round_down (it needs to be
diff --git a/tools/include/linux/log2.h b/tools/include/linux/log2.h
index d5677d39c1e4..0325cefc2220 100644
--- a/tools/include/linux/log2.h
+++ b/tools/include/linux/log2.h
@@ -12,6 +12,9 @@
12#ifndef _TOOLS_LINUX_LOG2_H 12#ifndef _TOOLS_LINUX_LOG2_H
13#define _TOOLS_LINUX_LOG2_H 13#define _TOOLS_LINUX_LOG2_H
14 14
15#include <linux/bitops.h>
16#include <linux/types.h>
17
15/* 18/*
16 * non-constant log of base 2 calculators 19 * non-constant log of base 2 calculators
17 * - the arch may override these in asm/bitops.h if they can be implemented 20 * - the arch may override these in asm/bitops.h if they can be implemented
diff --git a/tools/include/linux/refcount.h b/tools/include/linux/refcount.h
new file mode 100644
index 000000000000..a0177c1f55b1
--- /dev/null
+++ b/tools/include/linux/refcount.h
@@ -0,0 +1,151 @@
1#ifndef _TOOLS_LINUX_REFCOUNT_H
2#define _TOOLS_LINUX_REFCOUNT_H
3
4/*
5 * Variant of atomic_t specialized for reference counts.
6 *
7 * The interface matches the atomic_t interface (to aid in porting) but only
8 * provides the few functions one should use for reference counting.
9 *
10 * It differs in that the counter saturates at UINT_MAX and will not move once
11 * there. This avoids wrapping the counter and causing 'spurious'
12 * use-after-free issues.
13 *
14 * Memory ordering rules are slightly relaxed wrt regular atomic_t functions
15 * and provide only what is strictly required for refcounts.
16 *
17 * The increments are fully relaxed; these will not provide ordering. The
18 * rationale is that whatever is used to obtain the object we're increasing the
19 * reference count on will provide the ordering. For locked data structures,
20 * its the lock acquire, for RCU/lockless data structures its the dependent
21 * load.
22 *
23 * Do note that inc_not_zero() provides a control dependency which will order
24 * future stores against the inc, this ensures we'll never modify the object
25 * if we did not in fact acquire a reference.
26 *
27 * The decrements will provide release order, such that all the prior loads and
28 * stores will be issued before, it also provides a control dependency, which
29 * will order us against the subsequent free().
30 *
31 * The control dependency is against the load of the cmpxchg (ll/sc) that
32 * succeeded. This means the stores aren't fully ordered, but this is fine
33 * because the 1->0 transition indicates no concurrency.
34 *
35 * Note that the allocator is responsible for ordering things between free()
36 * and alloc().
37 *
38 */
39
40#include <linux/atomic.h>
41#include <linux/kernel.h>
42
43#ifdef NDEBUG
44#define REFCOUNT_WARN(cond, str) (void)(cond)
45#define __refcount_check
46#else
47#define REFCOUNT_WARN(cond, str) BUG_ON(cond)
48#define __refcount_check __must_check
49#endif
50
51typedef struct refcount_struct {
52 atomic_t refs;
53} refcount_t;
54
55#define REFCOUNT_INIT(n) { .refs = ATOMIC_INIT(n), }
56
57static inline void refcount_set(refcount_t *r, unsigned int n)
58{
59 atomic_set(&r->refs, n);
60}
61
62static inline unsigned int refcount_read(const refcount_t *r)
63{
64 return atomic_read(&r->refs);
65}
66
67/*
68 * Similar to atomic_inc_not_zero(), will saturate at UINT_MAX and WARN.
69 *
70 * Provides no memory ordering, it is assumed the caller has guaranteed the
71 * object memory to be stable (RCU, etc.). It does provide a control dependency
72 * and thereby orders future stores. See the comment on top.
73 */
74static inline __refcount_check
75bool refcount_inc_not_zero(refcount_t *r)
76{
77 unsigned int old, new, val = atomic_read(&r->refs);
78
79 for (;;) {
80 new = val + 1;
81
82 if (!val)
83 return false;
84
85 if (unlikely(!new))
86 return true;
87
88 old = atomic_cmpxchg_relaxed(&r->refs, val, new);
89 if (old == val)
90 break;
91
92 val = old;
93 }
94
95 REFCOUNT_WARN(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n");
96
97 return true;
98}
99
100/*
101 * Similar to atomic_inc(), will saturate at UINT_MAX and WARN.
102 *
103 * Provides no memory ordering, it is assumed the caller already has a
104 * reference on the object, will WARN when this is not so.
105 */
106static inline void refcount_inc(refcount_t *r)
107{
108 REFCOUNT_WARN(!refcount_inc_not_zero(r), "refcount_t: increment on 0; use-after-free.\n");
109}
110
111/*
112 * Similar to atomic_dec_and_test(), it will WARN on underflow and fail to
113 * decrement when saturated at UINT_MAX.
114 *
115 * Provides release memory ordering, such that prior loads and stores are done
116 * before, and provides a control dependency such that free() must come after.
117 * See the comment on top.
118 */
119static inline __refcount_check
120bool refcount_sub_and_test(unsigned int i, refcount_t *r)
121{
122 unsigned int old, new, val = atomic_read(&r->refs);
123
124 for (;;) {
125 if (unlikely(val == UINT_MAX))
126 return false;
127
128 new = val - i;
129 if (new > val) {
130 REFCOUNT_WARN(new > val, "refcount_t: underflow; use-after-free.\n");
131 return false;
132 }
133
134 old = atomic_cmpxchg_release(&r->refs, val, new);
135 if (old == val)
136 break;
137
138 val = old;
139 }
140
141 return !new;
142}
143
144static inline __refcount_check
145bool refcount_dec_and_test(refcount_t *r)
146{
147 return refcount_sub_and_test(1, r);
148}
149
150
151#endif /* _ATOMIC_LINUX_REFCOUNT_H */
diff --git a/tools/include/linux/types.h b/tools/include/linux/types.h
index c24b3e3ae296..77a28a26a670 100644
--- a/tools/include/linux/types.h
+++ b/tools/include/linux/types.h
@@ -7,6 +7,7 @@
7 7
8#define __SANE_USERSPACE_TYPES__ /* For PPC64, to get LL64 types */ 8#define __SANE_USERSPACE_TYPES__ /* For PPC64, to get LL64 types */
9#include <asm/types.h> 9#include <asm/types.h>
10#include <asm/posix_types.h>
10 11
11struct page; 12struct page;
12struct kmem_cache; 13struct kmem_cache;
diff --git a/tools/include/uapi/linux/fcntl.h b/tools/include/uapi/linux/fcntl.h
new file mode 100644
index 000000000000..813afd6eee71
--- /dev/null
+++ b/tools/include/uapi/linux/fcntl.h
@@ -0,0 +1,72 @@
1#ifndef _UAPI_LINUX_FCNTL_H
2#define _UAPI_LINUX_FCNTL_H
3
4#include <asm/fcntl.h>
5
6#define F_SETLEASE (F_LINUX_SPECIFIC_BASE + 0)
7#define F_GETLEASE (F_LINUX_SPECIFIC_BASE + 1)
8
9/*
10 * Cancel a blocking posix lock; internal use only until we expose an
11 * asynchronous lock api to userspace:
12 */
13#define F_CANCELLK (F_LINUX_SPECIFIC_BASE + 5)
14
15/* Create a file descriptor with FD_CLOEXEC set. */
16#define F_DUPFD_CLOEXEC (F_LINUX_SPECIFIC_BASE + 6)
17
18/*
19 * Request nofications on a directory.
20 * See below for events that may be notified.
21 */
22#define F_NOTIFY (F_LINUX_SPECIFIC_BASE+2)
23
24/*
25 * Set and get of pipe page size array
26 */
27#define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
28#define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8)
29
30/*
31 * Set/Get seals
32 */
33#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
34#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
35
36/*
37 * Types of seals
38 */
39#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
40#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
41#define F_SEAL_GROW 0x0004 /* prevent file from growing */
42#define F_SEAL_WRITE 0x0008 /* prevent writes */
43/* (1U << 31) is reserved for signed error codes */
44
45/*
46 * Types of directory notifications that may be requested.
47 */
48#define DN_ACCESS 0x00000001 /* File accessed */
49#define DN_MODIFY 0x00000002 /* File modified */
50#define DN_CREATE 0x00000004 /* File created */
51#define DN_DELETE 0x00000008 /* File removed */
52#define DN_RENAME 0x00000010 /* File renamed */
53#define DN_ATTRIB 0x00000020 /* File changed attibutes */
54#define DN_MULTISHOT 0x80000000 /* Don't remove notifier */
55
56#define AT_FDCWD -100 /* Special value used to indicate
57 openat should use the current
58 working directory. */
59#define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */
60#define AT_REMOVEDIR 0x200 /* Remove directory instead of
61 unlinking file. */
62#define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */
63#define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */
64#define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname */
65
66#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
67#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
68#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
69#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
70
71
72#endif /* _UAPI_LINUX_FCNTL_H */
diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index c66a485a24ac..d09a9cd021b1 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -344,7 +344,8 @@ struct perf_event_attr {
344 use_clockid : 1, /* use @clockid for time fields */ 344 use_clockid : 1, /* use @clockid for time fields */
345 context_switch : 1, /* context switch data */ 345 context_switch : 1, /* context switch data */
346 write_backward : 1, /* Write ring buffer from end to beginning */ 346 write_backward : 1, /* Write ring buffer from end to beginning */
347 __reserved_1 : 36; 347 namespaces : 1, /* include namespaces data */
348 __reserved_1 : 35;
348 349
349 union { 350 union {
350 __u32 wakeup_events; /* wakeup every n events */ 351 __u32 wakeup_events; /* wakeup every n events */
@@ -610,6 +611,23 @@ struct perf_event_header {
610 __u16 size; 611 __u16 size;
611}; 612};
612 613
614struct perf_ns_link_info {
615 __u64 dev;
616 __u64 ino;
617};
618
619enum {
620 NET_NS_INDEX = 0,
621 UTS_NS_INDEX = 1,
622 IPC_NS_INDEX = 2,
623 PID_NS_INDEX = 3,
624 USER_NS_INDEX = 4,
625 MNT_NS_INDEX = 5,
626 CGROUP_NS_INDEX = 6,
627
628 NR_NAMESPACES, /* number of available namespaces */
629};
630
613enum perf_event_type { 631enum perf_event_type {
614 632
615 /* 633 /*
@@ -862,6 +880,18 @@ enum perf_event_type {
862 */ 880 */
863 PERF_RECORD_SWITCH_CPU_WIDE = 15, 881 PERF_RECORD_SWITCH_CPU_WIDE = 15,
864 882
883 /*
884 * struct {
885 * struct perf_event_header header;
886 * u32 pid;
887 * u32 tid;
888 * u64 nr_namespaces;
889 * { u64 dev, inode; } [nr_namespaces];
890 * struct sample_id sample_id;
891 * };
892 */
893 PERF_RECORD_NAMESPACES = 16,
894
865 PERF_RECORD_MAX, /* non-ABI */ 895 PERF_RECORD_MAX, /* non-ABI */
866}; 896};
867 897
@@ -885,6 +915,7 @@ enum perf_callchain_context {
885 */ 915 */
886#define PERF_AUX_FLAG_TRUNCATED 0x01 /* record was truncated to fit */ 916#define PERF_AUX_FLAG_TRUNCATED 0x01 /* record was truncated to fit */
887#define PERF_AUX_FLAG_OVERWRITE 0x02 /* snapshot from overwrite mode */ 917#define PERF_AUX_FLAG_OVERWRITE 0x02 /* snapshot from overwrite mode */
918#define PERF_AUX_FLAG_PARTIAL 0x04 /* record contains gaps */
888 919
889#define PERF_FLAG_FD_NO_GROUP (1UL << 0) 920#define PERF_FLAG_FD_NO_GROUP (1UL << 0)
890#define PERF_FLAG_FD_OUTPUT (1UL << 1) 921#define PERF_FLAG_FD_OUTPUT (1UL << 1)
diff --git a/tools/include/uapi/linux/stat.h b/tools/include/uapi/linux/stat.h
new file mode 100644
index 000000000000..d538897b8e08
--- /dev/null
+++ b/tools/include/uapi/linux/stat.h
@@ -0,0 +1,177 @@
1#ifndef _UAPI_LINUX_STAT_H
2#define _UAPI_LINUX_STAT_H
3
4#include <linux/types.h>
5
6#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
7
8#define S_IFMT 00170000
9#define S_IFSOCK 0140000
10#define S_IFLNK 0120000
11#define S_IFREG 0100000
12#define S_IFBLK 0060000
13#define S_IFDIR 0040000
14#define S_IFCHR 0020000
15#define S_IFIFO 0010000
16#define S_ISUID 0004000
17#define S_ISGID 0002000
18#define S_ISVTX 0001000
19
20#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
21#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
22#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
23#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
24#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
25#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
26#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
27
28#define S_IRWXU 00700
29#define S_IRUSR 00400
30#define S_IWUSR 00200
31#define S_IXUSR 00100
32
33#define S_IRWXG 00070
34#define S_IRGRP 00040
35#define S_IWGRP 00020
36#define S_IXGRP 00010
37
38#define S_IRWXO 00007
39#define S_IROTH 00004
40#define S_IWOTH 00002
41#define S_IXOTH 00001
42
43#endif
44
45/*
46 * Timestamp structure for the timestamps in struct statx.
47 *
48 * tv_sec holds the number of seconds before (negative) or after (positive)
49 * 00:00:00 1st January 1970 UTC.
50 *
51 * tv_nsec holds a number of nanoseconds before (0..-999,999,999 if tv_sec is
52 * negative) or after (0..999,999,999 if tv_sec is positive) the tv_sec time.
53 *
54 * Note that if both tv_sec and tv_nsec are non-zero, then the two values must
55 * either be both positive or both negative.
56 *
57 * __reserved is held in case we need a yet finer resolution.
58 */
59struct statx_timestamp {
60 __s64 tv_sec;
61 __s32 tv_nsec;
62 __s32 __reserved;
63};
64
65/*
66 * Structures for the extended file attribute retrieval system call
67 * (statx()).
68 *
69 * The caller passes a mask of what they're specifically interested in as a
70 * parameter to statx(). What statx() actually got will be indicated in
71 * st_mask upon return.
72 *
73 * For each bit in the mask argument:
74 *
75 * - if the datum is not supported:
76 *
77 * - the bit will be cleared, and
78 *
79 * - the datum will be set to an appropriate fabricated value if one is
80 * available (eg. CIFS can take a default uid and gid), otherwise
81 *
82 * - the field will be cleared;
83 *
84 * - otherwise, if explicitly requested:
85 *
86 * - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
87 * set or if the datum is considered out of date, and
88 *
89 * - the field will be filled in and the bit will be set;
90 *
91 * - otherwise, if not requested, but available in approximate form without any
92 * effort, it will be filled in anyway, and the bit will be set upon return
93 * (it might not be up to date, however, and no attempt will be made to
94 * synchronise the internal state first);
95 *
96 * - otherwise the field and the bit will be cleared before returning.
97 *
98 * Items in STATX_BASIC_STATS may be marked unavailable on return, but they
99 * will have values installed for compatibility purposes so that stat() and
100 * co. can be emulated in userspace.
101 */
102struct statx {
103 /* 0x00 */
104 __u32 stx_mask; /* What results were written [uncond] */
105 __u32 stx_blksize; /* Preferred general I/O size [uncond] */
106 __u64 stx_attributes; /* Flags conveying information about the file [uncond] */
107 /* 0x10 */
108 __u32 stx_nlink; /* Number of hard links */
109 __u32 stx_uid; /* User ID of owner */
110 __u32 stx_gid; /* Group ID of owner */
111 __u16 stx_mode; /* File mode */
112 __u16 __spare0[1];
113 /* 0x20 */
114 __u64 stx_ino; /* Inode number */
115 __u64 stx_size; /* File size */
116 __u64 stx_blocks; /* Number of 512-byte blocks allocated */
117 __u64 stx_attributes_mask; /* Mask to show what's supported in stx_attributes */
118 /* 0x40 */
119 struct statx_timestamp stx_atime; /* Last access time */
120 struct statx_timestamp stx_btime; /* File creation time */
121 struct statx_timestamp stx_ctime; /* Last attribute change time */
122 struct statx_timestamp stx_mtime; /* Last data modification time */
123 /* 0x80 */
124 __u32 stx_rdev_major; /* Device ID of special file [if bdev/cdev] */
125 __u32 stx_rdev_minor;
126 __u32 stx_dev_major; /* ID of device containing file [uncond] */
127 __u32 stx_dev_minor;
128 /* 0x90 */
129 __u64 __spare2[14]; /* Spare space for future expansion */
130 /* 0x100 */
131};
132
133/*
134 * Flags to be stx_mask
135 *
136 * Query request/result mask for statx() and struct statx::stx_mask.
137 *
138 * These bits should be set in the mask argument of statx() to request
139 * particular items when calling statx().
140 */
141#define STATX_TYPE 0x00000001U /* Want/got stx_mode & S_IFMT */
142#define STATX_MODE 0x00000002U /* Want/got stx_mode & ~S_IFMT */
143#define STATX_NLINK 0x00000004U /* Want/got stx_nlink */
144#define STATX_UID 0x00000008U /* Want/got stx_uid */
145#define STATX_GID 0x00000010U /* Want/got stx_gid */
146#define STATX_ATIME 0x00000020U /* Want/got stx_atime */
147#define STATX_MTIME 0x00000040U /* Want/got stx_mtime */
148#define STATX_CTIME 0x00000080U /* Want/got stx_ctime */
149#define STATX_INO 0x00000100U /* Want/got stx_ino */
150#define STATX_SIZE 0x00000200U /* Want/got stx_size */
151#define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */
152#define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */
153#define STATX_BTIME 0x00000800U /* Want/got stx_btime */
154#define STATX_ALL 0x00000fffU /* All currently supported flags */
155#define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */
156
157/*
158 * Attributes to be found in stx_attributes and masked in stx_attributes_mask.
159 *
160 * These give information about the features or the state of a file that might
161 * be of use to ordinary userspace programs such as GUIs or ls rather than
162 * specialised tools.
163 *
164 * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
165 * semantically. Where possible, the numerical value is picked to correspond
166 * also.
167 */
168#define STATX_ATTR_COMPRESSED 0x00000004 /* [I] File is compressed by the fs */
169#define STATX_ATTR_IMMUTABLE 0x00000010 /* [I] File is marked immutable */
170#define STATX_ATTR_APPEND 0x00000020 /* [I] File is append-only */
171#define STATX_ATTR_NODUMP 0x00000040 /* [I] File is not to be dumped */
172#define STATX_ATTR_ENCRYPTED 0x00000800 /* [I] File requires key to decrypt in fs */
173
174#define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger */
175
176
177#endif /* _UAPI_LINUX_STAT_H */
diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c
index 4b6bfc43cccf..809c7721cd24 100644
--- a/tools/lib/api/fs/fs.c
+++ b/tools/lib/api/fs/fs.c
@@ -439,6 +439,35 @@ int sysfs__read_str(const char *entry, char **buf, size_t *sizep)
439 return filename__read_str(path, buf, sizep); 439 return filename__read_str(path, buf, sizep);
440} 440}
441 441
442int sysfs__read_bool(const char *entry, bool *value)
443{
444 char *buf;
445 size_t size;
446 int ret;
447
448 ret = sysfs__read_str(entry, &buf, &size);
449 if (ret < 0)
450 return ret;
451
452 switch (buf[0]) {
453 case '1':
454 case 'y':
455 case 'Y':
456 *value = true;
457 break;
458 case '0':
459 case 'n':
460 case 'N':
461 *value = false;
462 break;
463 default:
464 ret = -1;
465 }
466
467 free(buf);
468
469 return ret;
470}
442int sysctl__read_int(const char *sysctl, int *value) 471int sysctl__read_int(const char *sysctl, int *value)
443{ 472{
444 char path[PATH_MAX]; 473 char path[PATH_MAX];
diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h
index 6b332dc74498..956c21127d1e 100644
--- a/tools/lib/api/fs/fs.h
+++ b/tools/lib/api/fs/fs.h
@@ -37,4 +37,5 @@ int sysctl__read_int(const char *sysctl, int *value);
37int sysfs__read_int(const char *entry, int *value); 37int sysfs__read_int(const char *entry, int *value);
38int sysfs__read_ull(const char *entry, unsigned long long *value); 38int sysfs__read_ull(const char *entry, unsigned long long *value);
39int sysfs__read_str(const char *entry, char **buf, size_t *sizep); 39int sysfs__read_str(const char *entry, char **buf, size_t *sizep);
40int sysfs__read_bool(const char *entry, bool *value);
40#endif /* __API_FS__ */ 41#endif /* __API_FS__ */
diff --git a/tools/lib/subcmd/help.h b/tools/lib/subcmd/help.h
index e145a020780c..9bd4223dc722 100644
--- a/tools/lib/subcmd/help.h
+++ b/tools/lib/subcmd/help.h
@@ -2,6 +2,7 @@
2#define __SUBCMD_HELP_H 2#define __SUBCMD_HELP_H
3 3
4#include <sys/types.h> 4#include <sys/types.h>
5#include <stdio.h>
5 6
6struct cmdnames { 7struct cmdnames {
7 size_t alloc; 8 size_t alloc;
diff --git a/tools/lib/symbol/kallsyms.c b/tools/lib/symbol/kallsyms.c
index 5e431077fcd6..d270ac00613d 100644
--- a/tools/lib/symbol/kallsyms.c
+++ b/tools/lib/symbol/kallsyms.c
@@ -1,3 +1,4 @@
1#include <ctype.h>
1#include "symbol/kallsyms.h" 2#include "symbol/kallsyms.h"
2#include <stdio.h> 3#include <stdio.h>
3#include <stdlib.h> 4#include <stdlib.h>
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 066086dd59a8..282a60368b14 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -36,8 +36,7 @@
36#include "warn.h" 36#include "warn.h"
37 37
38#include <linux/hashtable.h> 38#include <linux/hashtable.h>
39 39#include <linux/kernel.h>
40#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
41 40
42#define STATE_FP_SAVED 0x1 41#define STATE_FP_SAVED 0x1
43#define STATE_FP_SETUP 0x2 42#define STATE_FP_SETUP 0x2
diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c
index 46c326db4f46..ecc5b1b5d15d 100644
--- a/tools/objtool/objtool.c
+++ b/tools/objtool/objtool.c
@@ -31,11 +31,10 @@
31#include <stdlib.h> 31#include <stdlib.h>
32#include <subcmd/exec-cmd.h> 32#include <subcmd/exec-cmd.h>
33#include <subcmd/pager.h> 33#include <subcmd/pager.h>
34#include <linux/kernel.h>
34 35
35#include "builtin.h" 36#include "builtin.h"
36 37
37#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
38
39struct cmd_struct { 38struct cmd_struct {
40 const char *name; 39 const char *name;
41 int (*fn)(int, const char **); 40 int (*fn)(int, const char **);
diff --git a/tools/perf/.gitignore b/tools/perf/.gitignore
index 3db3db9278be..643cc4ba6872 100644
--- a/tools/perf/.gitignore
+++ b/tools/perf/.gitignore
@@ -31,3 +31,5 @@ config.mak.autogen
31.config-detected 31.config-detected
32util/intel-pt-decoder/inat-tables.c 32util/intel-pt-decoder/inat-tables.c
33arch/*/include/generated/ 33arch/*/include/generated/
34pmu-events/pmu-events.c
35pmu-events/jevents
diff --git a/tools/perf/Build b/tools/perf/Build
index 9b79f8d7db50..bd8eeb60533c 100644
--- a/tools/perf/Build
+++ b/tools/perf/Build
@@ -50,5 +50,6 @@ libperf-y += util/
50libperf-y += arch/ 50libperf-y += arch/
51libperf-y += ui/ 51libperf-y += ui/
52libperf-y += scripts/ 52libperf-y += scripts/
53libperf-y += trace/beauty/
53 54
54gtk-y += ui/gtk/ 55gtk-y += ui/gtk/
diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt
index 2d96de6132a9..6e6a8b22c859 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -30,6 +30,24 @@ OPTIONS
30--verbose=:: 30--verbose=::
31 Verbosity level. 31 Verbosity level.
32 32
33-p::
34--pid=::
35 Trace on existing process id (comma separated list).
36
37-a::
38--all-cpus::
39 Force system-wide collection. Scripts run without a <command>
40 normally use -a by default, while scripts run with a <command>
41 normally don't - this option allows the latter to be run in
42 system-wide mode.
43
44-C::
45--cpu=::
46 Only trace for the list of CPUs provided. Multiple CPUs can
47 be provided as a comma separated list with no space like: 0,1.
48 Ranges of CPUs are specified with -: 0-2.
49 Default is to trace on all online CPUs.
50
33 51
34SEE ALSO 52SEE ALSO
35-------- 53--------
diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt
index 41857cce5e86..f709de54707b 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -8,7 +8,7 @@ perf-list - List all symbolic event types
8SYNOPSIS 8SYNOPSIS
9-------- 9--------
10[verse] 10[verse]
11'perf list' [--no-desc] [--long-desc] [hw|sw|cache|tracepoint|pmu|event_glob] 11'perf list' [--no-desc] [--long-desc] [hw|sw|cache|tracepoint|pmu|sdt|event_glob]
12 12
13DESCRIPTION 13DESCRIPTION
14----------- 14-----------
@@ -24,6 +24,10 @@ Don't print descriptions.
24--long-desc:: 24--long-desc::
25Print longer event descriptions. 25Print longer event descriptions.
26 26
27--details::
28Print how named events are resolved internally into perf events, and also
29any extra expressions computed by perf stat.
30
27 31
28[[EVENT_MODIFIERS]] 32[[EVENT_MODIFIERS]]
29EVENT MODIFIERS 33EVENT MODIFIERS
@@ -240,6 +244,8 @@ To limit the list use:
240 244
241. 'pmu' to print the kernel supplied PMU events. 245. 'pmu' to print the kernel supplied PMU events.
242 246
247. 'sdt' to list all Statically Defined Tracepoint events.
248
243. If none of the above is matched, it will apply the supplied glob to all 249. If none of the above is matched, it will apply the supplied glob to all
244 events, printing the ones that match. 250 events, printing the ones that match.
245 251
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index b16003ec14a7..ea3789d05e5e 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -347,6 +347,9 @@ Enable weightened sampling. An additional weight is recorded per sample and can
347displayed with the weight and local_weight sort keys. This currently works for TSX 347displayed with the weight and local_weight sort keys. This currently works for TSX
348abort events and some memory events in precise mode on modern Intel CPUs. 348abort events and some memory events in precise mode on modern Intel CPUs.
349 349
350--namespaces::
351Record events of type PERF_RECORD_NAMESPACES.
352
350--transaction:: 353--transaction::
351Record transaction flags for transaction related events. 354Record transaction flags for transaction related events.
352 355
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index c04cc0647c16..37a175914157 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -72,7 +72,8 @@ OPTIONS
72--sort=:: 72--sort=::
73 Sort histogram entries by given key(s) - multiple keys can be specified 73 Sort histogram entries by given key(s) - multiple keys can be specified
74 in CSV format. Following sort keys are available: 74 in CSV format. Following sort keys are available:
75 pid, comm, dso, symbol, parent, cpu, socket, srcline, weight, local_weight. 75 pid, comm, dso, symbol, parent, cpu, socket, srcline, weight,
76 local_weight, cgroup_id.
76 77
77 Each key has following meaning: 78 Each key has following meaning:
78 79
@@ -80,6 +81,7 @@ OPTIONS
80 - pid: command and tid of the task 81 - pid: command and tid of the task
81 - dso: name of library or module executed at the time of sample 82 - dso: name of library or module executed at the time of sample
82 - symbol: name of function executed at the time of sample 83 - symbol: name of function executed at the time of sample
84 - symbol_size: size of function executed at the time of sample
83 - parent: name of function matched to the parent regex filter. Unmatched 85 - parent: name of function matched to the parent regex filter. Unmatched
84 entries are displayed as "[other]". 86 entries are displayed as "[other]".
85 - cpu: cpu number the task ran at the time of sample 87 - cpu: cpu number the task ran at the time of sample
@@ -91,6 +93,7 @@ OPTIONS
91 - weight: Event specific weight, e.g. memory latency or transaction 93 - weight: Event specific weight, e.g. memory latency or transaction
92 abort cost. This is the global weight. 94 abort cost. This is the global weight.
93 - local_weight: Local weight version of the weight above. 95 - local_weight: Local weight version of the weight above.
96 - cgroup_id: ID derived from cgroup namespace device and inode numbers.
94 - transaction: Transaction abort flags. 97 - transaction: Transaction abort flags.
95 - overhead: Overhead percentage of sample 98 - overhead: Overhead percentage of sample
96 - overhead_sys: Overhead percentage of sample running in system mode 99 - overhead_sys: Overhead percentage of sample running in system mode
@@ -172,6 +175,9 @@ OPTIONS
172 By default, every sort keys not specified in -F will be appended 175 By default, every sort keys not specified in -F will be appended
173 automatically. 176 automatically.
174 177
178 If the keys starts with a prefix '+', then it will append the specified
179 field(s) to the default field order. For example: perf report -F +period,sample.
180
175-p:: 181-p::
176--parent=<regex>:: 182--parent=<regex>::
177 A regex filter to identify parent. The parent is a caller of this 183 A regex filter to identify parent. The parent is a caller of this
@@ -229,6 +235,7 @@ OPTIONS
229 sort_key can be: 235 sort_key can be:
230 - function: compare on functions (default) 236 - function: compare on functions (default)
231 - address: compare on individual code addresses 237 - address: compare on individual code addresses
238 - srcline: compare on source filename and line number
232 239
233 branch can be: 240 branch can be:
234 - branch: include last branch information in callgraph when available. 241 - branch: include last branch information in callgraph when available.
@@ -424,6 +431,10 @@ include::itrace.txt[]
424--hierarchy:: 431--hierarchy::
425 Enable hierarchical output. 432 Enable hierarchical output.
426 433
434--inline::
435 If a callgraph address belongs to an inlined function, the inline stack
436 will be printed. Each entry is function name or file/line.
437
427include::callchain-overhead-calculation.txt[] 438include::callchain-overhead-calculation.txt[]
428 439
429SEE ALSO 440SEE ALSO
diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
index d33deddb0146..a092a2499e8f 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -132,6 +132,10 @@ OPTIONS for 'perf sched timehist'
132--migrations:: 132--migrations::
133 Show migration events. 133 Show migration events.
134 134
135-n::
136--next::
137 Show next task.
138
135-I:: 139-I::
136--idle-hist:: 140--idle-hist::
137 Show idle-related events only. 141 Show idle-related events only.
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 4ed5f239ba7d..cb0eda3925e6 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -116,7 +116,7 @@ OPTIONS
116--fields:: 116--fields::
117 Comma separated list of fields to print. Options are: 117 Comma separated list of fields to print. Options are:
118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, 118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
119 srcline, period, iregs, brstack, brstacksym, flags, bpf-output, 119 srcline, period, iregs, brstack, brstacksym, flags, bpf-output, brstackinsn,
120 callindent, insn, insnlen. Field list can be prepended with the type, trace, sw or hw, 120 callindent, insn, insnlen. Field list can be prepended with the type, trace, sw or hw,
121 to indicate to which event type the field list applies. 121 to indicate to which event type the field list applies.
122 e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace 122 e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
@@ -189,15 +189,20 @@ OPTIONS
189 i.e., -F "" is not allowed. 189 i.e., -F "" is not allowed.
190 190
191 The brstack output includes branch related information with raw addresses using the 191 The brstack output includes branch related information with raw addresses using the
192 /v/v/v/v/ syntax in the following order: 192 /v/v/v/v/cycles syntax in the following order:
193 FROM: branch source instruction 193 FROM: branch source instruction
194 TO : branch target instruction 194 TO : branch target instruction
195 M/P/-: M=branch target mispredicted or branch direction was mispredicted, P=target predicted or direction predicted, -=not supported 195 M/P/-: M=branch target mispredicted or branch direction was mispredicted, P=target predicted or direction predicted, -=not supported
196 X/- : X=branch inside a transactional region, -=not in transaction region or not supported 196 X/- : X=branch inside a transactional region, -=not in transaction region or not supported
197 A/- : A=TSX abort entry, -=not aborted region or not supported 197 A/- : A=TSX abort entry, -=not aborted region or not supported
198 cycles
198 199
199 The brstacksym is identical to brstack, except that the FROM and TO addresses are printed in a symbolic form if possible. 200 The brstacksym is identical to brstack, except that the FROM and TO addresses are printed in a symbolic form if possible.
200 201
202 When brstackinsn is specified the full assembler sequences of branch sequences for each sample
203 is printed. This is the full execution path leading to the sample. This is only supported when the
204 sample was recorded with perf record -b or -j any.
205
201-k:: 206-k::
202--vmlinux=<file>:: 207--vmlinux=<file>::
203 vmlinux pathname 208 vmlinux pathname
@@ -248,6 +253,9 @@ OPTIONS
248--show-mmap-events 253--show-mmap-events
249 Display mmap related events (e.g. MMAP, MMAP2). 254 Display mmap related events (e.g. MMAP, MMAP2).
250 255
256--show-namespace-events
257 Display namespace events i.e. events of type PERF_RECORD_NAMESPACES.
258
251--show-switch-events 259--show-switch-events
252 Display context switch events i.e. events of type PERF_RECORD_SWITCH or 260 Display context switch events i.e. events of type PERF_RECORD_SWITCH or
253 PERF_RECORD_SWITCH_CPU_WIDE. 261 PERF_RECORD_SWITCH_CPU_WIDE.
@@ -299,6 +307,10 @@ include::itrace.txt[]
299 stop time is not given (i.e, time string is 'x.y,') then analysis goes 307 stop time is not given (i.e, time string is 'x.y,') then analysis goes
300 to end of file. 308 to end of file.
301 309
310--max-blocks::
311 Set the maximum number of program blocks to print with brstackasm for
312 each sample.
313
302SEE ALSO 314SEE ALSO
303-------- 315--------
304linkperf:perf-record[1], linkperf:perf-script-perl[1], 316linkperf:perf-record[1], linkperf:perf-script-perl[1],
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index aecf2a87e7d6..bd0e4417f2be 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -94,8 +94,7 @@ to activate system-wide monitoring. Default is to count on all CPUs.
94 94
95-A:: 95-A::
96--no-aggr:: 96--no-aggr::
97Do not aggregate counts across all monitored CPUs in system-wide mode (-a). 97Do not aggregate counts across all monitored CPUs.
98This option is only valid in system-wide mode.
99 98
100-n:: 99-n::
101--null:: 100--null::
@@ -237,6 +236,9 @@ To interpret the results it is usually needed to know on which
237CPUs the workload runs on. If needed the CPUs can be forced using 236CPUs the workload runs on. If needed the CPUs can be forced using
238taskset. 237taskset.
239 238
239--no-merge::
240Do not merge results from same PMUs.
241
240EXAMPLES 242EXAMPLES
241-------- 243--------
242 244
diff --git a/tools/perf/Documentation/perf-trace.txt b/tools/perf/Documentation/perf-trace.txt
index afd728672b6f..c1e3288a2dfb 100644
--- a/tools/perf/Documentation/perf-trace.txt
+++ b/tools/perf/Documentation/perf-trace.txt
@@ -123,7 +123,8 @@ the thread executes on the designated CPUs. Default is to monitor all CPUs.
123 major or all pagefaults. Default value is maj. 123 major or all pagefaults. Default value is maj.
124 124
125--syscalls:: 125--syscalls::
126 Trace system calls. This options is enabled by default. 126 Trace system calls. This options is enabled by default, disable with
127 --no-syscalls.
127 128
128--call-graph [mode,type,min[,limit],order[,key][,branch]]:: 129--call-graph [mode,type,min[,limit],order[,key][,branch]]::
129 Setup and enable call-graph (stack chain/backtrace) recording. 130 Setup and enable call-graph (stack chain/backtrace) recording.
diff --git a/tools/perf/Documentation/perf.data-file-format.txt b/tools/perf/Documentation/perf.data-file-format.txt
index b664b18d3991..fa2a9132f0a9 100644
--- a/tools/perf/Documentation/perf.data-file-format.txt
+++ b/tools/perf/Documentation/perf.data-file-format.txt
@@ -11,8 +11,8 @@ All fields are in native-endian of the machine that generated the perf.data.
11 11
12When perf is writing to a pipe it uses a special version of the file 12When perf is writing to a pipe it uses a special version of the file
13format that does not rely on seeking to adjust data offsets. This 13format that does not rely on seeking to adjust data offsets. This
14format is not described here. The pipe version can be converted to 14format is described in "Pipe-mode data" section. The pipe data version can be
15normal perf.data with perf inject. 15augmented with additional events using perf inject.
16 16
17The file starts with a perf_header: 17The file starts with a perf_header:
18 18
@@ -411,6 +411,21 @@ An array bound by the perf_file_section size.
411 411
412ids points to a array of uint64_t defining the ids for event attr attr. 412ids points to a array of uint64_t defining the ids for event attr attr.
413 413
414Pipe-mode data
415
416Pipe-mode avoid seeks in the file by removing the perf_file_section and flags
417from the struct perf_header. The trimmed header is:
418
419struct perf_pipe_file_header {
420 u64 magic;
421 u64 size;
422};
423
424The information about attrs, data, and event_types is instead in the
425synthesized events PERF_RECORD_ATTR, PERF_RECORD_HEADER_TRACING_DATA and
426PERF_RECORD_HEADER_EVENT_TYPE that are generated by perf record in pipe-mode.
427
428
414References: 429References:
415 430
416include/uapi/linux/perf_event.h 431include/uapi/linux/perf_event.h
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 8672f835ae4e..a29da46d180f 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -12,6 +12,7 @@ tools/arch/sparc/include/asm/barrier_32.h
12tools/arch/sparc/include/asm/barrier_64.h 12tools/arch/sparc/include/asm/barrier_64.h
13tools/arch/tile/include/asm/barrier.h 13tools/arch/tile/include/asm/barrier.h
14tools/arch/x86/include/asm/barrier.h 14tools/arch/x86/include/asm/barrier.h
15tools/arch/x86/include/asm/cmpxchg.h
15tools/arch/x86/include/asm/cpufeatures.h 16tools/arch/x86/include/asm/cpufeatures.h
16tools/arch/x86/include/asm/disabled-features.h 17tools/arch/x86/include/asm/disabled-features.h
17tools/arch/x86/include/asm/required-features.h 18tools/arch/x86/include/asm/required-features.h
@@ -63,6 +64,7 @@ tools/include/linux/bitops.h
63tools/include/linux/compiler.h 64tools/include/linux/compiler.h
64tools/include/linux/compiler-gcc.h 65tools/include/linux/compiler-gcc.h
65tools/include/linux/coresight-pmu.h 66tools/include/linux/coresight-pmu.h
67tools/include/linux/bug.h
66tools/include/linux/filter.h 68tools/include/linux/filter.h
67tools/include/linux/hash.h 69tools/include/linux/hash.h
68tools/include/linux/kernel.h 70tools/include/linux/kernel.h
@@ -72,12 +74,15 @@ tools/include/uapi/asm-generic/mman-common.h
72tools/include/uapi/asm-generic/mman.h 74tools/include/uapi/asm-generic/mman.h
73tools/include/uapi/linux/bpf.h 75tools/include/uapi/linux/bpf.h
74tools/include/uapi/linux/bpf_common.h 76tools/include/uapi/linux/bpf_common.h
77tools/include/uapi/linux/fcntl.h
75tools/include/uapi/linux/hw_breakpoint.h 78tools/include/uapi/linux/hw_breakpoint.h
76tools/include/uapi/linux/mman.h 79tools/include/uapi/linux/mman.h
77tools/include/uapi/linux/perf_event.h 80tools/include/uapi/linux/perf_event.h
81tools/include/uapi/linux/stat.h
78tools/include/linux/poison.h 82tools/include/linux/poison.h
79tools/include/linux/rbtree.h 83tools/include/linux/rbtree.h
80tools/include/linux/rbtree_augmented.h 84tools/include/linux/rbtree_augmented.h
85tools/include/linux/refcount.h
81tools/include/linux/string.h 86tools/include/linux/string.h
82tools/include/linux/stringify.h 87tools/include/linux/stringify.h
83tools/include/linux/types.h 88tools/include/linux/types.h
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 27c9fbca7bd9..8354d04b392f 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -170,13 +170,20 @@ PYTHON2_CONFIG := \
170override PYTHON_CONFIG := \ 170override PYTHON_CONFIG := \
171 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON2_CONFIG)) 171 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON2_CONFIG))
172 172
173PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG)) 173grep-libs = $(filter -l%,$(1))
174strip-libs = $(filter-out -l%,$(1))
174 175
175PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null) 176PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
176PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
177 177
178ifeq ($(CC), clang) 178ifdef PYTHON_CONFIG
179 PYTHON_EMBED_CCOPTS := $(filter-out -specs=%,$(PYTHON_EMBED_CCOPTS)) 179 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
180 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
181 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
182 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
183 ifeq ($(CC), clang)
184 PYTHON_EMBED_CCOPTS := $(filter-out -specs=%,$(PYTHON_EMBED_CCOPTS))
185 endif
186 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
180endif 187endif
181 188
182FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS) 189FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
@@ -267,6 +274,7 @@ ifdef NO_LIBELF
267 NO_LIBUNWIND := 1 274 NO_LIBUNWIND := 1
268 NO_LIBDW_DWARF_UNWIND := 1 275 NO_LIBDW_DWARF_UNWIND := 1
269 NO_LIBBPF := 1 276 NO_LIBBPF := 1
277 NO_JVMTI := 1
270else 278else
271 ifeq ($(feature-libelf), 0) 279 ifeq ($(feature-libelf), 0)
272 ifeq ($(feature-glibc), 1) 280 ifeq ($(feature-glibc), 1)
@@ -276,7 +284,7 @@ else
276 LIBC_SUPPORT := 1 284 LIBC_SUPPORT := 1
277 endif 285 endif
278 ifeq ($(LIBC_SUPPORT),1) 286 ifeq ($(LIBC_SUPPORT),1)
279 msg := $(warning No libelf found, disables 'probe' tool and BPF support in 'perf record', please install libelf-dev, libelf-devel or elfutils-libelf-devel); 287 msg := $(warning No libelf found. Disables 'probe' tool, jvmti and BPF support in 'perf record'. Please install libelf-dev, libelf-devel or elfutils-libelf-devel);
280 288
281 NO_LIBELF := 1 289 NO_LIBELF := 1
282 NO_DWARF := 1 290 NO_DWARF := 1
@@ -284,6 +292,7 @@ else
284 NO_LIBUNWIND := 1 292 NO_LIBUNWIND := 1
285 NO_LIBDW_DWARF_UNWIND := 1 293 NO_LIBDW_DWARF_UNWIND := 1
286 NO_LIBBPF := 1 294 NO_LIBBPF := 1
295 NO_JVMTI := 1
287 else 296 else
288 ifneq ($(filter s% -static%,$(LDFLAGS),),) 297 ifneq ($(filter s% -static%,$(LDFLAGS),),)
289 msg := $(error No static glibc found, please install glibc-static); 298 msg := $(error No static glibc found, please install glibc-static);
@@ -317,6 +326,10 @@ ifdef NO_DWARF
317 NO_LIBDW_DWARF_UNWIND := 1 326 NO_LIBDW_DWARF_UNWIND := 1
318endif 327endif
319 328
329ifeq ($(feature-sched_getcpu), 1)
330 CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
331endif
332
320ifndef NO_LIBELF 333ifndef NO_LIBELF
321 CFLAGS += -DHAVE_LIBELF_SUPPORT 334 CFLAGS += -DHAVE_LIBELF_SUPPORT
322 EXTLIBS += -lelf 335 EXTLIBS += -lelf
@@ -550,8 +563,6 @@ ifndef NO_GTK2
550 endif 563 endif
551endif 564endif
552 565
553grep-libs = $(filter -l%,$(1))
554strip-libs = $(filter-out -l%,$(1))
555 566
556ifdef NO_LIBPERL 567ifdef NO_LIBPERL
557 CFLAGS += -DNO_LIBPERL 568 CFLAGS += -DNO_LIBPERL
@@ -599,21 +610,9 @@ else
599 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev) 610 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
600 else 611 else
601 612
602 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
603
604 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
605 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
606 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
607 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
608 ifeq ($(CC), clang)
609 PYTHON_EMBED_CCOPTS := $(filter-out -specs=%,$(PYTHON_EMBED_CCOPTS))
610 endif
611 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
612
613 ifneq ($(feature-libpython), 1) 613 ifneq ($(feature-libpython), 1)
614 $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev) 614 $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
615 else 615 else
616
617 ifneq ($(feature-libpython-version), 1) 616 ifneq ($(feature-libpython-version), 1)
618 $(warning Python 3 is not yet supported; please set) 617 $(warning Python 3 is not yet supported; please set)
619 $(warning PYTHON and/or PYTHON_CONFIG appropriately.) 618 $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index dfea6b635525..29361d9b635a 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -33,6 +33,7 @@
33#include "../../util/cs-etm.h" 33#include "../../util/cs-etm.h"
34 34
35#include <stdlib.h> 35#include <stdlib.h>
36#include <sys/stat.h>
36 37
37#define ENABLE_SINK_MAX 128 38#define ENABLE_SINK_MAX 128
38#define CS_BUS_DEVICE_PATH "/bus/coresight/devices/" 39#define CS_BUS_DEVICE_PATH "/bus/coresight/devices/"
diff --git a/tools/perf/arch/arm/util/dwarf-regs.c b/tools/perf/arch/arm/util/dwarf-regs.c
index 33ec5b339da8..8bb176a37990 100644
--- a/tools/perf/arch/arm/util/dwarf-regs.c
+++ b/tools/perf/arch/arm/util/dwarf-regs.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <stddef.h> 11#include <stddef.h>
12#include <linux/stringify.h>
12#include <dwarf-regs.h> 13#include <dwarf-regs.h>
13 14
14struct pt_regs_dwarfnum { 15struct pt_regs_dwarfnum {
@@ -16,10 +17,9 @@ struct pt_regs_dwarfnum {
16 unsigned int dwarfnum; 17 unsigned int dwarfnum;
17}; 18};
18 19
19#define STR(s) #s
20#define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num} 20#define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num}
21#define GPR_DWARFNUM_NAME(num) \ 21#define GPR_DWARFNUM_NAME(num) \
22 {.name = STR(%r##num), .dwarfnum = num} 22 {.name = __stringify(%r##num), .dwarfnum = num}
23#define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0} 23#define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0}
24 24
25/* 25/*
diff --git a/tools/perf/arch/arm/util/unwind-libdw.c b/tools/perf/arch/arm/util/unwind-libdw.c
index b4176c60117a..bacfa00fca39 100644
--- a/tools/perf/arch/arm/util/unwind-libdw.c
+++ b/tools/perf/arch/arm/util/unwind-libdw.c
@@ -1,6 +1,7 @@
1#include <elfutils/libdwfl.h> 1#include <elfutils/libdwfl.h>
2#include "../../util/unwind-libdw.h" 2#include "../../util/unwind-libdw.h"
3#include "../../util/perf_regs.h" 3#include "../../util/perf_regs.h"
4#include "../../util/event.h"
4 5
5bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg) 6bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
6{ 7{
diff --git a/tools/perf/arch/arm64/util/dwarf-regs.c b/tools/perf/arch/arm64/util/dwarf-regs.c
index 068b6189157b..cd764a9fd098 100644
--- a/tools/perf/arch/arm64/util/dwarf-regs.c
+++ b/tools/perf/arch/arm64/util/dwarf-regs.c
@@ -8,9 +8,12 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11#include <errno.h>
11#include <stddef.h> 12#include <stddef.h>
13#include <string.h>
12#include <dwarf-regs.h> 14#include <dwarf-regs.h>
13#include <linux/ptrace.h> /* for struct user_pt_regs */ 15#include <linux/ptrace.h> /* for struct user_pt_regs */
16#include <linux/stringify.h>
14#include "util.h" 17#include "util.h"
15 18
16struct pt_regs_dwarfnum { 19struct pt_regs_dwarfnum {
@@ -20,7 +23,7 @@ struct pt_regs_dwarfnum {
20 23
21#define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num} 24#define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num}
22#define GPR_DWARFNUM_NAME(num) \ 25#define GPR_DWARFNUM_NAME(num) \
23 {.name = STR(%x##num), .dwarfnum = num} 26 {.name = __stringify(%x##num), .dwarfnum = num}
24#define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0} 27#define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0}
25#define DWARFNUM2OFFSET(index) \ 28#define DWARFNUM2OFFSET(index) \
26 (index * sizeof((struct user_pt_regs *)0)->regs[0]) 29 (index * sizeof((struct user_pt_regs *)0)->regs[0])
diff --git a/tools/perf/arch/arm64/util/unwind-libunwind.c b/tools/perf/arch/arm64/util/unwind-libunwind.c
index c116b713f7f7..b415dfdbccca 100644
--- a/tools/perf/arch/arm64/util/unwind-libunwind.c
+++ b/tools/perf/arch/arm64/util/unwind-libunwind.c
@@ -1,6 +1,6 @@
1#include <errno.h>
1 2
2#ifndef REMOTE_UNWIND_LIBUNWIND 3#ifndef REMOTE_UNWIND_LIBUNWIND
3#include <errno.h>
4#include <libunwind.h> 4#include <libunwind.h>
5#include "perf_regs.h" 5#include "perf_regs.h"
6#include "../../util/unwind.h" 6#include "../../util/unwind.h"
diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c
index 886dd2aaff0d..837067f48a4c 100644
--- a/tools/perf/arch/common.c
+++ b/tools/perf/arch/common.c
@@ -4,6 +4,8 @@
4#include "../util/util.h" 4#include "../util/util.h"
5#include "../util/debug.h" 5#include "../util/debug.h"
6 6
7#include "sane_ctype.h"
8
7const char *const arm_triplets[] = { 9const char *const arm_triplets[] = {
8 "arm-eabi-", 10 "arm-eabi-",
9 "arm-linux-androideabi-", 11 "arm-linux-androideabi-",
diff --git a/tools/perf/arch/powerpc/util/dwarf-regs.c b/tools/perf/arch/powerpc/util/dwarf-regs.c
index 41bdf9530d82..98ac87052a74 100644
--- a/tools/perf/arch/powerpc/util/dwarf-regs.c
+++ b/tools/perf/arch/powerpc/util/dwarf-regs.c
@@ -15,6 +15,7 @@
15#include <dwarf-regs.h> 15#include <dwarf-regs.h>
16#include <linux/ptrace.h> 16#include <linux/ptrace.h>
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/stringify.h>
18#include "util.h" 19#include "util.h"
19 20
20struct pt_regs_dwarfnum { 21struct pt_regs_dwarfnum {
@@ -24,10 +25,10 @@ struct pt_regs_dwarfnum {
24}; 25};
25 26
26#define REG_DWARFNUM_NAME(r, num) \ 27#define REG_DWARFNUM_NAME(r, num) \
27 {.name = STR(%)STR(r), .dwarfnum = num, \ 28 {.name = __stringify(%)__stringify(r), .dwarfnum = num, \
28 .ptregs_offset = offsetof(struct pt_regs, r)} 29 .ptregs_offset = offsetof(struct pt_regs, r)}
29#define GPR_DWARFNUM_NAME(num) \ 30#define GPR_DWARFNUM_NAME(num) \
30 {.name = STR(%gpr##num), .dwarfnum = num, \ 31 {.name = __stringify(%gpr##num), .dwarfnum = num, \
31 .ptregs_offset = offsetof(struct pt_regs, gpr[num])} 32 .ptregs_offset = offsetof(struct pt_regs, gpr[num])}
32#define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0, .ptregs_offset = 0} 33#define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0, .ptregs_offset = 0}
33 34
diff --git a/tools/perf/arch/powerpc/util/kvm-stat.c b/tools/perf/arch/powerpc/util/kvm-stat.c
index 74eee30398f8..249723f0e6a9 100644
--- a/tools/perf/arch/powerpc/util/kvm-stat.c
+++ b/tools/perf/arch/powerpc/util/kvm-stat.c
@@ -1,3 +1,4 @@
1#include <errno.h>
1#include "util/kvm-stat.h" 2#include "util/kvm-stat.h"
2#include "util/parse-events.h" 3#include "util/parse-events.h"
3#include "util/debug.h" 4#include "util/debug.h"
diff --git a/tools/perf/arch/powerpc/util/perf_regs.c b/tools/perf/arch/powerpc/util/perf_regs.c
index a3c3e1ce6807..f860dc411f69 100644
--- a/tools/perf/arch/powerpc/util/perf_regs.c
+++ b/tools/perf/arch/powerpc/util/perf_regs.c
@@ -1,5 +1,11 @@
1#include <errno.h>
2#include <string.h>
3#include <regex.h>
4
1#include "../../perf.h" 5#include "../../perf.h"
6#include "../../util/util.h"
2#include "../../util/perf_regs.h" 7#include "../../util/perf_regs.h"
8#include "../../util/debug.h"
3 9
4const struct sample_reg sample_reg_masks[] = { 10const struct sample_reg sample_reg_masks[] = {
5 SMPL_REG(r0, PERF_REG_POWERPC_R0), 11 SMPL_REG(r0, PERF_REG_POWERPC_R0),
@@ -47,3 +53,109 @@ const struct sample_reg sample_reg_masks[] = {
47 SMPL_REG(dsisr, PERF_REG_POWERPC_DSISR), 53 SMPL_REG(dsisr, PERF_REG_POWERPC_DSISR),
48 SMPL_REG_END 54 SMPL_REG_END
49}; 55};
56
57/* REG or %rREG */
58#define SDT_OP_REGEX1 "^(%r)?([1-2]?[0-9]|3[0-1])$"
59
60/* -NUM(REG) or NUM(REG) or -NUM(%rREG) or NUM(%rREG) */
61#define SDT_OP_REGEX2 "^(\\-)?([0-9]+)\\((%r)?([1-2]?[0-9]|3[0-1])\\)$"
62
63static regex_t sdt_op_regex1, sdt_op_regex2;
64
65static int sdt_init_op_regex(void)
66{
67 static int initialized;
68 int ret = 0;
69
70 if (initialized)
71 return 0;
72
73 ret = regcomp(&sdt_op_regex1, SDT_OP_REGEX1, REG_EXTENDED);
74 if (ret)
75 goto error;
76
77 ret = regcomp(&sdt_op_regex2, SDT_OP_REGEX2, REG_EXTENDED);
78 if (ret)
79 goto free_regex1;
80
81 initialized = 1;
82 return 0;
83
84free_regex1:
85 regfree(&sdt_op_regex1);
86error:
87 pr_debug4("Regex compilation error.\n");
88 return ret;
89}
90
91/*
92 * Parse OP and convert it into uprobe format, which is, +/-NUM(%gprREG).
93 * Possible variants of OP are:
94 * Format Example
95 * -------------------------
96 * NUM(REG) 48(18)
97 * -NUM(REG) -48(18)
98 * NUM(%rREG) 48(%r18)
99 * -NUM(%rREG) -48(%r18)
100 * REG 18
101 * %rREG %r18
102 * iNUM i0
103 * i-NUM i-1
104 *
105 * SDT marker arguments on Powerpc uses %rREG form with -mregnames flag
106 * and REG form with -mno-regnames. Here REG is general purpose register,
107 * which is in 0 to 31 range.
108 */
109int arch_sdt_arg_parse_op(char *old_op, char **new_op)
110{
111 int ret, new_len;
112 regmatch_t rm[5];
113 char prefix;
114
115 /* Constant argument. Uprobe does not support it */
116 if (old_op[0] == 'i') {
117 pr_debug4("Skipping unsupported SDT argument: %s\n", old_op);
118 return SDT_ARG_SKIP;
119 }
120
121 ret = sdt_init_op_regex();
122 if (ret < 0)
123 return ret;
124
125 if (!regexec(&sdt_op_regex1, old_op, 3, rm, 0)) {
126 /* REG or %rREG --> %gprREG */
127
128 new_len = 5; /* % g p r NULL */
129 new_len += (int)(rm[2].rm_eo - rm[2].rm_so);
130
131 *new_op = zalloc(new_len);
132 if (!*new_op)
133 return -ENOMEM;
134
135 scnprintf(*new_op, new_len, "%%gpr%.*s",
136 (int)(rm[2].rm_eo - rm[2].rm_so), old_op + rm[2].rm_so);
137 } else if (!regexec(&sdt_op_regex2, old_op, 5, rm, 0)) {
138 /*
139 * -NUM(REG) or NUM(REG) or -NUM(%rREG) or NUM(%rREG) -->
140 * +/-NUM(%gprREG)
141 */
142 prefix = (rm[1].rm_so == -1) ? '+' : '-';
143
144 new_len = 8; /* +/- ( % g p r ) NULL */
145 new_len += (int)(rm[2].rm_eo - rm[2].rm_so);
146 new_len += (int)(rm[4].rm_eo - rm[4].rm_so);
147
148 *new_op = zalloc(new_len);
149 if (!*new_op)
150 return -ENOMEM;
151
152 scnprintf(*new_op, new_len, "%c%.*s(%%gpr%.*s)", prefix,
153 (int)(rm[2].rm_eo - rm[2].rm_so), old_op + rm[2].rm_so,
154 (int)(rm[4].rm_eo - rm[4].rm_so), old_op + rm[4].rm_so);
155 } else {
156 pr_debug4("Skipping unsupported SDT argument: %s\n", old_op);
157 return SDT_ARG_SKIP;
158 }
159
160 return SDT_ARG_VALID;
161}
diff --git a/tools/perf/arch/powerpc/util/sym-handling.c b/tools/perf/arch/powerpc/util/sym-handling.c
index 1030a6e504bb..39dbe512b9fc 100644
--- a/tools/perf/arch/powerpc/util/sym-handling.c
+++ b/tools/perf/arch/powerpc/util/sym-handling.c
@@ -10,6 +10,7 @@
10#include "symbol.h" 10#include "symbol.h"
11#include "map.h" 11#include "map.h"
12#include "probe-event.h" 12#include "probe-event.h"
13#include "probe-file.h"
13 14
14#ifdef HAVE_LIBELF_SUPPORT 15#ifdef HAVE_LIBELF_SUPPORT
15bool elf__needs_adjust_symbols(GElf_Ehdr ehdr) 16bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
@@ -79,13 +80,18 @@ void arch__fix_tev_from_maps(struct perf_probe_event *pev,
79 * However, if the user specifies an offset, we fall back to using the 80 * However, if the user specifies an offset, we fall back to using the
80 * GEP since all userspace applications (objdump/readelf) show function 81 * GEP since all userspace applications (objdump/readelf) show function
81 * disassembly with offsets from the GEP. 82 * disassembly with offsets from the GEP.
82 *
83 * In addition, we shouldn't specify an offset for kretprobes.
84 */ 83 */
85 if (pev->point.offset || (!pev->uprobes && pev->point.retprobe) || 84 if (pev->point.offset || !map || !sym)
86 !map || !sym)
87 return; 85 return;
88 86
87 /* For kretprobes, add an offset only if the kernel supports it */
88 if (!pev->uprobes && pev->point.retprobe) {
89#ifdef HAVE_LIBELF_SUPPORT
90 if (!kretprobe_offset_is_supported())
91#endif
92 return;
93 }
94
89 lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym); 95 lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);
90 96
91 if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS) 97 if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS)
diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/arch/s390/annotate/instructions.c
new file mode 100644
index 000000000000..745b4b1b8b21
--- /dev/null
+++ b/tools/perf/arch/s390/annotate/instructions.c
@@ -0,0 +1,30 @@
1static struct ins_ops *s390__associate_ins_ops(struct arch *arch, const char *name)
2{
3 struct ins_ops *ops = NULL;
4
5 /* catch all kind of jumps */
6 if (strchr(name, 'j') ||
7 !strncmp(name, "bct", 3) ||
8 !strncmp(name, "br", 2))
9 ops = &jump_ops;
10 /* override call/returns */
11 if (!strcmp(name, "bras") ||
12 !strcmp(name, "brasl") ||
13 !strcmp(name, "basr"))
14 ops = &call_ops;
15 if (!strcmp(name, "br"))
16 ops = &ret_ops;
17
18 arch__associate_ins_ops(arch, name, ops);
19 return ops;
20}
21
22static int s390__annotate_init(struct arch *arch)
23{
24 if (!arch->initialized) {
25 arch->initialized = true;
26 arch->associate_instruction_ops = s390__associate_ins_ops;
27 }
28
29 return 0;
30}
diff --git a/tools/perf/arch/s390/util/kvm-stat.c b/tools/perf/arch/s390/util/kvm-stat.c
index ed57df2e6d68..d233e2eb9592 100644
--- a/tools/perf/arch/s390/util/kvm-stat.c
+++ b/tools/perf/arch/s390/util/kvm-stat.c
@@ -9,6 +9,7 @@
9 * as published by the Free Software Foundation. 9 * as published by the Free Software Foundation.
10 */ 10 */
11 11
12#include <errno.h>
12#include "../../util/kvm-stat.h" 13#include "../../util/kvm-stat.h"
13#include <asm/sie.h> 14#include <asm/sie.h>
14 15
diff --git a/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl b/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
index e93ef0b38db8..5aef183e2f85 100644
--- a/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
@@ -338,6 +338,7 @@
338329 common pkey_mprotect sys_pkey_mprotect 338329 common pkey_mprotect sys_pkey_mprotect
339330 common pkey_alloc sys_pkey_alloc 339330 common pkey_alloc sys_pkey_alloc
340331 common pkey_free sys_pkey_free 340331 common pkey_free sys_pkey_free
341332 common statx sys_statx
341 342
342# 343#
343# x32-specific system call numbers start at 512 to avoid cache impact 344# x32-specific system call numbers start at 512 to avoid cache impact
diff --git a/tools/perf/arch/x86/tests/intel-cqm.c b/tools/perf/arch/x86/tests/intel-cqm.c
index 7f064eb37158..f9713a71d77e 100644
--- a/tools/perf/arch/x86/tests/intel-cqm.c
+++ b/tools/perf/arch/x86/tests/intel-cqm.c
@@ -6,7 +6,10 @@
6#include "evsel.h" 6#include "evsel.h"
7#include "arch-tests.h" 7#include "arch-tests.h"
8 8
9#include <signal.h>
9#include <sys/mman.h> 10#include <sys/mman.h>
11#include <sys/wait.h>
12#include <errno.h>
10#include <string.h> 13#include <string.h>
11 14
12static pid_t spawn(void) 15static pid_t spawn(void)
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 5c76cc83186a..e3ae9cff2b67 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -1,3 +1,5 @@
1#include <errno.h>
2#include <inttypes.h>
1#include <stdio.h> 3#include <stdio.h>
2#include <unistd.h> 4#include <unistd.h>
3#include <linux/types.h> 5#include <linux/types.h>
diff --git a/tools/perf/arch/x86/util/auxtrace.c b/tools/perf/arch/x86/util/auxtrace.c
index cc1d865e31f1..6aa3f2a38321 100644
--- a/tools/perf/arch/x86/util/auxtrace.c
+++ b/tools/perf/arch/x86/util/auxtrace.c
@@ -13,6 +13,7 @@
13 * 13 *
14 */ 14 */
15 15
16#include <errno.h>
16#include <stdbool.h> 17#include <stdbool.h>
17 18
18#include "../../util/header.h" 19#include "../../util/header.h"
diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index 5132775a044f..af2bce7a2cd6 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -13,6 +13,7 @@
13 * 13 *
14 */ 14 */
15 15
16#include <errno.h>
16#include <linux/kernel.h> 17#include <linux/kernel.h>
17#include <linux/types.h> 18#include <linux/types.h>
18#include <linux/bitops.h> 19#include <linux/bitops.h>
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index 90fa2286edcf..f630de0206a1 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -13,6 +13,7 @@
13 * 13 *
14 */ 14 */
15 15
16#include <errno.h>
16#include <stdbool.h> 17#include <stdbool.h>
17#include <linux/kernel.h> 18#include <linux/kernel.h>
18#include <linux/types.h> 19#include <linux/types.h>
diff --git a/tools/perf/arch/x86/util/kvm-stat.c b/tools/perf/arch/x86/util/kvm-stat.c
index b63d4be655a2..bf817beca0a8 100644
--- a/tools/perf/arch/x86/util/kvm-stat.c
+++ b/tools/perf/arch/x86/util/kvm-stat.c
@@ -1,3 +1,4 @@
1#include <errno.h>
1#include "../../util/kvm-stat.h" 2#include "../../util/kvm-stat.h"
2#include <asm/svm.h> 3#include <asm/svm.h>
3#include <asm/vmx.h> 4#include <asm/vmx.h>
diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/perf_regs.c
index c5db14f36cc7..f95edebfb716 100644
--- a/tools/perf/arch/x86/util/perf_regs.c
+++ b/tools/perf/arch/x86/util/perf_regs.c
@@ -1,5 +1,11 @@
1#include <errno.h>
2#include <string.h>
3#include <regex.h>
4
1#include "../../perf.h" 5#include "../../perf.h"
6#include "../../util/util.h"
2#include "../../util/perf_regs.h" 7#include "../../util/perf_regs.h"
8#include "../../util/debug.h"
3 9
4const struct sample_reg sample_reg_masks[] = { 10const struct sample_reg sample_reg_masks[] = {
5 SMPL_REG(AX, PERF_REG_X86_AX), 11 SMPL_REG(AX, PERF_REG_X86_AX),
@@ -26,3 +32,224 @@ const struct sample_reg sample_reg_masks[] = {
26#endif 32#endif
27 SMPL_REG_END 33 SMPL_REG_END
28}; 34};
35
36struct sdt_name_reg {
37 const char *sdt_name;
38 const char *uprobe_name;
39};
40#define SDT_NAME_REG(n, m) {.sdt_name = "%" #n, .uprobe_name = "%" #m}
41#define SDT_NAME_REG_END {.sdt_name = NULL, .uprobe_name = NULL}
42
43static const struct sdt_name_reg sdt_reg_tbl[] = {
44 SDT_NAME_REG(eax, ax),
45 SDT_NAME_REG(rax, ax),
46 SDT_NAME_REG(al, ax),
47 SDT_NAME_REG(ah, ax),
48 SDT_NAME_REG(ebx, bx),
49 SDT_NAME_REG(rbx, bx),
50 SDT_NAME_REG(bl, bx),
51 SDT_NAME_REG(bh, bx),
52 SDT_NAME_REG(ecx, cx),
53 SDT_NAME_REG(rcx, cx),
54 SDT_NAME_REG(cl, cx),
55 SDT_NAME_REG(ch, cx),
56 SDT_NAME_REG(edx, dx),
57 SDT_NAME_REG(rdx, dx),
58 SDT_NAME_REG(dl, dx),
59 SDT_NAME_REG(dh, dx),
60 SDT_NAME_REG(esi, si),
61 SDT_NAME_REG(rsi, si),
62 SDT_NAME_REG(sil, si),
63 SDT_NAME_REG(edi, di),
64 SDT_NAME_REG(rdi, di),
65 SDT_NAME_REG(dil, di),
66 SDT_NAME_REG(ebp, bp),
67 SDT_NAME_REG(rbp, bp),
68 SDT_NAME_REG(bpl, bp),
69 SDT_NAME_REG(rsp, sp),
70 SDT_NAME_REG(esp, sp),
71 SDT_NAME_REG(spl, sp),
72
73 /* rNN registers */
74 SDT_NAME_REG(r8b, r8),
75 SDT_NAME_REG(r8w, r8),
76 SDT_NAME_REG(r8d, r8),
77 SDT_NAME_REG(r9b, r9),
78 SDT_NAME_REG(r9w, r9),
79 SDT_NAME_REG(r9d, r9),
80 SDT_NAME_REG(r10b, r10),
81 SDT_NAME_REG(r10w, r10),
82 SDT_NAME_REG(r10d, r10),
83 SDT_NAME_REG(r11b, r11),
84 SDT_NAME_REG(r11w, r11),
85 SDT_NAME_REG(r11d, r11),
86 SDT_NAME_REG(r12b, r12),
87 SDT_NAME_REG(r12w, r12),
88 SDT_NAME_REG(r12d, r12),
89 SDT_NAME_REG(r13b, r13),
90 SDT_NAME_REG(r13w, r13),
91 SDT_NAME_REG(r13d, r13),
92 SDT_NAME_REG(r14b, r14),
93 SDT_NAME_REG(r14w, r14),
94 SDT_NAME_REG(r14d, r14),
95 SDT_NAME_REG(r15b, r15),
96 SDT_NAME_REG(r15w, r15),
97 SDT_NAME_REG(r15d, r15),
98 SDT_NAME_REG_END,
99};
100
101/*
102 * Perf only supports OP which is in +/-NUM(REG) form.
103 * Here plus-minus sign, NUM and parenthesis are optional,
104 * only REG is mandatory.
105 *
106 * SDT events also supports indirect addressing mode with a
107 * symbol as offset, scaled mode and constants in OP. But
108 * perf does not support them yet. Below are few examples.
109 *
110 * OP with scaled mode:
111 * (%rax,%rsi,8)
112 * 10(%ras,%rsi,8)
113 *
114 * OP with indirect addressing mode:
115 * check_action(%rip)
116 * mp_+52(%rip)
117 * 44+mp_(%rip)
118 *
119 * OP with constant values:
120 * $0
121 * $123
122 * $-1
123 */
124#define SDT_OP_REGEX "^([+\\-]?)([0-9]*)(\\(?)(%[a-z][a-z0-9]+)(\\)?)$"
125
126static regex_t sdt_op_regex;
127
128static int sdt_init_op_regex(void)
129{
130 static int initialized;
131 int ret = 0;
132
133 if (initialized)
134 return 0;
135
136 ret = regcomp(&sdt_op_regex, SDT_OP_REGEX, REG_EXTENDED);
137 if (ret < 0) {
138 pr_debug4("Regex compilation error.\n");
139 return ret;
140 }
141
142 initialized = 1;
143 return 0;
144}
145
146/*
147 * Max x86 register name length is 5(ex: %r15d). So, 6th char
148 * should always contain NULL. This helps to find register name
149 * length using strlen, insted of maintaing one more variable.
150 */
151#define SDT_REG_NAME_SIZE 6
152
153/*
154 * The uprobe parser does not support all gas register names;
155 * so, we have to replace them (ex. for x86_64: %rax -> %ax).
156 * Note: If register does not require renaming, just copy
157 * paste as it is, but don't leave it empty.
158 */
159static void sdt_rename_register(char *sdt_reg, int sdt_len, char *uprobe_reg)
160{
161 int i = 0;
162
163 for (i = 0; sdt_reg_tbl[i].sdt_name != NULL; i++) {
164 if (!strncmp(sdt_reg_tbl[i].sdt_name, sdt_reg, sdt_len)) {
165 strcpy(uprobe_reg, sdt_reg_tbl[i].uprobe_name);
166 return;
167 }
168 }
169
170 strncpy(uprobe_reg, sdt_reg, sdt_len);
171}
172
173int arch_sdt_arg_parse_op(char *old_op, char **new_op)
174{
175 char new_reg[SDT_REG_NAME_SIZE] = {0};
176 int new_len = 0, ret;
177 /*
178 * rm[0]: +/-NUM(REG)
179 * rm[1]: +/-
180 * rm[2]: NUM
181 * rm[3]: (
182 * rm[4]: REG
183 * rm[5]: )
184 */
185 regmatch_t rm[6];
186 /*
187 * Max prefix length is 2 as it may contains sign(+/-)
188 * and displacement 0 (Both sign and displacement 0 are
189 * optional so it may be empty). Use one more character
190 * to hold last NULL so that strlen can be used to find
191 * prefix length, instead of maintaing one more variable.
192 */
193 char prefix[3] = {0};
194
195 ret = sdt_init_op_regex();
196 if (ret < 0)
197 return ret;
198
199 /*
200 * If unsupported OR does not match with regex OR
201 * register name too long, skip it.
202 */
203 if (strchr(old_op, ',') || strchr(old_op, '$') ||
204 regexec(&sdt_op_regex, old_op, 6, rm, 0) ||
205 rm[4].rm_eo - rm[4].rm_so > SDT_REG_NAME_SIZE) {
206 pr_debug4("Skipping unsupported SDT argument: %s\n", old_op);
207 return SDT_ARG_SKIP;
208 }
209
210 /*
211 * Prepare prefix.
212 * If SDT OP has parenthesis but does not provide
213 * displacement, add 0 for displacement.
214 * SDT Uprobe Prefix
215 * -----------------------------
216 * +24(%rdi) +24(%di) +
217 * 24(%rdi) +24(%di) +
218 * %rdi %di
219 * (%rdi) +0(%di) +0
220 * -80(%rbx) -80(%bx) -
221 */
222 if (rm[3].rm_so != rm[3].rm_eo) {
223 if (rm[1].rm_so != rm[1].rm_eo)
224 prefix[0] = *(old_op + rm[1].rm_so);
225 else if (rm[2].rm_so != rm[2].rm_eo)
226 prefix[0] = '+';
227 else
228 strncpy(prefix, "+0", 2);
229 }
230
231 /* Rename register */
232 sdt_rename_register(old_op + rm[4].rm_so, rm[4].rm_eo - rm[4].rm_so,
233 new_reg);
234
235 /* Prepare final OP which should be valid for uprobe_events */
236 new_len = strlen(prefix) +
237 (rm[2].rm_eo - rm[2].rm_so) +
238 (rm[3].rm_eo - rm[3].rm_so) +
239 strlen(new_reg) +
240 (rm[5].rm_eo - rm[5].rm_so) +
241 1; /* NULL */
242
243 *new_op = zalloc(new_len);
244 if (!*new_op)
245 return -ENOMEM;
246
247 scnprintf(*new_op, new_len, "%.*s%.*s%.*s%.*s%.*s",
248 strlen(prefix), prefix,
249 (int)(rm[2].rm_eo - rm[2].rm_so), old_op + rm[2].rm_so,
250 (int)(rm[3].rm_eo - rm[3].rm_so), old_op + rm[3].rm_so,
251 strlen(new_reg), new_reg,
252 (int)(rm[5].rm_eo - rm[5].rm_so), old_op + rm[5].rm_so);
253
254 return SDT_ARG_VALID;
255}
diff --git a/tools/perf/arch/x86/util/unwind-libdw.c b/tools/perf/arch/x86/util/unwind-libdw.c
index c4b72176ca83..38dc9bb2a7c9 100644
--- a/tools/perf/arch/x86/util/unwind-libdw.c
+++ b/tools/perf/arch/x86/util/unwind-libdw.c
@@ -1,6 +1,7 @@
1#include <elfutils/libdwfl.h> 1#include <elfutils/libdwfl.h>
2#include "../../util/unwind-libdw.h" 2#include "../../util/unwind-libdw.h"
3#include "../../util/perf_regs.h" 3#include "../../util/perf_regs.h"
4#include "../../util/event.h"
4 5
5bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg) 6bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
6{ 7{
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
index 579a592990dd..842ab2781cdc 100644
--- a/tools/perf/bench/bench.h
+++ b/tools/perf/bench/bench.h
@@ -25,17 +25,17 @@
25# endif 25# endif
26#endif 26#endif
27 27
28int bench_numa(int argc, const char **argv, const char *prefix); 28int bench_numa(int argc, const char **argv);
29int bench_sched_messaging(int argc, const char **argv, const char *prefix); 29int bench_sched_messaging(int argc, const char **argv);
30int bench_sched_pipe(int argc, const char **argv, const char *prefix); 30int bench_sched_pipe(int argc, const char **argv);
31int bench_mem_memcpy(int argc, const char **argv, const char *prefix); 31int bench_mem_memcpy(int argc, const char **argv);
32int bench_mem_memset(int argc, const char **argv, const char *prefix); 32int bench_mem_memset(int argc, const char **argv);
33int bench_futex_hash(int argc, const char **argv, const char *prefix); 33int bench_futex_hash(int argc, const char **argv);
34int bench_futex_wake(int argc, const char **argv, const char *prefix); 34int bench_futex_wake(int argc, const char **argv);
35int bench_futex_wake_parallel(int argc, const char **argv, const char *prefix); 35int bench_futex_wake_parallel(int argc, const char **argv);
36int bench_futex_requeue(int argc, const char **argv, const char *prefix); 36int bench_futex_requeue(int argc, const char **argv);
37/* pi futexes */ 37/* pi futexes */
38int bench_futex_lock_pi(int argc, const char **argv, const char *prefix); 38int bench_futex_lock_pi(int argc, const char **argv);
39 39
40#define BENCH_FORMAT_DEFAULT_STR "default" 40#define BENCH_FORMAT_DEFAULT_STR "default"
41#define BENCH_FORMAT_DEFAULT 0 41#define BENCH_FORMAT_DEFAULT 0
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
index da04b8c5568a..fe16b310097f 100644
--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11/* For the CLR_() macros */ 11/* For the CLR_() macros */
12#include <string.h>
12#include <pthread.h> 13#include <pthread.h>
13 14
14#include <errno.h> 15#include <errno.h>
@@ -113,8 +114,7 @@ static void print_summary(void)
113 (int) runtime.tv_sec); 114 (int) runtime.tv_sec);
114} 115}
115 116
116int bench_futex_hash(int argc, const char **argv, 117int bench_futex_hash(int argc, const char **argv)
117 const char *prefix __maybe_unused)
118{ 118{
119 int ret = 0; 119 int ret = 0;
120 cpu_set_t cpu; 120 cpu_set_t cpu;
diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c
index 91877777ec6e..73a1c44ea63c 100644
--- a/tools/perf/bench/futex-lock-pi.c
+++ b/tools/perf/bench/futex-lock-pi.c
@@ -3,6 +3,7 @@
3 */ 3 */
4 4
5/* For the CLR_() macros */ 5/* For the CLR_() macros */
6#include <string.h>
6#include <pthread.h> 7#include <pthread.h>
7 8
8#include <signal.h> 9#include <signal.h>
@@ -139,8 +140,7 @@ static void create_threads(struct worker *w, pthread_attr_t thread_attr)
139 } 140 }
140} 141}
141 142
142int bench_futex_lock_pi(int argc, const char **argv, 143int bench_futex_lock_pi(int argc, const char **argv)
143 const char *prefix __maybe_unused)
144{ 144{
145 int ret = 0; 145 int ret = 0;
146 unsigned int i; 146 unsigned int i;
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c
index 2b9705a8734c..41786cbea24c 100644
--- a/tools/perf/bench/futex-requeue.c
+++ b/tools/perf/bench/futex-requeue.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11/* For the CLR_() macros */ 11/* For the CLR_() macros */
12#include <string.h>
12#include <pthread.h> 13#include <pthread.h>
13 14
14#include <signal.h> 15#include <signal.h>
@@ -108,8 +109,7 @@ static void toggle_done(int sig __maybe_unused,
108 done = true; 109 done = true;
109} 110}
110 111
111int bench_futex_requeue(int argc, const char **argv, 112int bench_futex_requeue(int argc, const char **argv)
112 const char *prefix __maybe_unused)
113{ 113{
114 int ret = 0; 114 int ret = 0;
115 unsigned int i, j; 115 unsigned int i, j;
diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c
index 2c8fa67ad537..4ab12c8e016a 100644
--- a/tools/perf/bench/futex-wake-parallel.c
+++ b/tools/perf/bench/futex-wake-parallel.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10/* For the CLR_() macros */ 10/* For the CLR_() macros */
11#include <string.h>
11#include <pthread.h> 12#include <pthread.h>
12 13
13#include <signal.h> 14#include <signal.h>
@@ -196,8 +197,7 @@ static void toggle_done(int sig __maybe_unused,
196 done = true; 197 done = true;
197} 198}
198 199
199int bench_futex_wake_parallel(int argc, const char **argv, 200int bench_futex_wake_parallel(int argc, const char **argv)
200 const char *prefix __maybe_unused)
201{ 201{
202 int ret = 0; 202 int ret = 0;
203 unsigned int i, j; 203 unsigned int i, j;
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c
index e246b1b8388a..2fa49222ef8d 100644
--- a/tools/perf/bench/futex-wake.c
+++ b/tools/perf/bench/futex-wake.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11/* For the CLR_() macros */ 11/* For the CLR_() macros */
12#include <string.h>
12#include <pthread.h> 13#include <pthread.h>
13 14
14#include <signal.h> 15#include <signal.h>
@@ -114,8 +115,7 @@ static void toggle_done(int sig __maybe_unused,
114 done = true; 115 done = true;
115} 116}
116 117
117int bench_futex_wake(int argc, const char **argv, 118int bench_futex_wake(int argc, const char **argv)
118 const char *prefix __maybe_unused)
119{ 119{
120 int ret = 0; 120 int ret = 0;
121 unsigned int i, j; 121 unsigned int i, j;
diff --git a/tools/perf/bench/futex.h b/tools/perf/bench/futex.h
index b2e06d1190d0..e44fd3239530 100644
--- a/tools/perf/bench/futex.h
+++ b/tools/perf/bench/futex.h
@@ -88,13 +88,11 @@ futex_cmp_requeue(u_int32_t *uaddr, u_int32_t val, u_int32_t *uaddr2, int nr_wak
88 88
89#ifndef HAVE_PTHREAD_ATTR_SETAFFINITY_NP 89#ifndef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
90#include <pthread.h> 90#include <pthread.h>
91static inline int pthread_attr_setaffinity_np(pthread_attr_t *attr, 91#include <linux/compiler.h>
92 size_t cpusetsize, 92static inline int pthread_attr_setaffinity_np(pthread_attr_t *attr __maybe_unused,
93 cpu_set_t *cpuset) 93 size_t cpusetsize __maybe_unused,
94 cpu_set_t *cpuset __maybe_unused)
94{ 95{
95 attr = attr;
96 cpusetsize = cpusetsize;
97 cpuset = cpuset;
98 return 0; 96 return 0;
99} 97}
100#endif 98#endif
diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c
index 52504a83b5a1..fbd732b54047 100644
--- a/tools/perf/bench/mem-functions.c
+++ b/tools/perf/bench/mem-functions.c
@@ -12,6 +12,7 @@
12#include <subcmd/parse-options.h> 12#include <subcmd/parse-options.h>
13#include "../util/header.h" 13#include "../util/header.h"
14#include "../util/cloexec.h" 14#include "../util/cloexec.h"
15#include "../util/string2.h"
15#include "bench.h" 16#include "bench.h"
16#include "mem-memcpy-arch.h" 17#include "mem-memcpy-arch.h"
17#include "mem-memset-arch.h" 18#include "mem-memset-arch.h"
@@ -284,7 +285,7 @@ static const char * const bench_mem_memcpy_usage[] = {
284 NULL 285 NULL
285}; 286};
286 287
287int bench_mem_memcpy(int argc, const char **argv, const char *prefix __maybe_unused) 288int bench_mem_memcpy(int argc, const char **argv)
288{ 289{
289 struct bench_mem_info info = { 290 struct bench_mem_info info = {
290 .functions = memcpy_functions, 291 .functions = memcpy_functions,
@@ -358,7 +359,7 @@ static const struct function memset_functions[] = {
358 { .name = NULL, } 359 { .name = NULL, }
359}; 360};
360 361
361int bench_mem_memset(int argc, const char **argv, const char *prefix __maybe_unused) 362int bench_mem_memset(int argc, const char **argv)
362{ 363{
363 struct bench_mem_info info = { 364 struct bench_mem_info info = {
364 .functions = memset_functions, 365 .functions = memset_functions,
diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c
index 3083fc36282b..27de0c8c5c19 100644
--- a/tools/perf/bench/numa.c
+++ b/tools/perf/bench/numa.c
@@ -4,6 +4,7 @@
4 * numa: Simulate NUMA-sensitive workload and measure their NUMA performance 4 * numa: Simulate NUMA-sensitive workload and measure their NUMA performance
5 */ 5 */
6 6
7#include <inttypes.h>
7/* For the CLR_() macros */ 8/* For the CLR_() macros */
8#include <pthread.h> 9#include <pthread.h>
9 10
@@ -30,6 +31,7 @@
30#include <sys/wait.h> 31#include <sys/wait.h>
31#include <sys/prctl.h> 32#include <sys/prctl.h>
32#include <sys/types.h> 33#include <sys/types.h>
34#include <linux/kernel.h>
33#include <linux/time64.h> 35#include <linux/time64.h>
34 36
35#include <numa.h> 37#include <numa.h>
@@ -187,7 +189,8 @@ static const struct option options[] = {
187 OPT_INCR ('d', "show_details" , &p0.show_details, "Show details"), 189 OPT_INCR ('d', "show_details" , &p0.show_details, "Show details"),
188 OPT_INCR ('a', "all" , &p0.run_all, "Run all tests in the suite"), 190 OPT_INCR ('a', "all" , &p0.run_all, "Run all tests in the suite"),
189 OPT_INTEGER('H', "thp" , &p0.thp, "MADV_NOHUGEPAGE < 0 < MADV_HUGEPAGE"), 191 OPT_INTEGER('H', "thp" , &p0.thp, "MADV_NOHUGEPAGE < 0 < MADV_HUGEPAGE"),
190 OPT_BOOLEAN('c', "show_convergence", &p0.show_convergence, "show convergence details"), 192 OPT_BOOLEAN('c', "show_convergence", &p0.show_convergence, "show convergence details, "
193 "convergence is reached when each process (all its threads) is running on a single NUMA node."),
191 OPT_BOOLEAN('m', "measure_convergence", &p0.measure_convergence, "measure convergence latency"), 194 OPT_BOOLEAN('m', "measure_convergence", &p0.measure_convergence, "measure convergence latency"),
192 OPT_BOOLEAN('q', "quiet" , &p0.show_quiet, "quiet mode"), 195 OPT_BOOLEAN('q', "quiet" , &p0.show_quiet, "quiet mode"),
193 OPT_BOOLEAN('S', "serialize-startup", &p0.serialize_startup,"serialize thread startup"), 196 OPT_BOOLEAN('S', "serialize-startup", &p0.serialize_startup,"serialize thread startup"),
@@ -1766,7 +1769,7 @@ static int bench_all(void)
1766 return 0; 1769 return 0;
1767} 1770}
1768 1771
1769int bench_numa(int argc, const char **argv, const char *prefix __maybe_unused) 1772int bench_numa(int argc, const char **argv)
1770{ 1773{
1771 init_params(&p0, "main,", argc, argv); 1774 init_params(&p0, "main,", argc, argv);
1772 argc = parse_options(argc, argv, options, bench_numa_usage, 0); 1775 argc = parse_options(argc, argv, options, bench_numa_usage, 0);
diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c
index 6a111e775210..4f961e74535b 100644
--- a/tools/perf/bench/sched-messaging.c
+++ b/tools/perf/bench/sched-messaging.c
@@ -260,8 +260,7 @@ static const char * const bench_sched_message_usage[] = {
260 NULL 260 NULL
261}; 261};
262 262
263int bench_sched_messaging(int argc, const char **argv, 263int bench_sched_messaging(int argc, const char **argv)
264 const char *prefix __maybe_unused)
265{ 264{
266 unsigned int i, total_children; 265 unsigned int i, total_children;
267 struct timeval start, stop, diff; 266 struct timeval start, stop, diff;
diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
index 2243f0150d76..a152737370c5 100644
--- a/tools/perf/bench/sched-pipe.c
+++ b/tools/perf/bench/sched-pipe.c
@@ -76,7 +76,7 @@ static void *worker_thread(void *__tdata)
76 return NULL; 76 return NULL;
77} 77}
78 78
79int bench_sched_pipe(int argc, const char **argv, const char *prefix __maybe_unused) 79int bench_sched_pipe(int argc, const char **argv)
80{ 80{
81 struct thread_data threads[2], *td; 81 struct thread_data threads[2], *td;
82 int pipe_1[2], pipe_2[2]; 82 int pipe_1[2], pipe_2[2];
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 4f52d85f5ebc..7a5dc7e5c577 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -33,6 +33,7 @@
33#include "util/block-range.h" 33#include "util/block-range.h"
34 34
35#include <dlfcn.h> 35#include <dlfcn.h>
36#include <errno.h>
36#include <linux/bitmap.h> 37#include <linux/bitmap.h>
37 38
38struct perf_annotate { 39struct perf_annotate {
@@ -383,7 +384,7 @@ static const char * const annotate_usage[] = {
383 NULL 384 NULL
384}; 385};
385 386
386int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) 387int cmd_annotate(int argc, const char **argv)
387{ 388{
388 struct perf_annotate annotate = { 389 struct perf_annotate annotate = {
389 .tool = { 390 .tool = {
@@ -393,6 +394,9 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
393 .comm = perf_event__process_comm, 394 .comm = perf_event__process_comm,
394 .exit = perf_event__process_exit, 395 .exit = perf_event__process_exit,
395 .fork = perf_event__process_fork, 396 .fork = perf_event__process_fork,
397 .namespaces = perf_event__process_namespaces,
398 .attr = perf_event__process_attr,
399 .build_id = perf_event__process_build_id,
396 .ordered_events = true, 400 .ordered_events = true,
397 .ordering_requires_timestamps = true, 401 .ordering_requires_timestamps = true,
398 }, 402 },
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index a1cddc6bbf0f..445e62881254 100644
--- a/tools/perf/builtin-bench.c
+++ b/tools/perf/builtin-bench.c
@@ -25,7 +25,7 @@
25#include <string.h> 25#include <string.h>
26#include <sys/prctl.h> 26#include <sys/prctl.h>
27 27
28typedef int (*bench_fn_t)(int argc, const char **argv, const char *prefix); 28typedef int (*bench_fn_t)(int argc, const char **argv);
29 29
30struct bench { 30struct bench {
31 const char *name; 31 const char *name;
@@ -155,7 +155,7 @@ static int bench_str2int(const char *str)
155 * to something meaningful: 155 * to something meaningful:
156 */ 156 */
157static int run_bench(const char *coll_name, const char *bench_name, bench_fn_t fn, 157static int run_bench(const char *coll_name, const char *bench_name, bench_fn_t fn,
158 int argc, const char **argv, const char *prefix) 158 int argc, const char **argv)
159{ 159{
160 int size; 160 int size;
161 char *name; 161 char *name;
@@ -171,7 +171,7 @@ static int run_bench(const char *coll_name, const char *bench_name, bench_fn_t f
171 prctl(PR_SET_NAME, name); 171 prctl(PR_SET_NAME, name);
172 argv[0] = name; 172 argv[0] = name;
173 173
174 ret = fn(argc, argv, prefix); 174 ret = fn(argc, argv);
175 175
176 free(name); 176 free(name);
177 177
@@ -198,7 +198,7 @@ static void run_collection(struct collection *coll)
198 fflush(stdout); 198 fflush(stdout);
199 199
200 argv[1] = bench->name; 200 argv[1] = bench->name;
201 run_bench(coll->name, bench->name, bench->fn, 1, argv, NULL); 201 run_bench(coll->name, bench->name, bench->fn, 1, argv);
202 printf("\n"); 202 printf("\n");
203 } 203 }
204} 204}
@@ -211,7 +211,7 @@ static void run_all_collections(void)
211 run_collection(coll); 211 run_collection(coll);
212} 212}
213 213
214int cmd_bench(int argc, const char **argv, const char *prefix __maybe_unused) 214int cmd_bench(int argc, const char **argv)
215{ 215{
216 struct collection *coll; 216 struct collection *coll;
217 int ret = 0; 217 int ret = 0;
@@ -270,7 +270,7 @@ int cmd_bench(int argc, const char **argv, const char *prefix __maybe_unused)
270 if (bench_format == BENCH_FORMAT_DEFAULT) 270 if (bench_format == BENCH_FORMAT_DEFAULT)
271 printf("# Running '%s/%s' benchmark:\n", coll->name, bench->name); 271 printf("# Running '%s/%s' benchmark:\n", coll->name, bench->name);
272 fflush(stdout); 272 fflush(stdout);
273 ret = run_bench(coll->name, bench->name, bench->fn, argc-1, argv+1, prefix); 273 ret = run_bench(coll->name, bench->name, bench->fn, argc-1, argv+1);
274 goto end; 274 goto end;
275 } 275 }
276 276
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index 30e2b2cb2421..64b44e81c771 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -10,6 +10,7 @@
10#include <sys/time.h> 10#include <sys/time.h>
11#include <time.h> 11#include <time.h>
12#include <dirent.h> 12#include <dirent.h>
13#include <errno.h>
13#include <unistd.h> 14#include <unistd.h>
14#include "builtin.h" 15#include "builtin.h"
15#include "perf.h" 16#include "perf.h"
@@ -21,6 +22,7 @@
21#include "util/build-id.h" 22#include "util/build-id.h"
22#include "util/session.h" 23#include "util/session.h"
23#include "util/symbol.h" 24#include "util/symbol.h"
25#include "util/time-utils.h"
24 26
25static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) 27static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
26{ 28{
@@ -276,8 +278,7 @@ static int build_id_cache__update_file(const char *filename)
276 return err; 278 return err;
277} 279}
278 280
279int cmd_buildid_cache(int argc, const char **argv, 281int cmd_buildid_cache(int argc, const char **argv)
280 const char *prefix __maybe_unused)
281{ 282{
282 struct strlist *list; 283 struct strlist *list;
283 struct str_node *pos; 284 struct str_node *pos;
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index 5e914ee79eb3..fdaca16e0c74 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -16,6 +16,7 @@
16#include "util/session.h" 16#include "util/session.h"
17#include "util/symbol.h" 17#include "util/symbol.h"
18#include "util/data.h" 18#include "util/data.h"
19#include <errno.h>
19 20
20static int sysfs__fprintf_build_id(FILE *fp) 21static int sysfs__fprintf_build_id(FILE *fp)
21{ 22{
@@ -87,8 +88,7 @@ out:
87 return 0; 88 return 0;
88} 89}
89 90
90int cmd_buildid_list(int argc, const char **argv, 91int cmd_buildid_list(int argc, const char **argv)
91 const char *prefix __maybe_unused)
92{ 92{
93 bool show_kernel = false; 93 bool show_kernel = false;
94 bool with_hits = false; 94 bool with_hits = false;
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index e2b21723bbf8..e33b4acece90 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -9,10 +9,13 @@
9 * Dick Fowles <fowles@inreach.com> 9 * Dick Fowles <fowles@inreach.com>
10 * Joe Mario <jmario@redhat.com> 10 * Joe Mario <jmario@redhat.com>
11 */ 11 */
12#include <errno.h>
13#include <inttypes.h>
12#include <linux/compiler.h> 14#include <linux/compiler.h>
13#include <linux/kernel.h> 15#include <linux/kernel.h>
14#include <linux/stringify.h> 16#include <linux/stringify.h>
15#include <asm/bug.h> 17#include <asm/bug.h>
18#include <sys/param.h>
16#include "util.h" 19#include "util.h"
17#include "debug.h" 20#include "debug.h"
18#include "builtin.h" 21#include "builtin.h"
@@ -29,6 +32,7 @@
29#include <asm/bug.h> 32#include <asm/bug.h>
30#include "ui/browsers/hists.h" 33#include "ui/browsers/hists.h"
31#include "evlist.h" 34#include "evlist.h"
35#include "thread.h"
32 36
33struct c2c_hists { 37struct c2c_hists {
34 struct hists hists; 38 struct hists hists;
@@ -2334,7 +2338,7 @@ out:
2334 2338
2335static void perf_c2c_display(struct perf_session *session) 2339static void perf_c2c_display(struct perf_session *session)
2336{ 2340{
2337 if (c2c.use_stdio) 2341 if (use_browser == 0)
2338 perf_c2c__hists_fprintf(stdout, session); 2342 perf_c2c__hists_fprintf(stdout, session);
2339 else 2343 else
2340 perf_c2c__hists_browse(&c2c.hists.hists); 2344 perf_c2c__hists_browse(&c2c.hists.hists);
@@ -2536,7 +2540,7 @@ static int perf_c2c__report(int argc, const char **argv)
2536 OPT_BOOLEAN(0, "stdio", &c2c.use_stdio, "Use the stdio interface"), 2540 OPT_BOOLEAN(0, "stdio", &c2c.use_stdio, "Use the stdio interface"),
2537#endif 2541#endif
2538 OPT_BOOLEAN(0, "stats", &c2c.stats_only, 2542 OPT_BOOLEAN(0, "stats", &c2c.stats_only,
2539 "Use the stdio interface"), 2543 "Display only statistic tables (implies --stdio)"),
2540 OPT_BOOLEAN(0, "full-symbols", &c2c.symbol_full, 2544 OPT_BOOLEAN(0, "full-symbols", &c2c.symbol_full,
2541 "Display full length of symbols"), 2545 "Display full length of symbols"),
2542 OPT_BOOLEAN(0, "no-source", &no_source, 2546 OPT_BOOLEAN(0, "no-source", &no_source,
@@ -2755,12 +2759,12 @@ static int perf_c2c__record(int argc, const char **argv)
2755 pr_debug("\n"); 2759 pr_debug("\n");
2756 } 2760 }
2757 2761
2758 ret = cmd_record(i, rec_argv, NULL); 2762 ret = cmd_record(i, rec_argv);
2759 free(rec_argv); 2763 free(rec_argv);
2760 return ret; 2764 return ret;
2761} 2765}
2762 2766
2763int cmd_c2c(int argc, const char **argv, const char *prefix __maybe_unused) 2767int cmd_c2c(int argc, const char **argv)
2764{ 2768{
2765 argc = parse_options(argc, argv, c2c_options, c2c_usage, 2769 argc = parse_options(argc, argv, c2c_options, c2c_usage,
2766 PARSE_OPT_STOP_AT_NON_OPTION); 2770 PARSE_OPT_STOP_AT_NON_OPTION);
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index 8c0d93b7c2f0..55f04f85b049 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -154,7 +154,7 @@ static int parse_config_arg(char *arg, char **var, char **value)
154 return 0; 154 return 0;
155} 155}
156 156
157int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused) 157int cmd_config(int argc, const char **argv)
158{ 158{
159 int i, ret = 0; 159 int i, ret = 0;
160 struct perf_config_set *set; 160 struct perf_config_set *set;
diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index 7ad6e17ac6b3..0adb5f82335a 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -6,7 +6,7 @@
6#include "data-convert.h" 6#include "data-convert.h"
7#include "data-convert-bt.h" 7#include "data-convert-bt.h"
8 8
9typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix); 9typedef int (*data_cmd_fn_t)(int argc, const char **argv);
10 10
11struct data_cmd { 11struct data_cmd {
12 const char *name; 12 const char *name;
@@ -50,8 +50,7 @@ static const char * const data_convert_usage[] = {
50 NULL 50 NULL
51}; 51};
52 52
53static int cmd_data_convert(int argc, const char **argv, 53static int cmd_data_convert(int argc, const char **argv)
54 const char *prefix __maybe_unused)
55{ 54{
56 const char *to_ctf = NULL; 55 const char *to_ctf = NULL;
57 struct perf_data_convert_opts opts = { 56 struct perf_data_convert_opts opts = {
@@ -98,7 +97,7 @@ static struct data_cmd data_cmds[] = {
98 { .name = NULL, }, 97 { .name = NULL, },
99}; 98};
100 99
101int cmd_data(int argc, const char **argv, const char *prefix) 100int cmd_data(int argc, const char **argv)
102{ 101{
103 struct data_cmd *cmd; 102 struct data_cmd *cmd;
104 const char *cmdstr; 103 const char *cmdstr;
@@ -118,7 +117,7 @@ int cmd_data(int argc, const char **argv, const char *prefix)
118 if (strcmp(cmd->name, cmdstr)) 117 if (strcmp(cmd->name, cmdstr))
119 continue; 118 continue;
120 119
121 return cmd->fn(argc, argv, prefix); 120 return cmd->fn(argc, argv);
122 } 121 }
123 122
124 pr_err("Unknown command: %s\n", cmdstr); 123 pr_err("Unknown command: %s\n", cmdstr);
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 1b96a3122228..eec5df80f5a3 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -19,6 +19,8 @@
19#include "util/data.h" 19#include "util/data.h"
20#include "util/config.h" 20#include "util/config.h"
21 21
22#include <errno.h>
23#include <inttypes.h>
22#include <stdlib.h> 24#include <stdlib.h>
23#include <math.h> 25#include <math.h>
24 26
@@ -364,6 +366,7 @@ static struct perf_tool tool = {
364 .exit = perf_event__process_exit, 366 .exit = perf_event__process_exit,
365 .fork = perf_event__process_fork, 367 .fork = perf_event__process_fork,
366 .lost = perf_event__process_lost, 368 .lost = perf_event__process_lost,
369 .namespaces = perf_event__process_namespaces,
367 .ordered_events = true, 370 .ordered_events = true,
368 .ordering_requires_timestamps = true, 371 .ordering_requires_timestamps = true,
369}; 372};
@@ -1320,7 +1323,7 @@ static int diff__config(const char *var, const char *value,
1320 return 0; 1323 return 0;
1321} 1324}
1322 1325
1323int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused) 1326int cmd_diff(int argc, const char **argv)
1324{ 1327{
1325 int ret = hists__init(); 1328 int ret = hists__init();
1326 1329
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index e09c4287fe87..6d210e40d611 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -46,7 +46,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details
46 return 0; 46 return 0;
47} 47}
48 48
49int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused) 49int cmd_evlist(int argc, const char **argv)
50{ 50{
51 struct perf_attr_details details = { .verbose = false, }; 51 struct perf_attr_details details = { .verbose = false, };
52 const struct option options[] = { 52 const struct option options[] = {
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index c3e643666c72..9e0b35cd0eea 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -9,13 +9,18 @@
9#include "builtin.h" 9#include "builtin.h"
10#include "perf.h" 10#include "perf.h"
11 11
12#include <errno.h>
12#include <unistd.h> 13#include <unistd.h>
13#include <signal.h> 14#include <signal.h>
15#include <fcntl.h>
16#include <poll.h>
14 17
15#include "debug.h" 18#include "debug.h"
16#include <subcmd/parse-options.h> 19#include <subcmd/parse-options.h>
20#include <api/fs/tracing_path.h>
17#include "evlist.h" 21#include "evlist.h"
18#include "target.h" 22#include "target.h"
23#include "cpumap.h"
19#include "thread_map.h" 24#include "thread_map.h"
20#include "util/config.h" 25#include "util/config.h"
21 26
@@ -50,11 +55,12 @@ static void ftrace__workload_exec_failed_signal(int signo __maybe_unused,
50 done = true; 55 done = true;
51} 56}
52 57
53static int write_tracing_file(const char *name, const char *val) 58static int __write_tracing_file(const char *name, const char *val, bool append)
54{ 59{
55 char *file; 60 char *file;
56 int fd, ret = -1; 61 int fd, ret = -1;
57 ssize_t size = strlen(val); 62 ssize_t size = strlen(val);
63 int flags = O_WRONLY;
58 64
59 file = get_tracing_file(name); 65 file = get_tracing_file(name);
60 if (!file) { 66 if (!file) {
@@ -62,7 +68,12 @@ static int write_tracing_file(const char *name, const char *val)
62 return -1; 68 return -1;
63 } 69 }
64 70
65 fd = open(file, O_WRONLY); 71 if (append)
72 flags |= O_APPEND;
73 else
74 flags |= O_TRUNC;
75
76 fd = open(file, flags);
66 if (fd < 0) { 77 if (fd < 0) {
67 pr_debug("cannot open tracing file: %s\n", name); 78 pr_debug("cannot open tracing file: %s\n", name);
68 goto out; 79 goto out;
@@ -79,6 +90,18 @@ out:
79 return ret; 90 return ret;
80} 91}
81 92
93static int write_tracing_file(const char *name, const char *val)
94{
95 return __write_tracing_file(name, val, false);
96}
97
98static int append_tracing_file(const char *name, const char *val)
99{
100 return __write_tracing_file(name, val, true);
101}
102
103static int reset_tracing_cpu(void);
104
82static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused) 105static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
83{ 106{
84 if (write_tracing_file("tracing_on", "0") < 0) 107 if (write_tracing_file("tracing_on", "0") < 0)
@@ -90,14 +113,78 @@ static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
90 if (write_tracing_file("set_ftrace_pid", " ") < 0) 113 if (write_tracing_file("set_ftrace_pid", " ") < 0)
91 return -1; 114 return -1;
92 115
116 if (reset_tracing_cpu() < 0)
117 return -1;
118
119 return 0;
120}
121
122static int set_tracing_pid(struct perf_ftrace *ftrace)
123{
124 int i;
125 char buf[16];
126
127 if (target__has_cpu(&ftrace->target))
128 return 0;
129
130 for (i = 0; i < thread_map__nr(ftrace->evlist->threads); i++) {
131 scnprintf(buf, sizeof(buf), "%d",
132 ftrace->evlist->threads->map[i]);
133 if (append_tracing_file("set_ftrace_pid", buf) < 0)
134 return -1;
135 }
93 return 0; 136 return 0;
94} 137}
95 138
139static int set_tracing_cpumask(struct cpu_map *cpumap)
140{
141 char *cpumask;
142 size_t mask_size;
143 int ret;
144 int last_cpu;
145
146 last_cpu = cpu_map__cpu(cpumap, cpumap->nr - 1);
147 mask_size = (last_cpu + 3) / 4 + 1;
148 mask_size += last_cpu / 32; /* ',' is needed for every 32th cpus */
149
150 cpumask = malloc(mask_size);
151 if (cpumask == NULL) {
152 pr_debug("failed to allocate cpu mask\n");
153 return -1;
154 }
155
156 cpu_map__snprint_mask(cpumap, cpumask, mask_size);
157
158 ret = write_tracing_file("tracing_cpumask", cpumask);
159
160 free(cpumask);
161 return ret;
162}
163
164static int set_tracing_cpu(struct perf_ftrace *ftrace)
165{
166 struct cpu_map *cpumap = ftrace->evlist->cpus;
167
168 if (!target__has_cpu(&ftrace->target))
169 return 0;
170
171 return set_tracing_cpumask(cpumap);
172}
173
174static int reset_tracing_cpu(void)
175{
176 struct cpu_map *cpumap = cpu_map__new(NULL);
177 int ret;
178
179 ret = set_tracing_cpumask(cpumap);
180 cpu_map__put(cpumap);
181 return ret;
182}
183
96static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) 184static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
97{ 185{
98 char *trace_file; 186 char *trace_file;
99 int trace_fd; 187 int trace_fd;
100 char *trace_pid;
101 char buf[4096]; 188 char buf[4096];
102 struct pollfd pollfd = { 189 struct pollfd pollfd = {
103 .events = POLLIN, 190 .events = POLLIN,
@@ -108,42 +195,43 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
108 return -1; 195 return -1;
109 } 196 }
110 197
111 if (argc < 1)
112 return -1;
113
114 signal(SIGINT, sig_handler); 198 signal(SIGINT, sig_handler);
115 signal(SIGUSR1, sig_handler); 199 signal(SIGUSR1, sig_handler);
116 signal(SIGCHLD, sig_handler); 200 signal(SIGCHLD, sig_handler);
201 signal(SIGPIPE, sig_handler);
117 202
118 reset_tracing_files(ftrace); 203 if (reset_tracing_files(ftrace) < 0)
204 goto out;
119 205
120 /* reset ftrace buffer */ 206 /* reset ftrace buffer */
121 if (write_tracing_file("trace", "0") < 0) 207 if (write_tracing_file("trace", "0") < 0)
122 goto out; 208 goto out;
123 209
124 if (perf_evlist__prepare_workload(ftrace->evlist, &ftrace->target, 210 if (argc && perf_evlist__prepare_workload(ftrace->evlist,
125 argv, false, ftrace__workload_exec_failed_signal) < 0) 211 &ftrace->target, argv, false,
212 ftrace__workload_exec_failed_signal) < 0) {
126 goto out; 213 goto out;
214 }
127 215
128 if (write_tracing_file("current_tracer", ftrace->tracer) < 0) { 216 if (set_tracing_pid(ftrace) < 0) {
129 pr_err("failed to set current_tracer to %s\n", ftrace->tracer); 217 pr_err("failed to set ftrace pid\n");
130 goto out; 218 goto out_reset;
131 } 219 }
132 220
133 if (asprintf(&trace_pid, "%d", thread_map__pid(ftrace->evlist->threads, 0)) < 0) { 221 if (set_tracing_cpu(ftrace) < 0) {
134 pr_err("failed to allocate pid string\n"); 222 pr_err("failed to set tracing cpumask\n");
135 goto out; 223 goto out_reset;
136 } 224 }
137 225
138 if (write_tracing_file("set_ftrace_pid", trace_pid) < 0) { 226 if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
139 pr_err("failed to set pid: %s\n", trace_pid); 227 pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
140 goto out_free_pid; 228 goto out_reset;
141 } 229 }
142 230
143 trace_file = get_tracing_file("trace_pipe"); 231 trace_file = get_tracing_file("trace_pipe");
144 if (!trace_file) { 232 if (!trace_file) {
145 pr_err("failed to open trace_pipe\n"); 233 pr_err("failed to open trace_pipe\n");
146 goto out_free_pid; 234 goto out_reset;
147 } 235 }
148 236
149 trace_fd = open(trace_file, O_RDONLY); 237 trace_fd = open(trace_file, O_RDONLY);
@@ -152,7 +240,7 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
152 240
153 if (trace_fd < 0) { 241 if (trace_fd < 0) {
154 pr_err("failed to open trace_pipe\n"); 242 pr_err("failed to open trace_pipe\n");
155 goto out_free_pid; 243 goto out_reset;
156 } 244 }
157 245
158 fcntl(trace_fd, F_SETFL, O_NONBLOCK); 246 fcntl(trace_fd, F_SETFL, O_NONBLOCK);
@@ -163,6 +251,8 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
163 goto out_close_fd; 251 goto out_close_fd;
164 } 252 }
165 253
254 setup_pager();
255
166 perf_evlist__start_workload(ftrace->evlist); 256 perf_evlist__start_workload(ftrace->evlist);
167 257
168 while (!done) { 258 while (!done) {
@@ -191,11 +281,9 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
191 281
192out_close_fd: 282out_close_fd:
193 close(trace_fd); 283 close(trace_fd);
194out_free_pid: 284out_reset:
195 free(trace_pid);
196out:
197 reset_tracing_files(ftrace); 285 reset_tracing_files(ftrace);
198 286out:
199 return done ? 0 : -1; 287 return done ? 0 : -1;
200} 288}
201 289
@@ -219,7 +307,7 @@ static int perf_ftrace_config(const char *var, const char *value, void *cb)
219 return -1; 307 return -1;
220} 308}
221 309
222int cmd_ftrace(int argc, const char **argv, const char *prefix __maybe_unused) 310int cmd_ftrace(int argc, const char **argv)
223{ 311{
224 int ret; 312 int ret;
225 struct perf_ftrace ftrace = { 313 struct perf_ftrace ftrace = {
@@ -227,15 +315,21 @@ int cmd_ftrace(int argc, const char **argv, const char *prefix __maybe_unused)
227 .target = { .uid = UINT_MAX, }, 315 .target = { .uid = UINT_MAX, },
228 }; 316 };
229 const char * const ftrace_usage[] = { 317 const char * const ftrace_usage[] = {
230 "perf ftrace [<options>] <command>", 318 "perf ftrace [<options>] [<command>]",
231 "perf ftrace [<options>] -- <command> [<options>]", 319 "perf ftrace [<options>] -- <command> [<options>]",
232 NULL 320 NULL
233 }; 321 };
234 const struct option ftrace_options[] = { 322 const struct option ftrace_options[] = {
235 OPT_STRING('t', "tracer", &ftrace.tracer, "tracer", 323 OPT_STRING('t', "tracer", &ftrace.tracer, "tracer",
236 "tracer to use: function_graph(default) or function"), 324 "tracer to use: function_graph(default) or function"),
325 OPT_STRING('p', "pid", &ftrace.target.pid, "pid",
326 "trace on existing process id"),
237 OPT_INCR('v', "verbose", &verbose, 327 OPT_INCR('v', "verbose", &verbose,
238 "be more verbose"), 328 "be more verbose"),
329 OPT_BOOLEAN('a', "all-cpus", &ftrace.target.system_wide,
330 "system-wide collection from all CPUs"),
331 OPT_STRING('C', "cpu", &ftrace.target.cpu_list, "cpu",
332 "list of cpus to monitor"),
239 OPT_END() 333 OPT_END()
240 }; 334 };
241 335
@@ -245,9 +339,18 @@ int cmd_ftrace(int argc, const char **argv, const char *prefix __maybe_unused)
245 339
246 argc = parse_options(argc, argv, ftrace_options, ftrace_usage, 340 argc = parse_options(argc, argv, ftrace_options, ftrace_usage,
247 PARSE_OPT_STOP_AT_NON_OPTION); 341 PARSE_OPT_STOP_AT_NON_OPTION);
248 if (!argc) 342 if (!argc && target__none(&ftrace.target))
249 usage_with_options(ftrace_usage, ftrace_options); 343 usage_with_options(ftrace_usage, ftrace_options);
250 344
345 ret = target__validate(&ftrace.target);
346 if (ret) {
347 char errbuf[512];
348
349 target__strerror(&ftrace.target, ret, errbuf, 512);
350 pr_err("%s\n", errbuf);
351 return -EINVAL;
352 }
353
251 ftrace.evlist = perf_evlist__new(); 354 ftrace.evlist = perf_evlist__new();
252 if (ftrace.evlist == NULL) 355 if (ftrace.evlist == NULL)
253 return -ENOMEM; 356 return -ENOMEM;
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index aed0d844e8c2..492f8e14ab09 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -12,16 +12,22 @@
12#include <subcmd/run-command.h> 12#include <subcmd/run-command.h>
13#include <subcmd/help.h> 13#include <subcmd/help.h>
14#include "util/debug.h" 14#include "util/debug.h"
15#include <linux/kernel.h>
16#include <errno.h>
17#include <stdio.h>
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <unistd.h>
15 21
16static struct man_viewer_list { 22static struct man_viewer_list {
17 struct man_viewer_list *next; 23 struct man_viewer_list *next;
18 char name[FLEX_ARRAY]; 24 char name[0];
19} *man_viewer_list; 25} *man_viewer_list;
20 26
21static struct man_viewer_info_list { 27static struct man_viewer_info_list {
22 struct man_viewer_info_list *next; 28 struct man_viewer_info_list *next;
23 const char *info; 29 const char *info;
24 char name[FLEX_ARRAY]; 30 char name[0];
25} *man_viewer_info_list; 31} *man_viewer_info_list;
26 32
27enum help_format { 33enum help_format {
@@ -301,12 +307,6 @@ void list_common_cmds_help(void)
301 } 307 }
302} 308}
303 309
304static int is_perf_command(const char *s)
305{
306 return is_in_cmdlist(&main_cmds, s) ||
307 is_in_cmdlist(&other_cmds, s);
308}
309
310static const char *cmd_to_page(const char *perf_cmd) 310static const char *cmd_to_page(const char *perf_cmd)
311{ 311{
312 char *s; 312 char *s;
@@ -418,7 +418,7 @@ static int show_html_page(const char *perf_cmd)
418 return 0; 418 return 0;
419} 419}
420 420
421int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused) 421int cmd_help(int argc, const char **argv)
422{ 422{
423 bool show_all = false; 423 bool show_all = false;
424 enum help_format help_format = HELP_FORMAT_MAN; 424 enum help_format help_format = HELP_FORMAT_MAN;
@@ -446,7 +446,6 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
446 "perf help [--all] [--man|--web|--info] [command]", 446 "perf help [--all] [--man|--web|--info] [command]",
447 NULL 447 NULL
448 }; 448 };
449 const char *alias;
450 int rc; 449 int rc;
451 450
452 load_command_list("perf-", &main_cmds, &other_cmds); 451 load_command_list("perf-", &main_cmds, &other_cmds);
@@ -472,12 +471,6 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
472 return 0; 471 return 0;
473 } 472 }
474 473
475 alias = alias_lookup(argv[0]);
476 if (alias && !is_perf_command(argv[0])) {
477 printf("`perf %s' is aliased to `%s'\n", argv[0], alias);
478 return 0;
479 }
480
481 switch (help_format) { 474 switch (help_format) {
482 case HELP_FORMAT_MAN: 475 case HELP_FORMAT_MAN:
483 rc = show_man_page(argv[0]); 476 rc = show_man_page(argv[0]);
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index b9bc7e39833a..ea8db38eedd1 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -18,10 +18,13 @@
18#include "util/data.h" 18#include "util/data.h"
19#include "util/auxtrace.h" 19#include "util/auxtrace.h"
20#include "util/jit.h" 20#include "util/jit.h"
21#include "util/thread.h"
21 22
22#include <subcmd/parse-options.h> 23#include <subcmd/parse-options.h>
23 24
24#include <linux/list.h> 25#include <linux/list.h>
26#include <errno.h>
27#include <signal.h>
25 28
26struct perf_inject { 29struct perf_inject {
27 struct perf_tool tool; 30 struct perf_tool tool;
@@ -333,6 +336,18 @@ static int perf_event__repipe_comm(struct perf_tool *tool,
333 return err; 336 return err;
334} 337}
335 338
339static int perf_event__repipe_namespaces(struct perf_tool *tool,
340 union perf_event *event,
341 struct perf_sample *sample,
342 struct machine *machine)
343{
344 int err = perf_event__process_namespaces(tool, event, sample, machine);
345
346 perf_event__repipe(tool, event, sample, machine);
347
348 return err;
349}
350
336static int perf_event__repipe_exit(struct perf_tool *tool, 351static int perf_event__repipe_exit(struct perf_tool *tool,
337 union perf_event *event, 352 union perf_event *event,
338 struct perf_sample *sample, 353 struct perf_sample *sample,
@@ -660,6 +675,7 @@ static int __cmd_inject(struct perf_inject *inject)
660 session->itrace_synth_opts = &inject->itrace_synth_opts; 675 session->itrace_synth_opts = &inject->itrace_synth_opts;
661 inject->itrace_synth_opts.inject = true; 676 inject->itrace_synth_opts.inject = true;
662 inject->tool.comm = perf_event__repipe_comm; 677 inject->tool.comm = perf_event__repipe_comm;
678 inject->tool.namespaces = perf_event__repipe_namespaces;
663 inject->tool.exit = perf_event__repipe_exit; 679 inject->tool.exit = perf_event__repipe_exit;
664 inject->tool.id_index = perf_event__repipe_id_index; 680 inject->tool.id_index = perf_event__repipe_id_index;
665 inject->tool.auxtrace_info = perf_event__process_auxtrace_info; 681 inject->tool.auxtrace_info = perf_event__process_auxtrace_info;
@@ -681,6 +697,8 @@ static int __cmd_inject(struct perf_inject *inject)
681 lseek(fd, output_data_offset, SEEK_SET); 697 lseek(fd, output_data_offset, SEEK_SET);
682 698
683 ret = perf_session__process_events(session); 699 ret = perf_session__process_events(session);
700 if (ret)
701 return ret;
684 702
685 if (!file_out->is_pipe) { 703 if (!file_out->is_pipe) {
686 if (inject->build_ids) 704 if (inject->build_ids)
@@ -725,7 +743,7 @@ static int __cmd_inject(struct perf_inject *inject)
725 return ret; 743 return ret;
726} 744}
727 745
728int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) 746int cmd_inject(int argc, const char **argv)
729{ 747{
730 struct perf_inject inject = { 748 struct perf_inject inject = {
731 .tool = { 749 .tool = {
diff --git a/tools/perf/builtin-kallsyms.c b/tools/perf/builtin-kallsyms.c
index 224bfc454b4a..bcfb363112d3 100644
--- a/tools/perf/builtin-kallsyms.c
+++ b/tools/perf/builtin-kallsyms.c
@@ -7,6 +7,7 @@
7 * 7 *
8 * Released under the GPL v2. (and only v2, not any later version) 8 * Released under the GPL v2. (and only v2, not any later version)
9 */ 9 */
10#include <inttypes.h>
10#include "builtin.h" 11#include "builtin.h"
11#include <linux/compiler.h> 12#include <linux/compiler.h>
12#include <subcmd/parse-options.h> 13#include <subcmd/parse-options.h>
@@ -43,7 +44,7 @@ static int __cmd_kallsyms(int argc, const char **argv)
43 return 0; 44 return 0;
44} 45}
45 46
46int cmd_kallsyms(int argc, const char **argv, const char *prefix __maybe_unused) 47int cmd_kallsyms(int argc, const char **argv)
47{ 48{
48 const struct option options[] = { 49 const struct option options[] = {
49 OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"), 50 OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"),
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 6da8d083e4e5..9409c9464667 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -20,11 +20,16 @@
20 20
21#include "util/debug.h" 21#include "util/debug.h"
22 22
23#include <linux/kernel.h>
23#include <linux/rbtree.h> 24#include <linux/rbtree.h>
24#include <linux/string.h> 25#include <linux/string.h>
26#include <errno.h>
27#include <inttypes.h>
25#include <locale.h> 28#include <locale.h>
26#include <regex.h> 29#include <regex.h>
27 30
31#include "sane_ctype.h"
32
28static int kmem_slab; 33static int kmem_slab;
29static int kmem_page; 34static int kmem_page;
30 35
@@ -964,6 +969,7 @@ static struct perf_tool perf_kmem = {
964 .comm = perf_event__process_comm, 969 .comm = perf_event__process_comm,
965 .mmap = perf_event__process_mmap, 970 .mmap = perf_event__process_mmap,
966 .mmap2 = perf_event__process_mmap2, 971 .mmap2 = perf_event__process_mmap2,
972 .namespaces = perf_event__process_namespaces,
967 .ordered_events = true, 973 .ordered_events = true,
968}; 974};
969 975
@@ -1865,7 +1871,7 @@ static int __cmd_record(int argc, const char **argv)
1865 for (j = 1; j < (unsigned int)argc; j++, i++) 1871 for (j = 1; j < (unsigned int)argc; j++, i++)
1866 rec_argv[i] = argv[j]; 1872 rec_argv[i] = argv[j];
1867 1873
1868 return cmd_record(i, rec_argv, NULL); 1874 return cmd_record(i, rec_argv);
1869} 1875}
1870 1876
1871static int kmem_config(const char *var, const char *value, void *cb __maybe_unused) 1877static int kmem_config(const char *var, const char *value, void *cb __maybe_unused)
@@ -1884,7 +1890,7 @@ static int kmem_config(const char *var, const char *value, void *cb __maybe_unus
1884 return 0; 1890 return 0;
1885} 1891}
1886 1892
1887int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused) 1893int cmd_kmem(int argc, const char **argv)
1888{ 1894{
1889 const char * const default_slab_sort = "frag,hit,bytes"; 1895 const char * const default_slab_sort = "frag,hit,bytes";
1890 const char * const default_page_sort = "bytes,hit"; 1896 const char * const default_page_sort = "bytes,hit";
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 08fa88f62a24..f309c3773522 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -3,6 +3,7 @@
3 3
4#include "util/evsel.h" 4#include "util/evsel.h"
5#include "util/evlist.h" 5#include "util/evlist.h"
6#include "util/term.h"
6#include "util/util.h" 7#include "util/util.h"
7#include "util/cache.h" 8#include "util/cache.h"
8#include "util/symbol.h" 9#include "util/symbol.h"
@@ -23,13 +24,33 @@
23#ifdef HAVE_TIMERFD_SUPPORT 24#ifdef HAVE_TIMERFD_SUPPORT
24#include <sys/timerfd.h> 25#include <sys/timerfd.h>
25#endif 26#endif
27#include <sys/time.h>
26 28
29#include <linux/kernel.h>
27#include <linux/time64.h> 30#include <linux/time64.h>
31#include <errno.h>
32#include <inttypes.h>
33#include <poll.h>
28#include <termios.h> 34#include <termios.h>
29#include <semaphore.h> 35#include <semaphore.h>
36#include <signal.h>
30#include <pthread.h> 37#include <pthread.h>
31#include <math.h> 38#include <math.h>
32 39
40static const char *get_filename_for_perf_kvm(void)
41{
42 const char *filename;
43
44 if (perf_host && !perf_guest)
45 filename = strdup("perf.data.host");
46 else if (!perf_host && perf_guest)
47 filename = strdup("perf.data.guest");
48 else
49 filename = strdup("perf.data.kvm");
50
51 return filename;
52}
53
33#ifdef HAVE_KVM_STAT_SUPPORT 54#ifdef HAVE_KVM_STAT_SUPPORT
34#include "util/kvm-stat.h" 55#include "util/kvm-stat.h"
35 56
@@ -1044,6 +1065,7 @@ static int read_events(struct perf_kvm_stat *kvm)
1044 struct perf_tool eops = { 1065 struct perf_tool eops = {
1045 .sample = process_sample_event, 1066 .sample = process_sample_event,
1046 .comm = perf_event__process_comm, 1067 .comm = perf_event__process_comm,
1068 .namespaces = perf_event__process_namespaces,
1047 .ordered_events = true, 1069 .ordered_events = true,
1048 }; 1070 };
1049 struct perf_data_file file = { 1071 struct perf_data_file file = {
@@ -1208,7 +1230,7 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
1208 set_option_flag(record_options, 0, "transaction", PARSE_OPT_DISABLED); 1230 set_option_flag(record_options, 0, "transaction", PARSE_OPT_DISABLED);
1209 1231
1210 record_usage = kvm_stat_record_usage; 1232 record_usage = kvm_stat_record_usage;
1211 return cmd_record(i, rec_argv, NULL); 1233 return cmd_record(i, rec_argv);
1212} 1234}
1213 1235
1214static int 1236static int
@@ -1348,6 +1370,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
1348 kvm->tool.exit = perf_event__process_exit; 1370 kvm->tool.exit = perf_event__process_exit;
1349 kvm->tool.fork = perf_event__process_fork; 1371 kvm->tool.fork = perf_event__process_fork;
1350 kvm->tool.lost = process_lost_event; 1372 kvm->tool.lost = process_lost_event;
1373 kvm->tool.namespaces = perf_event__process_namespaces;
1351 kvm->tool.ordered_events = true; 1374 kvm->tool.ordered_events = true;
1352 perf_tool__fill_defaults(&kvm->tool); 1375 perf_tool__fill_defaults(&kvm->tool);
1353 1376
@@ -1475,7 +1498,7 @@ static int kvm_cmd_stat(const char *file_name, int argc, const char **argv)
1475#endif 1498#endif
1476 1499
1477perf_stat: 1500perf_stat:
1478 return cmd_stat(argc, argv, NULL); 1501 return cmd_stat(argc, argv);
1479} 1502}
1480#endif /* HAVE_KVM_STAT_SUPPORT */ 1503#endif /* HAVE_KVM_STAT_SUPPORT */
1481 1504
@@ -1494,7 +1517,7 @@ static int __cmd_record(const char *file_name, int argc, const char **argv)
1494 1517
1495 BUG_ON(i != rec_argc); 1518 BUG_ON(i != rec_argc);
1496 1519
1497 return cmd_record(i, rec_argv, NULL); 1520 return cmd_record(i, rec_argv);
1498} 1521}
1499 1522
1500static int __cmd_report(const char *file_name, int argc, const char **argv) 1523static int __cmd_report(const char *file_name, int argc, const char **argv)
@@ -1512,7 +1535,7 @@ static int __cmd_report(const char *file_name, int argc, const char **argv)
1512 1535
1513 BUG_ON(i != rec_argc); 1536 BUG_ON(i != rec_argc);
1514 1537
1515 return cmd_report(i, rec_argv, NULL); 1538 return cmd_report(i, rec_argv);
1516} 1539}
1517 1540
1518static int 1541static int
@@ -1531,10 +1554,10 @@ __cmd_buildid_list(const char *file_name, int argc, const char **argv)
1531 1554
1532 BUG_ON(i != rec_argc); 1555 BUG_ON(i != rec_argc);
1533 1556
1534 return cmd_buildid_list(i, rec_argv, NULL); 1557 return cmd_buildid_list(i, rec_argv);
1535} 1558}
1536 1559
1537int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused) 1560int cmd_kvm(int argc, const char **argv)
1538{ 1561{
1539 const char *file_name = NULL; 1562 const char *file_name = NULL;
1540 const struct option kvm_options[] = { 1563 const struct option kvm_options[] = {
@@ -1589,9 +1612,9 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
1589 else if (!strncmp(argv[0], "rep", 3)) 1612 else if (!strncmp(argv[0], "rep", 3))
1590 return __cmd_report(file_name, argc, argv); 1613 return __cmd_report(file_name, argc, argv);
1591 else if (!strncmp(argv[0], "diff", 4)) 1614 else if (!strncmp(argv[0], "diff", 4))
1592 return cmd_diff(argc, argv, NULL); 1615 return cmd_diff(argc, argv);
1593 else if (!strncmp(argv[0], "top", 3)) 1616 else if (!strncmp(argv[0], "top", 3))
1594 return cmd_top(argc, argv, NULL); 1617 return cmd_top(argc, argv);
1595 else if (!strncmp(argv[0], "buildid-list", 12)) 1618 else if (!strncmp(argv[0], "buildid-list", 12))
1596 return __cmd_buildid_list(file_name, argc, argv); 1619 return __cmd_buildid_list(file_name, argc, argv);
1597#ifdef HAVE_KVM_STAT_SUPPORT 1620#ifdef HAVE_KVM_STAT_SUPPORT
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 3b9d98b5feef..4bf2cb4d25aa 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -18,8 +18,9 @@
18#include <subcmd/parse-options.h> 18#include <subcmd/parse-options.h>
19 19
20static bool desc_flag = true; 20static bool desc_flag = true;
21static bool details_flag;
21 22
22int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) 23int cmd_list(int argc, const char **argv)
23{ 24{
24 int i; 25 int i;
25 bool raw_dump = false; 26 bool raw_dump = false;
@@ -30,6 +31,8 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
30 "Print extra event descriptions. --no-desc to not print."), 31 "Print extra event descriptions. --no-desc to not print."),
31 OPT_BOOLEAN('v', "long-desc", &long_desc_flag, 32 OPT_BOOLEAN('v', "long-desc", &long_desc_flag,
32 "Print longer event descriptions."), 33 "Print longer event descriptions."),
34 OPT_BOOLEAN(0, "details", &details_flag,
35 "Print information on the perf event names and expressions used internally by events."),
33 OPT_INCR(0, "debug", &verbose, 36 OPT_INCR(0, "debug", &verbose,
34 "Enable debugging output"), 37 "Enable debugging output"),
35 OPT_END() 38 OPT_END()
@@ -50,7 +53,8 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
50 printf("\nList of pre-defined events (to be used in -e):\n\n"); 53 printf("\nList of pre-defined events (to be used in -e):\n\n");
51 54
52 if (argc == 0) { 55 if (argc == 0) {
53 print_events(NULL, raw_dump, !desc_flag, long_desc_flag); 56 print_events(NULL, raw_dump, !desc_flag, long_desc_flag,
57 details_flag);
54 return 0; 58 return 0;
55 } 59 }
56 60
@@ -72,7 +76,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
72 print_hwcache_events(NULL, raw_dump); 76 print_hwcache_events(NULL, raw_dump);
73 else if (strcmp(argv[i], "pmu") == 0) 77 else if (strcmp(argv[i], "pmu") == 0)
74 print_pmu_events(NULL, raw_dump, !desc_flag, 78 print_pmu_events(NULL, raw_dump, !desc_flag,
75 long_desc_flag); 79 long_desc_flag, details_flag);
76 else if (strcmp(argv[i], "sdt") == 0) 80 else if (strcmp(argv[i], "sdt") == 0)
77 print_sdt_events(NULL, NULL, raw_dump); 81 print_sdt_events(NULL, NULL, raw_dump);
78 else if ((sep = strchr(argv[i], ':')) != NULL) { 82 else if ((sep = strchr(argv[i], ':')) != NULL) {
@@ -80,7 +84,8 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
80 84
81 if (sep == NULL) { 85 if (sep == NULL) {
82 print_events(argv[i], raw_dump, !desc_flag, 86 print_events(argv[i], raw_dump, !desc_flag,
83 long_desc_flag); 87 long_desc_flag,
88 details_flag);
84 continue; 89 continue;
85 } 90 }
86 sep_idx = sep - argv[i]; 91 sep_idx = sep - argv[i];
@@ -103,7 +108,8 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
103 event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump); 108 event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
104 print_hwcache_events(s, raw_dump); 109 print_hwcache_events(s, raw_dump);
105 print_pmu_events(s, raw_dump, !desc_flag, 110 print_pmu_events(s, raw_dump, !desc_flag,
106 long_desc_flag); 111 long_desc_flag,
112 details_flag);
107 print_tracepoint_events(NULL, s, raw_dump); 113 print_tracepoint_events(NULL, s, raw_dump);
108 print_sdt_events(NULL, s, raw_dump); 114 print_sdt_events(NULL, s, raw_dump);
109 free(s); 115 free(s);
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index ce3bfb48b26f..ff98652484a7 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -1,3 +1,5 @@
1#include <errno.h>
2#include <inttypes.h>
1#include "builtin.h" 3#include "builtin.h"
2#include "perf.h" 4#include "perf.h"
3 5
@@ -26,6 +28,7 @@
26 28
27#include <linux/list.h> 29#include <linux/list.h>
28#include <linux/hash.h> 30#include <linux/hash.h>
31#include <linux/kernel.h>
29 32
30static struct perf_session *session; 33static struct perf_session *session;
31 34
@@ -858,6 +861,7 @@ static int __cmd_report(bool display_info)
858 struct perf_tool eops = { 861 struct perf_tool eops = {
859 .sample = process_sample_event, 862 .sample = process_sample_event,
860 .comm = perf_event__process_comm, 863 .comm = perf_event__process_comm,
864 .namespaces = perf_event__process_namespaces,
861 .ordered_events = true, 865 .ordered_events = true,
862 }; 866 };
863 struct perf_data_file file = { 867 struct perf_data_file file = {
@@ -940,34 +944,36 @@ static int __cmd_record(int argc, const char **argv)
940 944
941 BUG_ON(i != rec_argc); 945 BUG_ON(i != rec_argc);
942 946
943 ret = cmd_record(i, rec_argv, NULL); 947 ret = cmd_record(i, rec_argv);
944 free(rec_argv); 948 free(rec_argv);
945 return ret; 949 return ret;
946} 950}
947 951
948int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused) 952int cmd_lock(int argc, const char **argv)
949{ 953{
950 const struct option info_options[] = {
951 OPT_BOOLEAN('t', "threads", &info_threads,
952 "dump thread list in perf.data"),
953 OPT_BOOLEAN('m', "map", &info_map,
954 "map of lock instances (address:name table)"),
955 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
956 OPT_END()
957 };
958 const struct option lock_options[] = { 954 const struct option lock_options[] = {
959 OPT_STRING('i', "input", &input_name, "file", "input file name"), 955 OPT_STRING('i', "input", &input_name, "file", "input file name"),
960 OPT_INCR('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"), 956 OPT_INCR('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"),
961 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"), 957 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"),
958 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
962 OPT_END() 959 OPT_END()
963 }; 960 };
961
962 const struct option info_options[] = {
963 OPT_BOOLEAN('t', "threads", &info_threads,
964 "dump thread list in perf.data"),
965 OPT_BOOLEAN('m', "map", &info_map,
966 "map of lock instances (address:name table)"),
967 OPT_PARENT(lock_options)
968 };
969
964 const struct option report_options[] = { 970 const struct option report_options[] = {
965 OPT_STRING('k', "key", &sort_key, "acquired", 971 OPT_STRING('k', "key", &sort_key, "acquired",
966 "key for sorting (acquired / contended / avg_wait / wait_total / wait_max / wait_min)"), 972 "key for sorting (acquired / contended / avg_wait / wait_total / wait_max / wait_min)"),
967 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
968 /* TODO: type */ 973 /* TODO: type */
969 OPT_END() 974 OPT_PARENT(lock_options)
970 }; 975 };
976
971 const char * const info_usage[] = { 977 const char * const info_usage[] = {
972 "perf lock info [<options>]", 978 "perf lock info [<options>]",
973 NULL 979 NULL
@@ -1006,7 +1012,7 @@ int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)
1006 rc = __cmd_report(false); 1012 rc = __cmd_report(false);
1007 } else if (!strcmp(argv[0], "script")) { 1013 } else if (!strcmp(argv[0], "script")) {
1008 /* Aliased to 'perf script' */ 1014 /* Aliased to 'perf script' */
1009 return cmd_script(argc, argv, prefix); 1015 return cmd_script(argc, argv);
1010 } else if (!strcmp(argv[0], "info")) { 1016 } else if (!strcmp(argv[0], "info")) {
1011 if (argc) { 1017 if (argc) {
1012 argc = parse_options(argc, argv, 1018 argc = parse_options(argc, argv,
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 6114e07ca613..e001c0290793 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -1,3 +1,7 @@
1#include <inttypes.h>
2#include <sys/types.h>
3#include <sys/stat.h>
4#include <unistd.h>
1#include "builtin.h" 5#include "builtin.h"
2#include "perf.h" 6#include "perf.h"
3 7
@@ -8,6 +12,7 @@
8#include "util/data.h" 12#include "util/data.h"
9#include "util/mem-events.h" 13#include "util/mem-events.h"
10#include "util/debug.h" 14#include "util/debug.h"
15#include "util/symbol.h"
11 16
12#define MEM_OPERATION_LOAD 0x1 17#define MEM_OPERATION_LOAD 0x1
13#define MEM_OPERATION_STORE 0x2 18#define MEM_OPERATION_STORE 0x2
@@ -129,7 +134,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
129 pr_debug("\n"); 134 pr_debug("\n");
130 } 135 }
131 136
132 ret = cmd_record(i, rec_argv, NULL); 137 ret = cmd_record(i, rec_argv);
133 free(rec_argv); 138 free(rec_argv);
134 return ret; 139 return ret;
135} 140}
@@ -256,7 +261,7 @@ static int report_events(int argc, const char **argv, struct perf_mem *mem)
256 for (j = 1; j < argc; j++, i++) 261 for (j = 1; j < argc; j++, i++)
257 rep_argv[i] = argv[j]; 262 rep_argv[i] = argv[j];
258 263
259 ret = cmd_report(i, rep_argv, NULL); 264 ret = cmd_report(i, rep_argv);
260 free(rep_argv); 265 free(rep_argv);
261 return ret; 266 return ret;
262} 267}
@@ -330,7 +335,7 @@ error:
330 return ret; 335 return ret;
331} 336}
332 337
333int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused) 338int cmd_mem(int argc, const char **argv)
334{ 339{
335 struct stat st; 340 struct stat st;
336 struct perf_mem mem = { 341 struct perf_mem mem = {
@@ -342,6 +347,7 @@ int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused)
342 .lost = perf_event__process_lost, 347 .lost = perf_event__process_lost,
343 .fork = perf_event__process_fork, 348 .fork = perf_event__process_fork,
344 .build_id = perf_event__process_build_id, 349 .build_id = perf_event__process_build_id,
350 .namespaces = perf_event__process_namespaces,
345 .ordered_events = true, 351 .ordered_events = true,
346 }, 352 },
347 .input_name = "perf.data", 353 .input_name = "perf.data",
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 1fcebc31a508..d7360c2bda13 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -442,9 +442,9 @@ static int perf_del_probe_events(struct strfilter *filter)
442 } 442 }
443 443
444 if (ret == -ENOENT && ret2 == -ENOENT) 444 if (ret == -ENOENT && ret2 == -ENOENT)
445 pr_debug("\"%s\" does not hit any event.\n", str); 445 pr_warning("\"%s\" does not hit any event.\n", str);
446 /* Note that this is silently ignored */ 446 else
447 ret = 0; 447 ret = 0;
448 448
449error: 449error:
450 if (kfd >= 0) 450 if (kfd >= 0)
@@ -468,7 +468,7 @@ out:
468 468
469 469
470static int 470static int
471__cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) 471__cmd_probe(int argc, const char **argv)
472{ 472{
473 const char * const probe_usage[] = { 473 const char * const probe_usage[] = {
474 "perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]", 474 "perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]",
@@ -687,13 +687,13 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
687 return 0; 687 return 0;
688} 688}
689 689
690int cmd_probe(int argc, const char **argv, const char *prefix) 690int cmd_probe(int argc, const char **argv)
691{ 691{
692 int ret; 692 int ret;
693 693
694 ret = init_params(); 694 ret = init_params();
695 if (!ret) { 695 if (!ret) {
696 ret = __cmd_probe(argc, argv, prefix); 696 ret = __cmd_probe(argc, argv);
697 cleanup_params(); 697 cleanup_params();
698 } 698 }
699 699
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index bc84a375295d..ee7d0a82ccd0 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -38,11 +38,18 @@
38#include "util/bpf-loader.h" 38#include "util/bpf-loader.h"
39#include "util/trigger.h" 39#include "util/trigger.h"
40#include "util/perf-hooks.h" 40#include "util/perf-hooks.h"
41#include "util/time-utils.h"
42#include "util/units.h"
41#include "asm/bug.h" 43#include "asm/bug.h"
42 44
45#include <errno.h>
46#include <inttypes.h>
47#include <poll.h>
43#include <unistd.h> 48#include <unistd.h>
44#include <sched.h> 49#include <sched.h>
50#include <signal.h>
45#include <sys/mman.h> 51#include <sys/mman.h>
52#include <sys/wait.h>
46#include <asm/bug.h> 53#include <asm/bug.h>
47#include <linux/time64.h> 54#include <linux/time64.h>
48 55
@@ -876,6 +883,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
876 signal(SIGTERM, sig_handler); 883 signal(SIGTERM, sig_handler);
877 signal(SIGSEGV, sigsegv_handler); 884 signal(SIGSEGV, sigsegv_handler);
878 885
886 if (rec->opts.record_namespaces)
887 tool->namespace_events = true;
888
879 if (rec->opts.auxtrace_snapshot_mode || rec->switch_output.enabled) { 889 if (rec->opts.auxtrace_snapshot_mode || rec->switch_output.enabled) {
880 signal(SIGUSR2, snapshot_sig_handler); 890 signal(SIGUSR2, snapshot_sig_handler);
881 if (rec->opts.auxtrace_snapshot_mode) 891 if (rec->opts.auxtrace_snapshot_mode)
@@ -983,6 +993,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
983 */ 993 */
984 if (forks) { 994 if (forks) {
985 union perf_event *event; 995 union perf_event *event;
996 pid_t tgid;
986 997
987 event = malloc(sizeof(event->comm) + machine->id_hdr_size); 998 event = malloc(sizeof(event->comm) + machine->id_hdr_size);
988 if (event == NULL) { 999 if (event == NULL) {
@@ -996,10 +1007,30 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
996 * cannot see a correct process name for those events. 1007 * cannot see a correct process name for those events.
997 * Synthesize COMM event to prevent it. 1008 * Synthesize COMM event to prevent it.
998 */ 1009 */
999 perf_event__synthesize_comm(tool, event, 1010 tgid = perf_event__synthesize_comm(tool, event,
1000 rec->evlist->workload.pid, 1011 rec->evlist->workload.pid,
1001 process_synthesized_event, 1012 process_synthesized_event,
1002 machine); 1013 machine);
1014 free(event);
1015
1016 if (tgid == -1)
1017 goto out_child;
1018
1019 event = malloc(sizeof(event->namespaces) +
1020 (NR_NAMESPACES * sizeof(struct perf_ns_link_info)) +
1021 machine->id_hdr_size);
1022 if (event == NULL) {
1023 err = -ENOMEM;
1024 goto out_child;
1025 }
1026
1027 /*
1028 * Synthesize NAMESPACES event for the command specified.
1029 */
1030 perf_event__synthesize_namespaces(tool, event,
1031 rec->evlist->workload.pid,
1032 tgid, process_synthesized_event,
1033 machine);
1003 free(event); 1034 free(event);
1004 1035
1005 perf_evlist__start_workload(rec->evlist); 1036 perf_evlist__start_workload(rec->evlist);
@@ -1497,6 +1528,7 @@ static struct record record = {
1497 .fork = perf_event__process_fork, 1528 .fork = perf_event__process_fork,
1498 .exit = perf_event__process_exit, 1529 .exit = perf_event__process_exit,
1499 .comm = perf_event__process_comm, 1530 .comm = perf_event__process_comm,
1531 .namespaces = perf_event__process_namespaces,
1500 .mmap = perf_event__process_mmap, 1532 .mmap = perf_event__process_mmap,
1501 .mmap2 = perf_event__process_mmap2, 1533 .mmap2 = perf_event__process_mmap2,
1502 .ordered_events = true, 1534 .ordered_events = true,
@@ -1611,6 +1643,8 @@ static struct option __record_options[] = {
1611 "opts", "AUX area tracing Snapshot Mode", ""), 1643 "opts", "AUX area tracing Snapshot Mode", ""),
1612 OPT_UINTEGER(0, "proc-map-timeout", &record.opts.proc_map_timeout, 1644 OPT_UINTEGER(0, "proc-map-timeout", &record.opts.proc_map_timeout,
1613 "per thread proc mmap processing timeout in ms"), 1645 "per thread proc mmap processing timeout in ms"),
1646 OPT_BOOLEAN(0, "namespaces", &record.opts.record_namespaces,
1647 "Record namespaces events"),
1614 OPT_BOOLEAN(0, "switch-events", &record.opts.record_switch_events, 1648 OPT_BOOLEAN(0, "switch-events", &record.opts.record_switch_events,
1615 "Record context switch events"), 1649 "Record context switch events"),
1616 OPT_BOOLEAN_FLAG(0, "all-kernel", &record.opts.all_kernel, 1650 OPT_BOOLEAN_FLAG(0, "all-kernel", &record.opts.all_kernel,
@@ -1640,7 +1674,7 @@ static struct option __record_options[] = {
1640 1674
1641struct option *record_options = __record_options; 1675struct option *record_options = __record_options;
1642 1676
1643int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) 1677int cmd_record(int argc, const char **argv)
1644{ 1678{
1645 int err; 1679 int err;
1646 struct record *rec = &record; 1680 struct record *rec = &record;
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 0a88670e56f3..22478ff2b706 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -16,7 +16,6 @@
16#include <linux/rbtree.h> 16#include <linux/rbtree.h>
17#include "util/symbol.h" 17#include "util/symbol.h"
18#include "util/callchain.h" 18#include "util/callchain.h"
19#include "util/strlist.h"
20#include "util/values.h" 19#include "util/values.h"
21 20
22#include "perf.h" 21#include "perf.h"
@@ -38,10 +37,18 @@
38#include "arch/common.h" 37#include "arch/common.h"
39#include "util/time-utils.h" 38#include "util/time-utils.h"
40#include "util/auxtrace.h" 39#include "util/auxtrace.h"
40#include "util/units.h"
41 41
42#include <dlfcn.h> 42#include <dlfcn.h>
43#include <errno.h>
44#include <inttypes.h>
45#include <regex.h>
46#include <signal.h>
43#include <linux/bitmap.h> 47#include <linux/bitmap.h>
44#include <linux/stringify.h> 48#include <linux/stringify.h>
49#include <sys/types.h>
50#include <sys/stat.h>
51#include <unistd.h>
45 52
46struct report { 53struct report {
47 struct perf_tool tool; 54 struct perf_tool tool;
@@ -394,8 +401,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
394 fprintf(stdout, "\n\n"); 401 fprintf(stdout, "\n\n");
395 } 402 }
396 403
397 if (sort_order == NULL && 404 if (!quiet)
398 parent_pattern == default_parent_pattern)
399 fprintf(stdout, "#\n# (%s)\n#\n", help); 405 fprintf(stdout, "#\n# (%s)\n#\n", help);
400 406
401 if (rep->show_threads) { 407 if (rep->show_threads) {
@@ -682,7 +688,7 @@ const char report_callchain_help[] = "Display call graph (stack chain/backtrace)
682 CALLCHAIN_REPORT_HELP 688 CALLCHAIN_REPORT_HELP
683 "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT; 689 "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT;
684 690
685int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) 691int cmd_report(int argc, const char **argv)
686{ 692{
687 struct perf_session *session; 693 struct perf_session *session;
688 struct itrace_synth_opts itrace_synth_opts = { .set = 0, }; 694 struct itrace_synth_opts itrace_synth_opts = { .set = 0, };
@@ -701,6 +707,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
701 .mmap = perf_event__process_mmap, 707 .mmap = perf_event__process_mmap,
702 .mmap2 = perf_event__process_mmap2, 708 .mmap2 = perf_event__process_mmap2,
703 .comm = perf_event__process_comm, 709 .comm = perf_event__process_comm,
710 .namespaces = perf_event__process_namespaces,
704 .exit = perf_event__process_exit, 711 .exit = perf_event__process_exit,
705 .fork = perf_event__process_fork, 712 .fork = perf_event__process_fork,
706 .lost = perf_event__process_lost, 713 .lost = perf_event__process_lost,
@@ -845,6 +852,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
845 stdio__config_color, "always"), 852 stdio__config_color, "always"),
846 OPT_STRING(0, "time", &report.time_str, "str", 853 OPT_STRING(0, "time", &report.time_str, "str",
847 "Time span of interest (start,stop)"), 854 "Time span of interest (start,stop)"),
855 OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name,
856 "Show inline function"),
848 OPT_END() 857 OPT_END()
849 }; 858 };
850 struct perf_data_file file = { 859 struct perf_data_file file = {
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index b94cf0de715a..39996c53995a 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -22,16 +22,21 @@
22 22
23#include "util/debug.h" 23#include "util/debug.h"
24 24
25#include <linux/kernel.h>
25#include <linux/log2.h> 26#include <linux/log2.h>
26#include <sys/prctl.h> 27#include <sys/prctl.h>
27#include <sys/resource.h> 28#include <sys/resource.h>
29#include <inttypes.h>
28 30
31#include <errno.h>
29#include <semaphore.h> 32#include <semaphore.h>
30#include <pthread.h> 33#include <pthread.h>
31#include <math.h> 34#include <math.h>
32#include <api/fs/fs.h> 35#include <api/fs/fs.h>
33#include <linux/time64.h> 36#include <linux/time64.h>
34 37
38#include "sane_ctype.h"
39
35#define PR_SET_NAME 15 /* Set process name */ 40#define PR_SET_NAME 15 /* Set process name */
36#define MAX_CPUS 4096 41#define MAX_CPUS 4096
37#define COMM_LEN 20 42#define COMM_LEN 20
@@ -221,6 +226,7 @@ struct perf_sched {
221 unsigned int max_stack; 226 unsigned int max_stack;
222 bool show_cpu_visual; 227 bool show_cpu_visual;
223 bool show_wakeups; 228 bool show_wakeups;
229 bool show_next;
224 bool show_migrations; 230 bool show_migrations;
225 bool show_state; 231 bool show_state;
226 u64 skipped_samples; 232 u64 skipped_samples;
@@ -1897,14 +1903,18 @@ static char task_state_char(struct thread *thread, int state)
1897} 1903}
1898 1904
1899static void timehist_print_sample(struct perf_sched *sched, 1905static void timehist_print_sample(struct perf_sched *sched,
1906 struct perf_evsel *evsel,
1900 struct perf_sample *sample, 1907 struct perf_sample *sample,
1901 struct addr_location *al, 1908 struct addr_location *al,
1902 struct thread *thread, 1909 struct thread *thread,
1903 u64 t, int state) 1910 u64 t, int state)
1904{ 1911{
1905 struct thread_runtime *tr = thread__priv(thread); 1912 struct thread_runtime *tr = thread__priv(thread);
1913 const char *next_comm = perf_evsel__strval(evsel, sample, "next_comm");
1914 const u32 next_pid = perf_evsel__intval(evsel, sample, "next_pid");
1906 u32 max_cpus = sched->max_cpu + 1; 1915 u32 max_cpus = sched->max_cpu + 1;
1907 char tstr[64]; 1916 char tstr[64];
1917 char nstr[30];
1908 u64 wait_time; 1918 u64 wait_time;
1909 1919
1910 timestamp__scnprintf_usec(t, tstr, sizeof(tstr)); 1920 timestamp__scnprintf_usec(t, tstr, sizeof(tstr));
@@ -1937,7 +1947,12 @@ static void timehist_print_sample(struct perf_sched *sched,
1937 if (sched->show_state) 1947 if (sched->show_state)
1938 printf(" %5c ", task_state_char(thread, state)); 1948 printf(" %5c ", task_state_char(thread, state));
1939 1949
1940 if (sched->show_wakeups) 1950 if (sched->show_next) {
1951 snprintf(nstr, sizeof(nstr), "next: %s[%d]", next_comm, next_pid);
1952 printf(" %-*s", comm_width, nstr);
1953 }
1954
1955 if (sched->show_wakeups && !sched->show_next)
1941 printf(" %-*s", comm_width, ""); 1956 printf(" %-*s", comm_width, "");
1942 1957
1943 if (thread->tid == 0) 1958 if (thread->tid == 0)
@@ -2531,7 +2546,7 @@ static int timehist_sched_change_event(struct perf_tool *tool,
2531 } 2546 }
2532 2547
2533 if (!sched->summary_only) 2548 if (!sched->summary_only)
2534 timehist_print_sample(sched, sample, &al, thread, t, state); 2549 timehist_print_sample(sched, evsel, sample, &al, thread, t, state);
2535 2550
2536out: 2551out:
2537 if (sched->hist_time.start == 0 && t >= ptime->start) 2552 if (sched->hist_time.start == 0 && t >= ptime->start)
@@ -3262,16 +3277,17 @@ static int __cmd_record(int argc, const char **argv)
3262 3277
3263 BUG_ON(i != rec_argc); 3278 BUG_ON(i != rec_argc);
3264 3279
3265 return cmd_record(i, rec_argv, NULL); 3280 return cmd_record(i, rec_argv);
3266} 3281}
3267 3282
3268int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused) 3283int cmd_sched(int argc, const char **argv)
3269{ 3284{
3270 const char default_sort_order[] = "avg, max, switch, runtime"; 3285 const char default_sort_order[] = "avg, max, switch, runtime";
3271 struct perf_sched sched = { 3286 struct perf_sched sched = {
3272 .tool = { 3287 .tool = {
3273 .sample = perf_sched__process_tracepoint_sample, 3288 .sample = perf_sched__process_tracepoint_sample,
3274 .comm = perf_event__process_comm, 3289 .comm = perf_event__process_comm,
3290 .namespaces = perf_event__process_namespaces,
3275 .lost = perf_event__process_lost, 3291 .lost = perf_event__process_lost,
3276 .fork = perf_sched__process_fork_event, 3292 .fork = perf_sched__process_fork_event,
3277 .ordered_events = true, 3293 .ordered_events = true,
@@ -3340,6 +3356,7 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
3340 OPT_BOOLEAN('S', "with-summary", &sched.summary, 3356 OPT_BOOLEAN('S', "with-summary", &sched.summary,
3341 "Show all syscalls and summary with statistics"), 3357 "Show all syscalls and summary with statistics"),
3342 OPT_BOOLEAN('w', "wakeups", &sched.show_wakeups, "Show wakeup events"), 3358 OPT_BOOLEAN('w', "wakeups", &sched.show_wakeups, "Show wakeup events"),
3359 OPT_BOOLEAN('n', "next", &sched.show_next, "Show next task"),
3343 OPT_BOOLEAN('M', "migrations", &sched.show_migrations, "Show migration events"), 3360 OPT_BOOLEAN('M', "migrations", &sched.show_migrations, "Show migration events"),
3344 OPT_BOOLEAN('V', "cpu-visual", &sched.show_cpu_visual, "Add CPU visual"), 3361 OPT_BOOLEAN('V', "cpu-visual", &sched.show_cpu_visual, "Add CPU visual"),
3345 OPT_BOOLEAN('I', "idle-hist", &sched.idle_hist, "Show idle events only"), 3362 OPT_BOOLEAN('I', "idle-hist", &sched.idle_hist, "Show idle events only"),
@@ -3400,7 +3417,7 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
3400 * Aliased to 'perf script' for now: 3417 * Aliased to 'perf script' for now:
3401 */ 3418 */
3402 if (!strcmp(argv[0], "script")) 3419 if (!strcmp(argv[0], "script"))
3403 return cmd_script(argc, argv, prefix); 3420 return cmd_script(argc, argv);
3404 3421
3405 if (!strncmp(argv[0], "rec", 3)) { 3422 if (!strncmp(argv[0], "rec", 3)) {
3406 return __cmd_record(argc, argv); 3423 return __cmd_record(argc, argv);
@@ -3437,10 +3454,14 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
3437 if (argc) 3454 if (argc)
3438 usage_with_options(timehist_usage, timehist_options); 3455 usage_with_options(timehist_usage, timehist_options);
3439 } 3456 }
3440 if (sched.show_wakeups && sched.summary_only) { 3457 if ((sched.show_wakeups || sched.show_next) &&
3441 pr_err(" Error: -s and -w are mutually exclusive.\n"); 3458 sched.summary_only) {
3459 pr_err(" Error: -s and -[n|w] are mutually exclusive.\n");
3442 parse_options_usage(timehist_usage, timehist_options, "s", true); 3460 parse_options_usage(timehist_usage, timehist_options, "s", true);
3443 parse_options_usage(NULL, timehist_options, "w", true); 3461 if (sched.show_wakeups)
3462 parse_options_usage(NULL, timehist_options, "w", true);
3463 if (sched.show_next)
3464 parse_options_usage(NULL, timehist_options, "n", true);
3444 return -EINVAL; 3465 return -EINVAL;
3445 } 3466 }
3446 3467
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index c0783b4f7b6c..d05aec491cff 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -21,13 +21,27 @@
21#include "util/cpumap.h" 21#include "util/cpumap.h"
22#include "util/thread_map.h" 22#include "util/thread_map.h"
23#include "util/stat.h" 23#include "util/stat.h"
24#include "util/string2.h"
24#include "util/thread-stack.h" 25#include "util/thread-stack.h"
25#include "util/time-utils.h" 26#include "util/time-utils.h"
27#include "print_binary.h"
26#include <linux/bitmap.h> 28#include <linux/bitmap.h>
29#include <linux/kernel.h>
27#include <linux/stringify.h> 30#include <linux/stringify.h>
28#include <linux/time64.h> 31#include <linux/time64.h>
29#include "asm/bug.h" 32#include "asm/bug.h"
30#include "util/mem-events.h" 33#include "util/mem-events.h"
34#include "util/dump-insn.h"
35#include <dirent.h>
36#include <errno.h>
37#include <inttypes.h>
38#include <signal.h>
39#include <sys/param.h>
40#include <sys/types.h>
41#include <sys/stat.h>
42#include <unistd.h>
43
44#include "sane_ctype.h"
31 45
32static char const *script_name; 46static char const *script_name;
33static char const *generate_script_lang; 47static char const *generate_script_lang;
@@ -42,6 +56,7 @@ static bool nanosecs;
42static const char *cpu_list; 56static const char *cpu_list;
43static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); 57static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
44static struct perf_stat_config stat_config; 58static struct perf_stat_config stat_config;
59static int max_blocks;
45 60
46unsigned int scripting_max_stack = PERF_MAX_STACK_DEPTH; 61unsigned int scripting_max_stack = PERF_MAX_STACK_DEPTH;
47 62
@@ -69,6 +84,7 @@ enum perf_output_field {
69 PERF_OUTPUT_CALLINDENT = 1U << 20, 84 PERF_OUTPUT_CALLINDENT = 1U << 20,
70 PERF_OUTPUT_INSN = 1U << 21, 85 PERF_OUTPUT_INSN = 1U << 21,
71 PERF_OUTPUT_INSNLEN = 1U << 22, 86 PERF_OUTPUT_INSNLEN = 1U << 22,
87 PERF_OUTPUT_BRSTACKINSN = 1U << 23,
72}; 88};
73 89
74struct output_option { 90struct output_option {
@@ -98,6 +114,7 @@ struct output_option {
98 {.str = "callindent", .field = PERF_OUTPUT_CALLINDENT}, 114 {.str = "callindent", .field = PERF_OUTPUT_CALLINDENT},
99 {.str = "insn", .field = PERF_OUTPUT_INSN}, 115 {.str = "insn", .field = PERF_OUTPUT_INSN},
100 {.str = "insnlen", .field = PERF_OUTPUT_INSNLEN}, 116 {.str = "insnlen", .field = PERF_OUTPUT_INSNLEN},
117 {.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN},
101}; 118};
102 119
103/* default set to maintain compatibility with current format */ 120/* default set to maintain compatibility with current format */
@@ -292,7 +309,13 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
292 "selected. Hence, no address to lookup the source line number.\n"); 309 "selected. Hence, no address to lookup the source line number.\n");
293 return -EINVAL; 310 return -EINVAL;
294 } 311 }
295 312 if (PRINT_FIELD(BRSTACKINSN) &&
313 !(perf_evlist__combined_branch_type(session->evlist) &
314 PERF_SAMPLE_BRANCH_ANY)) {
315 pr_err("Display of branch stack assembler requested, but non all-branch filter set\n"
316 "Hint: run 'perf record -b ...'\n");
317 return -EINVAL;
318 }
296 if ((PRINT_FIELD(PID) || PRINT_FIELD(TID)) && 319 if ((PRINT_FIELD(PID) || PRINT_FIELD(TID)) &&
297 perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID", 320 perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID",
298 PERF_OUTPUT_TID|PERF_OUTPUT_PID)) 321 PERF_OUTPUT_TID|PERF_OUTPUT_PID))
@@ -546,6 +569,233 @@ static void print_sample_brstacksym(struct perf_sample *sample,
546 } 569 }
547} 570}
548 571
572#define MAXBB 16384UL
573
574static int grab_bb(u8 *buffer, u64 start, u64 end,
575 struct machine *machine, struct thread *thread,
576 bool *is64bit, u8 *cpumode, bool last)
577{
578 long offset, len;
579 struct addr_location al;
580 bool kernel;
581
582 if (!start || !end)
583 return 0;
584
585 kernel = machine__kernel_ip(machine, start);
586 if (kernel)
587 *cpumode = PERF_RECORD_MISC_KERNEL;
588 else
589 *cpumode = PERF_RECORD_MISC_USER;
590
591 /*
592 * Block overlaps between kernel and user.
593 * This can happen due to ring filtering
594 * On Intel CPUs the entry into the kernel is filtered,
595 * but the exit is not. Let the caller patch it up.
596 */
597 if (kernel != machine__kernel_ip(machine, end)) {
598 printf("\tblock %" PRIx64 "-%" PRIx64 " transfers between kernel and user\n",
599 start, end);
600 return -ENXIO;
601 }
602
603 memset(&al, 0, sizeof(al));
604 if (end - start > MAXBB - MAXINSN) {
605 if (last)
606 printf("\tbrstack does not reach to final jump (%" PRIx64 "-%" PRIx64 ")\n", start, end);
607 else
608 printf("\tblock %" PRIx64 "-%" PRIx64 " (%" PRIu64 ") too long to dump\n", start, end, end - start);
609 return 0;
610 }
611
612 thread__find_addr_map(thread, *cpumode, MAP__FUNCTION, start, &al);
613 if (!al.map || !al.map->dso) {
614 printf("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
615 return 0;
616 }
617 if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR) {
618 printf("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
619 return 0;
620 }
621
622 /* Load maps to ensure dso->is_64_bit has been updated */
623 map__load(al.map);
624
625 offset = al.map->map_ip(al.map, start);
626 len = dso__data_read_offset(al.map->dso, machine, offset, (u8 *)buffer,
627 end - start + MAXINSN);
628
629 *is64bit = al.map->dso->is_64_bit;
630 if (len <= 0)
631 printf("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n",
632 start, end);
633 return len;
634}
635
636static void print_jump(uint64_t ip, struct branch_entry *en,
637 struct perf_insn *x, u8 *inbuf, int len,
638 int insn)
639{
640 printf("\t%016" PRIx64 "\t%-30s\t#%s%s%s%s",
641 ip,
642 dump_insn(x, ip, inbuf, len, NULL),
643 en->flags.predicted ? " PRED" : "",
644 en->flags.mispred ? " MISPRED" : "",
645 en->flags.in_tx ? " INTX" : "",
646 en->flags.abort ? " ABORT" : "");
647 if (en->flags.cycles) {
648 printf(" %d cycles", en->flags.cycles);
649 if (insn)
650 printf(" %.2f IPC", (float)insn / en->flags.cycles);
651 }
652 putchar('\n');
653}
654
655static void print_ip_sym(struct thread *thread, u8 cpumode, int cpu,
656 uint64_t addr, struct symbol **lastsym,
657 struct perf_event_attr *attr)
658{
659 struct addr_location al;
660 int off;
661
662 memset(&al, 0, sizeof(al));
663
664 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, addr, &al);
665 if (!al.map)
666 thread__find_addr_map(thread, cpumode, MAP__VARIABLE,
667 addr, &al);
668 if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end)
669 return;
670
671 al.cpu = cpu;
672 al.sym = NULL;
673 if (al.map)
674 al.sym = map__find_symbol(al.map, al.addr);
675
676 if (!al.sym)
677 return;
678
679 if (al.addr < al.sym->end)
680 off = al.addr - al.sym->start;
681 else
682 off = al.addr - al.map->start - al.sym->start;
683 printf("\t%s", al.sym->name);
684 if (off)
685 printf("%+d", off);
686 putchar(':');
687 if (PRINT_FIELD(SRCLINE))
688 map__fprintf_srcline(al.map, al.addr, "\t", stdout);
689 putchar('\n');
690 *lastsym = al.sym;
691}
692
693static void print_sample_brstackinsn(struct perf_sample *sample,
694 struct thread *thread,
695 struct perf_event_attr *attr,
696 struct machine *machine)
697{
698 struct branch_stack *br = sample->branch_stack;
699 u64 start, end;
700 int i, insn, len, nr, ilen;
701 struct perf_insn x;
702 u8 buffer[MAXBB];
703 unsigned off;
704 struct symbol *lastsym = NULL;
705
706 if (!(br && br->nr))
707 return;
708 nr = br->nr;
709 if (max_blocks && nr > max_blocks + 1)
710 nr = max_blocks + 1;
711
712 x.thread = thread;
713 x.cpu = sample->cpu;
714
715 putchar('\n');
716
717 /* Handle first from jump, of which we don't know the entry. */
718 len = grab_bb(buffer, br->entries[nr-1].from,
719 br->entries[nr-1].from,
720 machine, thread, &x.is64bit, &x.cpumode, false);
721 if (len > 0) {
722 print_ip_sym(thread, x.cpumode, x.cpu,
723 br->entries[nr - 1].from, &lastsym, attr);
724 print_jump(br->entries[nr - 1].from, &br->entries[nr - 1],
725 &x, buffer, len, 0);
726 }
727
728 /* Print all blocks */
729 for (i = nr - 2; i >= 0; i--) {
730 if (br->entries[i].from || br->entries[i].to)
731 pr_debug("%d: %" PRIx64 "-%" PRIx64 "\n", i,
732 br->entries[i].from,
733 br->entries[i].to);
734 start = br->entries[i + 1].to;
735 end = br->entries[i].from;
736
737 len = grab_bb(buffer, start, end, machine, thread, &x.is64bit, &x.cpumode, false);
738 /* Patch up missing kernel transfers due to ring filters */
739 if (len == -ENXIO && i > 0) {
740 end = br->entries[--i].from;
741 pr_debug("\tpatching up to %" PRIx64 "-%" PRIx64 "\n", start, end);
742 len = grab_bb(buffer, start, end, machine, thread, &x.is64bit, &x.cpumode, false);
743 }
744 if (len <= 0)
745 continue;
746
747 insn = 0;
748 for (off = 0;; off += ilen) {
749 uint64_t ip = start + off;
750
751 print_ip_sym(thread, x.cpumode, x.cpu, ip, &lastsym, attr);
752 if (ip == end) {
753 print_jump(ip, &br->entries[i], &x, buffer + off, len - off, insn);
754 break;
755 } else {
756 printf("\t%016" PRIx64 "\t%s\n", ip,
757 dump_insn(&x, ip, buffer + off, len - off, &ilen));
758 if (ilen == 0)
759 break;
760 insn++;
761 }
762 }
763 }
764
765 /*
766 * Hit the branch? In this case we are already done, and the target
767 * has not been executed yet.
768 */
769 if (br->entries[0].from == sample->ip)
770 return;
771 if (br->entries[0].flags.abort)
772 return;
773
774 /*
775 * Print final block upto sample
776 */
777 start = br->entries[0].to;
778 end = sample->ip;
779 len = grab_bb(buffer, start, end, machine, thread, &x.is64bit, &x.cpumode, true);
780 print_ip_sym(thread, x.cpumode, x.cpu, start, &lastsym, attr);
781 if (len <= 0) {
782 /* Print at least last IP if basic block did not work */
783 len = grab_bb(buffer, sample->ip, sample->ip,
784 machine, thread, &x.is64bit, &x.cpumode, false);
785 if (len <= 0)
786 return;
787
788 printf("\t%016" PRIx64 "\t%s\n", sample->ip,
789 dump_insn(&x, sample->ip, buffer, len, NULL));
790 return;
791 }
792 for (off = 0; off <= end - start; off += ilen) {
793 printf("\t%016" PRIx64 "\t%s\n", start + off,
794 dump_insn(&x, start + off, buffer + off, len - off, &ilen));
795 if (ilen == 0)
796 break;
797 }
798}
549 799
550static void print_sample_addr(struct perf_sample *sample, 800static void print_sample_addr(struct perf_sample *sample,
551 struct thread *thread, 801 struct thread *thread,
@@ -632,7 +882,9 @@ static void print_sample_callindent(struct perf_sample *sample,
632} 882}
633 883
634static void print_insn(struct perf_sample *sample, 884static void print_insn(struct perf_sample *sample,
635 struct perf_event_attr *attr) 885 struct perf_event_attr *attr,
886 struct thread *thread,
887 struct machine *machine)
636{ 888{
637 if (PRINT_FIELD(INSNLEN)) 889 if (PRINT_FIELD(INSNLEN))
638 printf(" ilen: %d", sample->insn_len); 890 printf(" ilen: %d", sample->insn_len);
@@ -643,12 +895,15 @@ static void print_insn(struct perf_sample *sample,
643 for (i = 0; i < sample->insn_len; i++) 895 for (i = 0; i < sample->insn_len; i++)
644 printf(" %02x", (unsigned char)sample->insn[i]); 896 printf(" %02x", (unsigned char)sample->insn[i]);
645 } 897 }
898 if (PRINT_FIELD(BRSTACKINSN))
899 print_sample_brstackinsn(sample, thread, attr, machine);
646} 900}
647 901
648static void print_sample_bts(struct perf_sample *sample, 902static void print_sample_bts(struct perf_sample *sample,
649 struct perf_evsel *evsel, 903 struct perf_evsel *evsel,
650 struct thread *thread, 904 struct thread *thread,
651 struct addr_location *al) 905 struct addr_location *al,
906 struct machine *machine)
652{ 907{
653 struct perf_event_attr *attr = &evsel->attr; 908 struct perf_event_attr *attr = &evsel->attr;
654 bool print_srcline_last = false; 909 bool print_srcline_last = false;
@@ -689,7 +944,7 @@ static void print_sample_bts(struct perf_sample *sample,
689 if (print_srcline_last) 944 if (print_srcline_last)
690 map__fprintf_srcline(al->map, al->addr, "\n ", stdout); 945 map__fprintf_srcline(al->map, al->addr, "\n ", stdout);
691 946
692 print_insn(sample, attr); 947 print_insn(sample, attr, thread, machine);
693 948
694 printf("\n"); 949 printf("\n");
695} 950}
@@ -830,6 +1085,7 @@ struct perf_script {
830 bool show_task_events; 1085 bool show_task_events;
831 bool show_mmap_events; 1086 bool show_mmap_events;
832 bool show_switch_events; 1087 bool show_switch_events;
1088 bool show_namespace_events;
833 bool allocated; 1089 bool allocated;
834 struct cpu_map *cpus; 1090 struct cpu_map *cpus;
835 struct thread_map *threads; 1091 struct thread_map *threads;
@@ -871,7 +1127,8 @@ static size_t data_src__printf(u64 data_src)
871 1127
872static void process_event(struct perf_script *script, 1128static void process_event(struct perf_script *script,
873 struct perf_sample *sample, struct perf_evsel *evsel, 1129 struct perf_sample *sample, struct perf_evsel *evsel,
874 struct addr_location *al) 1130 struct addr_location *al,
1131 struct machine *machine)
875{ 1132{
876 struct thread *thread = al->thread; 1133 struct thread *thread = al->thread;
877 struct perf_event_attr *attr = &evsel->attr; 1134 struct perf_event_attr *attr = &evsel->attr;
@@ -898,7 +1155,7 @@ static void process_event(struct perf_script *script,
898 print_sample_flags(sample->flags); 1155 print_sample_flags(sample->flags);
899 1156
900 if (is_bts_event(attr)) { 1157 if (is_bts_event(attr)) {
901 print_sample_bts(sample, evsel, thread, al); 1158 print_sample_bts(sample, evsel, thread, al, machine);
902 return; 1159 return;
903 } 1160 }
904 1161
@@ -936,7 +1193,7 @@ static void process_event(struct perf_script *script,
936 1193
937 if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT)) 1194 if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT))
938 print_sample_bpf_output(sample); 1195 print_sample_bpf_output(sample);
939 print_insn(sample, attr); 1196 print_insn(sample, attr, thread, machine);
940 printf("\n"); 1197 printf("\n");
941} 1198}
942 1199
@@ -1046,7 +1303,7 @@ static int process_sample_event(struct perf_tool *tool,
1046 if (scripting_ops) 1303 if (scripting_ops)
1047 scripting_ops->process_event(event, sample, evsel, &al); 1304 scripting_ops->process_event(event, sample, evsel, &al);
1048 else 1305 else
1049 process_event(scr, sample, evsel, &al); 1306 process_event(scr, sample, evsel, &al, machine);
1050 1307
1051out_put: 1308out_put:
1052 addr_location__put(&al); 1309 addr_location__put(&al);
@@ -1118,6 +1375,41 @@ out:
1118 return ret; 1375 return ret;
1119} 1376}
1120 1377
1378static int process_namespaces_event(struct perf_tool *tool,
1379 union perf_event *event,
1380 struct perf_sample *sample,
1381 struct machine *machine)
1382{
1383 struct thread *thread;
1384 struct perf_script *script = container_of(tool, struct perf_script, tool);
1385 struct perf_session *session = script->session;
1386 struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
1387 int ret = -1;
1388
1389 thread = machine__findnew_thread(machine, event->namespaces.pid,
1390 event->namespaces.tid);
1391 if (thread == NULL) {
1392 pr_debug("problem processing NAMESPACES event, skipping it.\n");
1393 return -1;
1394 }
1395
1396 if (perf_event__process_namespaces(tool, event, sample, machine) < 0)
1397 goto out;
1398
1399 if (!evsel->attr.sample_id_all) {
1400 sample->cpu = 0;
1401 sample->time = 0;
1402 sample->tid = event->namespaces.tid;
1403 sample->pid = event->namespaces.pid;
1404 }
1405 print_sample_start(sample, thread, evsel);
1406 perf_event__fprintf(event, stdout);
1407 ret = 0;
1408out:
1409 thread__put(thread);
1410 return ret;
1411}
1412
1121static int process_fork_event(struct perf_tool *tool, 1413static int process_fork_event(struct perf_tool *tool,
1122 union perf_event *event, 1414 union perf_event *event,
1123 struct perf_sample *sample, 1415 struct perf_sample *sample,
@@ -1293,6 +1585,8 @@ static int __cmd_script(struct perf_script *script)
1293 } 1585 }
1294 if (script->show_switch_events) 1586 if (script->show_switch_events)
1295 script->tool.context_switch = process_switch_event; 1587 script->tool.context_switch = process_switch_event;
1588 if (script->show_namespace_events)
1589 script->tool.namespaces = process_namespaces_event;
1296 1590
1297 ret = perf_session__process_events(script->session); 1591 ret = perf_session__process_events(script->session);
1298 1592
@@ -1427,7 +1721,7 @@ static int parse_scriptname(const struct option *opt __maybe_unused,
1427static int parse_output_fields(const struct option *opt __maybe_unused, 1721static int parse_output_fields(const struct option *opt __maybe_unused,
1428 const char *arg, int unset __maybe_unused) 1722 const char *arg, int unset __maybe_unused)
1429{ 1723{
1430 char *tok; 1724 char *tok, *strtok_saveptr = NULL;
1431 int i, imax = ARRAY_SIZE(all_output_options); 1725 int i, imax = ARRAY_SIZE(all_output_options);
1432 int j; 1726 int j;
1433 int rc = 0; 1727 int rc = 0;
@@ -1488,7 +1782,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
1488 } 1782 }
1489 } 1783 }
1490 1784
1491 for (tok = strtok(tok, ","); tok; tok = strtok(NULL, ",")) { 1785 for (tok = strtok_r(tok, ",", &strtok_saveptr); tok; tok = strtok_r(NULL, ",", &strtok_saveptr)) {
1492 for (i = 0; i < imax; ++i) { 1786 for (i = 0; i < imax; ++i) {
1493 if (strcmp(tok, all_output_options[i].str) == 0) 1787 if (strcmp(tok, all_output_options[i].str) == 0)
1494 break; 1788 break;
@@ -2078,7 +2372,7 @@ int process_cpu_map_event(struct perf_tool *tool __maybe_unused,
2078 return set_maps(script); 2372 return set_maps(script);
2079} 2373}
2080 2374
2081int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) 2375int cmd_script(int argc, const char **argv)
2082{ 2376{
2083 bool show_full_info = false; 2377 bool show_full_info = false;
2084 bool header = false; 2378 bool header = false;
@@ -2097,6 +2391,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
2097 .mmap = perf_event__process_mmap, 2391 .mmap = perf_event__process_mmap,
2098 .mmap2 = perf_event__process_mmap2, 2392 .mmap2 = perf_event__process_mmap2,
2099 .comm = perf_event__process_comm, 2393 .comm = perf_event__process_comm,
2394 .namespaces = perf_event__process_namespaces,
2100 .exit = perf_event__process_exit, 2395 .exit = perf_event__process_exit,
2101 .fork = perf_event__process_fork, 2396 .fork = perf_event__process_fork,
2102 .attr = process_attr, 2397 .attr = process_attr,
@@ -2152,7 +2447,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
2152 "Valid types: hw,sw,trace,raw. " 2447 "Valid types: hw,sw,trace,raw. "
2153 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," 2448 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
2154 "addr,symoff,period,iregs,brstack,brstacksym,flags," 2449 "addr,symoff,period,iregs,brstack,brstacksym,flags,"
2155 "bpf-output,callindent,insn,insnlen", parse_output_fields), 2450 "bpf-output,callindent,insn,insnlen,brstackinsn",
2451 parse_output_fields),
2156 OPT_BOOLEAN('a', "all-cpus", &system_wide, 2452 OPT_BOOLEAN('a', "all-cpus", &system_wide,
2157 "system-wide collection from all CPUs"), 2453 "system-wide collection from all CPUs"),
2158 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", 2454 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
@@ -2180,7 +2476,11 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
2180 "Show the mmap events"), 2476 "Show the mmap events"),
2181 OPT_BOOLEAN('\0', "show-switch-events", &script.show_switch_events, 2477 OPT_BOOLEAN('\0', "show-switch-events", &script.show_switch_events,
2182 "Show context switch events (if recorded)"), 2478 "Show context switch events (if recorded)"),
2479 OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events,
2480 "Show namespace events (if recorded)"),
2183 OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), 2481 OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
2482 OPT_INTEGER(0, "max-blocks", &max_blocks,
2483 "Maximum number of code blocks to dump with brstackinsn"),
2184 OPT_BOOLEAN(0, "ns", &nanosecs, 2484 OPT_BOOLEAN(0, "ns", &nanosecs,
2185 "Use 9 decimal places when displaying time"), 2485 "Use 9 decimal places when displaying time"),
2186 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts", 2486 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
@@ -2217,7 +2517,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
2217 if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) { 2517 if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) {
2218 rec_script_path = get_script_path(argv[1], RECORD_SUFFIX); 2518 rec_script_path = get_script_path(argv[1], RECORD_SUFFIX);
2219 if (!rec_script_path) 2519 if (!rec_script_path)
2220 return cmd_record(argc, argv, NULL); 2520 return cmd_record(argc, argv);
2221 } 2521 }
2222 2522
2223 if (argc > 1 && !strncmp(argv[0], "rep", strlen("rep"))) { 2523 if (argc > 1 && !strncmp(argv[0], "rep", strlen("rep"))) {
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 13b54999ad79..a935b5023732 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -64,14 +64,24 @@
64#include "util/session.h" 64#include "util/session.h"
65#include "util/tool.h" 65#include "util/tool.h"
66#include "util/group.h" 66#include "util/group.h"
67#include "util/string2.h"
67#include "asm/bug.h" 68#include "asm/bug.h"
68 69
69#include <linux/time64.h> 70#include <linux/time64.h>
70#include <api/fs/fs.h> 71#include <api/fs/fs.h>
72#include <errno.h>
73#include <signal.h>
71#include <stdlib.h> 74#include <stdlib.h>
72#include <sys/prctl.h> 75#include <sys/prctl.h>
76#include <inttypes.h>
73#include <locale.h> 77#include <locale.h>
74#include <math.h> 78#include <math.h>
79#include <sys/types.h>
80#include <sys/stat.h>
81#include <sys/wait.h>
82#include <unistd.h>
83
84#include "sane_ctype.h"
75 85
76#define DEFAULT_SEPARATOR " " 86#define DEFAULT_SEPARATOR " "
77#define CNTR_NOT_SUPPORTED "<not supported>" 87#define CNTR_NOT_SUPPORTED "<not supported>"
@@ -140,12 +150,14 @@ static unsigned int unit_width = 4; /* strlen("unit") */
140static bool forever = false; 150static bool forever = false;
141static bool metric_only = false; 151static bool metric_only = false;
142static bool force_metric_only = false; 152static bool force_metric_only = false;
153static bool no_merge = false;
143static struct timespec ref_time; 154static struct timespec ref_time;
144static struct cpu_map *aggr_map; 155static struct cpu_map *aggr_map;
145static aggr_get_id_t aggr_get_id; 156static aggr_get_id_t aggr_get_id;
146static bool append_file; 157static bool append_file;
147static const char *output_name; 158static const char *output_name;
148static int output_fd; 159static int output_fd;
160static int print_free_counters_hint;
149 161
150struct perf_stat { 162struct perf_stat {
151 bool record; 163 bool record;
@@ -310,8 +322,12 @@ static int read_counter(struct perf_evsel *counter)
310 struct perf_counts_values *count; 322 struct perf_counts_values *count;
311 323
312 count = perf_counts(counter->counts, cpu, thread); 324 count = perf_counts(counter->counts, cpu, thread);
313 if (perf_evsel__read(counter, cpu, thread, count)) 325 if (perf_evsel__read(counter, cpu, thread, count)) {
326 counter->counts->scaled = -1;
327 perf_counts(counter->counts, cpu, thread)->ena = 0;
328 perf_counts(counter->counts, cpu, thread)->run = 0;
314 return -1; 329 return -1;
330 }
315 331
316 if (STAT_RECORD) { 332 if (STAT_RECORD) {
317 if (perf_evsel__write_stat_event(counter, cpu, thread, count)) { 333 if (perf_evsel__write_stat_event(counter, cpu, thread, count)) {
@@ -336,12 +352,14 @@ static int read_counter(struct perf_evsel *counter)
336static void read_counters(void) 352static void read_counters(void)
337{ 353{
338 struct perf_evsel *counter; 354 struct perf_evsel *counter;
355 int ret;
339 356
340 evlist__for_each_entry(evsel_list, counter) { 357 evlist__for_each_entry(evsel_list, counter) {
341 if (read_counter(counter)) 358 ret = read_counter(counter);
359 if (ret)
342 pr_debug("failed to read counter %s\n", counter->name); 360 pr_debug("failed to read counter %s\n", counter->name);
343 361
344 if (perf_stat_process_counter(&stat_config, counter)) 362 if (ret == 0 && perf_stat_process_counter(&stat_config, counter))
345 pr_warning("failed to process counter %s\n", counter->name); 363 pr_warning("failed to process counter %s\n", counter->name);
346 } 364 }
347} 365}
@@ -873,10 +891,7 @@ static void print_metric_csv(void *ctx,
873 return; 891 return;
874 } 892 }
875 snprintf(buf, sizeof(buf), fmt, val); 893 snprintf(buf, sizeof(buf), fmt, val);
876 vals = buf; 894 ends = vals = ltrim(buf);
877 while (isspace(*vals))
878 vals++;
879 ends = vals;
880 while (isdigit(*ends) || *ends == '.') 895 while (isdigit(*ends) || *ends == '.')
881 ends++; 896 ends++;
882 *ends = 0; 897 *ends = 0;
@@ -948,10 +963,7 @@ static void print_metric_only_csv(void *ctx, const char *color __maybe_unused,
948 return; 963 return;
949 unit = fixunit(tbuf, os->evsel, unit); 964 unit = fixunit(tbuf, os->evsel, unit);
950 snprintf(buf, sizeof buf, fmt, val); 965 snprintf(buf, sizeof buf, fmt, val);
951 vals = buf; 966 ends = vals = ltrim(buf);
952 while (isspace(*vals))
953 vals++;
954 ends = vals;
955 while (isdigit(*ends) || *ends == '.') 967 while (isdigit(*ends) || *ends == '.')
956 ends++; 968 ends++;
957 *ends = 0; 969 *ends = 0;
@@ -1109,6 +1121,9 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,
1109 counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED, 1121 counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED,
1110 csv_sep); 1122 csv_sep);
1111 1123
1124 if (counter->supported)
1125 print_free_counters_hint = 1;
1126
1112 fprintf(stat_config.output, "%-*s%s", 1127 fprintf(stat_config.output, "%-*s%s",
1113 csv_output ? 0 : unit_width, 1128 csv_output ? 0 : unit_width,
1114 counter->unit, csv_sep); 1129 counter->unit, csv_sep);
@@ -1140,6 +1155,7 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,
1140 out.print_metric = pm; 1155 out.print_metric = pm;
1141 out.new_line = nl; 1156 out.new_line = nl;
1142 out.ctx = &os; 1157 out.ctx = &os;
1158 out.force_header = false;
1143 1159
1144 if (csv_output && !metric_only) { 1160 if (csv_output && !metric_only) {
1145 print_noise(counter, noise); 1161 print_noise(counter, noise);
@@ -1178,11 +1194,81 @@ static void aggr_update_shadow(void)
1178 } 1194 }
1179} 1195}
1180 1196
1197static void collect_all_aliases(struct perf_evsel *counter,
1198 void (*cb)(struct perf_evsel *counter, void *data,
1199 bool first),
1200 void *data)
1201{
1202 struct perf_evsel *alias;
1203
1204 alias = list_prepare_entry(counter, &(evsel_list->entries), node);
1205 list_for_each_entry_continue (alias, &evsel_list->entries, node) {
1206 if (strcmp(perf_evsel__name(alias), perf_evsel__name(counter)) ||
1207 alias->scale != counter->scale ||
1208 alias->cgrp != counter->cgrp ||
1209 strcmp(alias->unit, counter->unit) ||
1210 nsec_counter(alias) != nsec_counter(counter))
1211 break;
1212 alias->merged_stat = true;
1213 cb(alias, data, false);
1214 }
1215}
1216
1217static bool collect_data(struct perf_evsel *counter,
1218 void (*cb)(struct perf_evsel *counter, void *data,
1219 bool first),
1220 void *data)
1221{
1222 if (counter->merged_stat)
1223 return false;
1224 cb(counter, data, true);
1225 if (!no_merge)
1226 collect_all_aliases(counter, cb, data);
1227 return true;
1228}
1229
1230struct aggr_data {
1231 u64 ena, run, val;
1232 int id;
1233 int nr;
1234 int cpu;
1235};
1236
1237static void aggr_cb(struct perf_evsel *counter, void *data, bool first)
1238{
1239 struct aggr_data *ad = data;
1240 int cpu, s2;
1241
1242 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
1243 struct perf_counts_values *counts;
1244
1245 s2 = aggr_get_id(perf_evsel__cpus(counter), cpu);
1246 if (s2 != ad->id)
1247 continue;
1248 if (first)
1249 ad->nr++;
1250 counts = perf_counts(counter->counts, cpu, 0);
1251 /*
1252 * When any result is bad, make them all to give
1253 * consistent output in interval mode.
1254 */
1255 if (counts->ena == 0 || counts->run == 0 ||
1256 counter->counts->scaled == -1) {
1257 ad->ena = 0;
1258 ad->run = 0;
1259 break;
1260 }
1261 ad->val += counts->val;
1262 ad->ena += counts->ena;
1263 ad->run += counts->run;
1264 }
1265}
1266
1181static void print_aggr(char *prefix) 1267static void print_aggr(char *prefix)
1182{ 1268{
1183 FILE *output = stat_config.output; 1269 FILE *output = stat_config.output;
1184 struct perf_evsel *counter; 1270 struct perf_evsel *counter;
1185 int cpu, s, s2, id, nr; 1271 int s, id, nr;
1186 double uval; 1272 double uval;
1187 u64 ena, run, val; 1273 u64 ena, run, val;
1188 bool first; 1274 bool first;
@@ -1197,23 +1283,21 @@ static void print_aggr(char *prefix)
1197 * Without each counter has its own line. 1283 * Without each counter has its own line.
1198 */ 1284 */
1199 for (s = 0; s < aggr_map->nr; s++) { 1285 for (s = 0; s < aggr_map->nr; s++) {
1286 struct aggr_data ad;
1200 if (prefix && metric_only) 1287 if (prefix && metric_only)
1201 fprintf(output, "%s", prefix); 1288 fprintf(output, "%s", prefix);
1202 1289
1203 id = aggr_map->map[s]; 1290 ad.id = id = aggr_map->map[s];
1204 first = true; 1291 first = true;
1205 evlist__for_each_entry(evsel_list, counter) { 1292 evlist__for_each_entry(evsel_list, counter) {
1206 val = ena = run = 0; 1293 ad.val = ad.ena = ad.run = 0;
1207 nr = 0; 1294 ad.nr = 0;
1208 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) { 1295 if (!collect_data(counter, aggr_cb, &ad))
1209 s2 = aggr_get_id(perf_evsel__cpus(counter), cpu); 1296 continue;
1210 if (s2 != id) 1297 nr = ad.nr;
1211 continue; 1298 ena = ad.ena;
1212 val += perf_counts(counter->counts, cpu, 0)->val; 1299 run = ad.run;
1213 ena += perf_counts(counter->counts, cpu, 0)->ena; 1300 val = ad.val;
1214 run += perf_counts(counter->counts, cpu, 0)->run;
1215 nr++;
1216 }
1217 if (first && metric_only) { 1301 if (first && metric_only) {
1218 first = false; 1302 first = false;
1219 aggr_printout(counter, id, nr); 1303 aggr_printout(counter, id, nr);
@@ -1257,6 +1341,21 @@ static void print_aggr_thread(struct perf_evsel *counter, char *prefix)
1257 } 1341 }
1258} 1342}
1259 1343
1344struct caggr_data {
1345 double avg, avg_enabled, avg_running;
1346};
1347
1348static void counter_aggr_cb(struct perf_evsel *counter, void *data,
1349 bool first __maybe_unused)
1350{
1351 struct caggr_data *cd = data;
1352 struct perf_stat_evsel *ps = counter->priv;
1353
1354 cd->avg += avg_stats(&ps->res_stats[0]);
1355 cd->avg_enabled += avg_stats(&ps->res_stats[1]);
1356 cd->avg_running += avg_stats(&ps->res_stats[2]);
1357}
1358
1260/* 1359/*
1261 * Print out the results of a single counter: 1360 * Print out the results of a single counter:
1262 * aggregated counts in system-wide mode 1361 * aggregated counts in system-wide mode
@@ -1264,23 +1363,31 @@ static void print_aggr_thread(struct perf_evsel *counter, char *prefix)
1264static void print_counter_aggr(struct perf_evsel *counter, char *prefix) 1363static void print_counter_aggr(struct perf_evsel *counter, char *prefix)
1265{ 1364{
1266 FILE *output = stat_config.output; 1365 FILE *output = stat_config.output;
1267 struct perf_stat_evsel *ps = counter->priv;
1268 double avg = avg_stats(&ps->res_stats[0]);
1269 double uval; 1366 double uval;
1270 double avg_enabled, avg_running; 1367 struct caggr_data cd = { .avg = 0.0 };
1271 1368
1272 avg_enabled = avg_stats(&ps->res_stats[1]); 1369 if (!collect_data(counter, counter_aggr_cb, &cd))
1273 avg_running = avg_stats(&ps->res_stats[2]); 1370 return;
1274 1371
1275 if (prefix && !metric_only) 1372 if (prefix && !metric_only)
1276 fprintf(output, "%s", prefix); 1373 fprintf(output, "%s", prefix);
1277 1374
1278 uval = avg * counter->scale; 1375 uval = cd.avg * counter->scale;
1279 printout(-1, 0, counter, uval, prefix, avg_running, avg_enabled, avg); 1376 printout(-1, 0, counter, uval, prefix, cd.avg_running, cd.avg_enabled, cd.avg);
1280 if (!metric_only) 1377 if (!metric_only)
1281 fprintf(output, "\n"); 1378 fprintf(output, "\n");
1282} 1379}
1283 1380
1381static void counter_cb(struct perf_evsel *counter, void *data,
1382 bool first __maybe_unused)
1383{
1384 struct aggr_data *ad = data;
1385
1386 ad->val += perf_counts(counter->counts, ad->cpu, 0)->val;
1387 ad->ena += perf_counts(counter->counts, ad->cpu, 0)->ena;
1388 ad->run += perf_counts(counter->counts, ad->cpu, 0)->run;
1389}
1390
1284/* 1391/*
1285 * Print out the results of a single counter: 1392 * Print out the results of a single counter:
1286 * does not use aggregated count in system-wide 1393 * does not use aggregated count in system-wide
@@ -1293,9 +1400,13 @@ static void print_counter(struct perf_evsel *counter, char *prefix)
1293 int cpu; 1400 int cpu;
1294 1401
1295 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) { 1402 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
1296 val = perf_counts(counter->counts, cpu, 0)->val; 1403 struct aggr_data ad = { .cpu = cpu };
1297 ena = perf_counts(counter->counts, cpu, 0)->ena; 1404
1298 run = perf_counts(counter->counts, cpu, 0)->run; 1405 if (!collect_data(counter, counter_cb, &ad))
1406 return;
1407 val = ad.val;
1408 ena = ad.ena;
1409 run = ad.run;
1299 1410
1300 if (prefix) 1411 if (prefix)
1301 fprintf(output, "%s", prefix); 1412 fprintf(output, "%s", prefix);
@@ -1380,6 +1491,7 @@ static void print_metric_headers(const char *prefix, bool no_indent)
1380 out.ctx = &os; 1491 out.ctx = &os;
1381 out.print_metric = print_metric_header; 1492 out.print_metric = print_metric_header;
1382 out.new_line = new_line_metric; 1493 out.new_line = new_line_metric;
1494 out.force_header = true;
1383 os.evsel = counter; 1495 os.evsel = counter;
1384 perf_stat__print_shadow_stats(counter, 0, 1496 perf_stat__print_shadow_stats(counter, 0,
1385 0, 1497 0,
@@ -1477,6 +1589,13 @@ static void print_footer(void)
1477 avg_stats(&walltime_nsecs_stats)); 1589 avg_stats(&walltime_nsecs_stats));
1478 } 1590 }
1479 fprintf(output, "\n\n"); 1591 fprintf(output, "\n\n");
1592
1593 if (print_free_counters_hint)
1594 fprintf(output,
1595"Some events weren't counted. Try disabling the NMI watchdog:\n"
1596" echo 0 > /proc/sys/kernel/nmi_watchdog\n"
1597" perf stat ...\n"
1598" echo 1 > /proc/sys/kernel/nmi_watchdog\n");
1480} 1599}
1481 1600
1482static void print_counters(struct timespec *ts, int argc, const char **argv) 1601static void print_counters(struct timespec *ts, int argc, const char **argv)
@@ -1633,6 +1752,7 @@ static const struct option stat_options[] = {
1633 "list of cpus to monitor in system-wide"), 1752 "list of cpus to monitor in system-wide"),
1634 OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode, 1753 OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode,
1635 "disable CPU count aggregation", AGGR_NONE), 1754 "disable CPU count aggregation", AGGR_NONE),
1755 OPT_BOOLEAN(0, "no-merge", &no_merge, "Do not merge identical named events"),
1636 OPT_STRING('x', "field-separator", &csv_sep, "separator", 1756 OPT_STRING('x', "field-separator", &csv_sep, "separator",
1637 "print counts with custom separator"), 1757 "print counts with custom separator"),
1638 OPT_CALLBACK('G', "cgroup", &evsel_list, "name", 1758 OPT_CALLBACK('G', "cgroup", &evsel_list, "name",
@@ -2339,7 +2459,36 @@ static int __cmd_report(int argc, const char **argv)
2339 return 0; 2459 return 0;
2340} 2460}
2341 2461
2342int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) 2462static void setup_system_wide(int forks)
2463{
2464 /*
2465 * Make system wide (-a) the default target if
2466 * no target was specified and one of following
2467 * conditions is met:
2468 *
2469 * - there's no workload specified
2470 * - there is workload specified but all requested
2471 * events are system wide events
2472 */
2473 if (!target__none(&target))
2474 return;
2475
2476 if (!forks)
2477 target.system_wide = true;
2478 else {
2479 struct perf_evsel *counter;
2480
2481 evlist__for_each_entry(evsel_list, counter) {
2482 if (!counter->system_wide)
2483 return;
2484 }
2485
2486 if (evsel_list->nr_entries)
2487 target.system_wide = true;
2488 }
2489}
2490
2491int cmd_stat(int argc, const char **argv)
2343{ 2492{
2344 const char * const stat_usage[] = { 2493 const char * const stat_usage[] = {
2345 "perf stat [<options>] [<command>]", 2494 "perf stat [<options>] [<command>]",
@@ -2361,6 +2510,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
2361 argc = parse_options_subcommand(argc, argv, stat_options, stat_subcommands, 2510 argc = parse_options_subcommand(argc, argv, stat_options, stat_subcommands,
2362 (const char **) stat_usage, 2511 (const char **) stat_usage,
2363 PARSE_OPT_STOP_AT_NON_OPTION); 2512 PARSE_OPT_STOP_AT_NON_OPTION);
2513 perf_stat__collect_metric_expr(evsel_list);
2364 perf_stat__init_shadow_stats(); 2514 perf_stat__init_shadow_stats();
2365 2515
2366 if (csv_sep) { 2516 if (csv_sep) {
@@ -2445,9 +2595,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
2445 } else if (big_num_opt == 0) /* User passed --no-big-num */ 2595 } else if (big_num_opt == 0) /* User passed --no-big-num */
2446 big_num = false; 2596 big_num = false;
2447 2597
2448 /* Make system wide (-a) the default target. */ 2598 setup_system_wide(argc);
2449 if (!argc && target__none(&target))
2450 target.system_wide = true;
2451 2599
2452 if (run_count < 0) { 2600 if (run_count < 0) {
2453 pr_err("Run count must be a positive number\n"); 2601 pr_err("Run count must be a positive number\n");
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index e7eaa298d34a..4e2e61695986 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -12,6 +12,8 @@
12 * of the License. 12 * of the License.
13 */ 13 */
14 14
15#include <errno.h>
16#include <inttypes.h>
15#include <traceevent/event-parse.h> 17#include <traceevent/event-parse.h>
16 18
17#include "builtin.h" 19#include "builtin.h"
@@ -23,11 +25,12 @@
23#include "util/cache.h" 25#include "util/cache.h"
24#include "util/evlist.h" 26#include "util/evlist.h"
25#include "util/evsel.h" 27#include "util/evsel.h"
28#include <linux/kernel.h>
26#include <linux/rbtree.h> 29#include <linux/rbtree.h>
27#include <linux/time64.h> 30#include <linux/time64.h>
28#include "util/symbol.h" 31#include "util/symbol.h"
32#include "util/thread.h"
29#include "util/callchain.h" 33#include "util/callchain.h"
30#include "util/strlist.h"
31 34
32#include "perf.h" 35#include "perf.h"
33#include "util/header.h" 36#include "util/header.h"
@@ -1773,7 +1776,7 @@ static int timechart__io_record(int argc, const char **argv)
1773 for (i = 0; i < (unsigned int)argc; i++) 1776 for (i = 0; i < (unsigned int)argc; i++)
1774 *p++ = argv[i]; 1777 *p++ = argv[i];
1775 1778
1776 return cmd_record(rec_argc, rec_argv, NULL); 1779 return cmd_record(rec_argc, rec_argv);
1777} 1780}
1778 1781
1779 1782
@@ -1864,7 +1867,7 @@ static int timechart__record(struct timechart *tchart, int argc, const char **ar
1864 for (j = 0; j < (unsigned int)argc; j++) 1867 for (j = 0; j < (unsigned int)argc; j++)
1865 *p++ = argv[j]; 1868 *p++ = argv[j];
1866 1869
1867 return cmd_record(rec_argc, rec_argv, NULL); 1870 return cmd_record(rec_argc, rec_argv);
1868} 1871}
1869 1872
1870static int 1873static int
@@ -1917,8 +1920,7 @@ parse_time(const struct option *opt, const char *arg, int __maybe_unused unset)
1917 return 0; 1920 return 0;
1918} 1921}
1919 1922
1920int cmd_timechart(int argc, const char **argv, 1923int cmd_timechart(int argc, const char **argv)
1921 const char *prefix __maybe_unused)
1922{ 1924{
1923 struct timechart tchart = { 1925 struct timechart tchart = {
1924 .tool = { 1926 .tool = {
@@ -1933,6 +1935,11 @@ int cmd_timechart(int argc, const char **argv,
1933 .merge_dist = 1000, 1935 .merge_dist = 1000,
1934 }; 1936 };
1935 const char *output_name = "output.svg"; 1937 const char *output_name = "output.svg";
1938 const struct option timechart_common_options[] = {
1939 OPT_BOOLEAN('P', "power-only", &tchart.power_only, "output power data only"),
1940 OPT_BOOLEAN('T', "tasks-only", &tchart.tasks_only, "output processes data only"),
1941 OPT_END()
1942 };
1936 const struct option timechart_options[] = { 1943 const struct option timechart_options[] = {
1937 OPT_STRING('i', "input", &input_name, "file", "input file name"), 1944 OPT_STRING('i', "input", &input_name, "file", "input file name"),
1938 OPT_STRING('o', "output", &output_name, "file", "output file name"), 1945 OPT_STRING('o', "output", &output_name, "file", "output file name"),
@@ -1940,9 +1947,6 @@ int cmd_timechart(int argc, const char **argv,
1940 OPT_CALLBACK(0, "highlight", NULL, "duration or task name", 1947 OPT_CALLBACK(0, "highlight", NULL, "duration or task name",
1941 "highlight tasks. Pass duration in ns or process name.", 1948 "highlight tasks. Pass duration in ns or process name.",
1942 parse_highlight), 1949 parse_highlight),
1943 OPT_BOOLEAN('P', "power-only", &tchart.power_only, "output power data only"),
1944 OPT_BOOLEAN('T', "tasks-only", &tchart.tasks_only,
1945 "output processes data only"),
1946 OPT_CALLBACK('p', "process", NULL, "process", 1950 OPT_CALLBACK('p', "process", NULL, "process",
1947 "process selector. Pass a pid or process name.", 1951 "process selector. Pass a pid or process name.",
1948 parse_process), 1952 parse_process),
@@ -1962,22 +1966,18 @@ int cmd_timechart(int argc, const char **argv,
1962 "merge events that are merge-dist us apart", 1966 "merge events that are merge-dist us apart",
1963 parse_time), 1967 parse_time),
1964 OPT_BOOLEAN('f', "force", &tchart.force, "don't complain, do it"), 1968 OPT_BOOLEAN('f', "force", &tchart.force, "don't complain, do it"),
1965 OPT_END() 1969 OPT_PARENT(timechart_common_options),
1966 }; 1970 };
1967 const char * const timechart_subcommands[] = { "record", NULL }; 1971 const char * const timechart_subcommands[] = { "record", NULL };
1968 const char *timechart_usage[] = { 1972 const char *timechart_usage[] = {
1969 "perf timechart [<options>] {record}", 1973 "perf timechart [<options>] {record}",
1970 NULL 1974 NULL
1971 }; 1975 };
1972
1973 const struct option timechart_record_options[] = { 1976 const struct option timechart_record_options[] = {
1974 OPT_BOOLEAN('P', "power-only", &tchart.power_only, "output power data only"),
1975 OPT_BOOLEAN('T', "tasks-only", &tchart.tasks_only,
1976 "output processes data only"),
1977 OPT_BOOLEAN('I', "io-only", &tchart.io_only, 1977 OPT_BOOLEAN('I', "io-only", &tchart.io_only,
1978 "record only IO data"), 1978 "record only IO data"),
1979 OPT_BOOLEAN('g', "callchain", &tchart.with_backtrace, "record callchain"), 1979 OPT_BOOLEAN('g', "callchain", &tchart.with_backtrace, "record callchain"),
1980 OPT_END() 1980 OPT_PARENT(timechart_common_options),
1981 }; 1981 };
1982 const char * const timechart_record_usage[] = { 1982 const char * const timechart_record_usage[] = {
1983 "perf timechart record [<options>]", 1983 "perf timechart record [<options>]",
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index ab9077915763..7ab42b8311a1 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -40,6 +40,7 @@
40#include "util/cpumap.h" 40#include "util/cpumap.h"
41#include "util/xyarray.h" 41#include "util/xyarray.h"
42#include "util/sort.h" 42#include "util/sort.h"
43#include "util/term.h"
43#include "util/intlist.h" 44#include "util/intlist.h"
44#include "util/parse-branch-options.h" 45#include "util/parse-branch-options.h"
45#include "arch/common.h" 46#include "arch/common.h"
@@ -58,6 +59,7 @@
58#include <errno.h> 59#include <errno.h>
59#include <time.h> 60#include <time.h>
60#include <sched.h> 61#include <sched.h>
62#include <signal.h>
61 63
62#include <sys/syscall.h> 64#include <sys/syscall.h>
63#include <sys/ioctl.h> 65#include <sys/ioctl.h>
@@ -72,6 +74,8 @@
72#include <linux/time64.h> 74#include <linux/time64.h>
73#include <linux/types.h> 75#include <linux/types.h>
74 76
77#include "sane_ctype.h"
78
75static volatile int done; 79static volatile int done;
76 80
77#define HEADER_LINE_NR 5 81#define HEADER_LINE_NR 5
@@ -1075,7 +1079,7 @@ parse_percent_limit(const struct option *opt, const char *arg,
1075const char top_callchain_help[] = CALLCHAIN_RECORD_HELP CALLCHAIN_REPORT_HELP 1079const char top_callchain_help[] = CALLCHAIN_RECORD_HELP CALLCHAIN_REPORT_HELP
1076 "\n\t\t\t\tDefault: fp,graph,0.5,caller,function"; 1080 "\n\t\t\t\tDefault: fp,graph,0.5,caller,function";
1077 1081
1078int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) 1082int cmd_top(int argc, const char **argv)
1079{ 1083{
1080 char errbuf[BUFSIZ]; 1084 char errbuf[BUFSIZ];
1081 struct perf_top top = { 1085 struct perf_top top = {
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 256f1fac6f7e..eaa66fb57347 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -24,6 +24,7 @@
24#include "util/evlist.h" 24#include "util/evlist.h"
25#include <subcmd/exec-cmd.h> 25#include <subcmd/exec-cmd.h>
26#include "util/machine.h" 26#include "util/machine.h"
27#include "util/path.h"
27#include "util/session.h" 28#include "util/session.h"
28#include "util/thread.h" 29#include "util/thread.h"
29#include <subcmd/parse-options.h> 30#include <subcmd/parse-options.h>
@@ -31,23 +32,33 @@
31#include "util/intlist.h" 32#include "util/intlist.h"
32#include "util/thread_map.h" 33#include "util/thread_map.h"
33#include "util/stat.h" 34#include "util/stat.h"
35#include "trace/beauty/beauty.h"
34#include "trace-event.h" 36#include "trace-event.h"
35#include "util/parse-events.h" 37#include "util/parse-events.h"
36#include "util/bpf-loader.h" 38#include "util/bpf-loader.h"
37#include "callchain.h" 39#include "callchain.h"
40#include "print_binary.h"
41#include "string2.h"
38#include "syscalltbl.h" 42#include "syscalltbl.h"
39#include "rb_resort.h" 43#include "rb_resort.h"
40 44
45#include <errno.h>
46#include <inttypes.h>
41#include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */ 47#include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */
48#include <poll.h>
49#include <signal.h>
42#include <stdlib.h> 50#include <stdlib.h>
43#include <string.h> 51#include <string.h>
44#include <linux/err.h> 52#include <linux/err.h>
45#include <linux/filter.h> 53#include <linux/filter.h>
46#include <linux/audit.h> 54#include <linux/audit.h>
55#include <linux/kernel.h>
47#include <linux/random.h> 56#include <linux/random.h>
48#include <linux/stringify.h> 57#include <linux/stringify.h>
49#include <linux/time64.h> 58#include <linux/time64.h>
50 59
60#include "sane_ctype.h"
61
51#ifndef O_CLOEXEC 62#ifndef O_CLOEXEC
52# define O_CLOEXEC 02000000 63# define O_CLOEXEC 02000000
53#endif 64#endif
@@ -267,15 +278,6 @@ out_delete:
267 ({ struct syscall_tp *fields = evsel->priv; \ 278 ({ struct syscall_tp *fields = evsel->priv; \
268 fields->name.pointer(&fields->name, sample); }) 279 fields->name.pointer(&fields->name, sample); })
269 280
270struct syscall_arg {
271 unsigned long val;
272 struct thread *thread;
273 struct trace *trace;
274 void *parm;
275 u8 idx;
276 u8 mask;
277};
278
279struct strarray { 281struct strarray {
280 int offset; 282 int offset;
281 int nr_entries; 283 int nr_entries;
@@ -771,6 +773,10 @@ static struct syscall_fmt {
771 .arg_parm = { [0] = &strarray__socket_families, /* family */ }, }, 773 .arg_parm = { [0] = &strarray__socket_families, /* family */ }, },
772 { .name = "stat", .errmsg = true, .alias = "newstat", }, 774 { .name = "stat", .errmsg = true, .alias = "newstat", },
773 { .name = "statfs", .errmsg = true, }, 775 { .name = "statfs", .errmsg = true, },
776 { .name = "statx", .errmsg = true,
777 .arg_scnprintf = { [0] = SCA_FDAT, /* flags */
778 [2] = SCA_STATX_FLAGS, /* flags */
779 [3] = SCA_STATX_MASK, /* mask */ }, },
774 { .name = "swapoff", .errmsg = true, 780 { .name = "swapoff", .errmsg = true,
775 .arg_scnprintf = { [0] = SCA_FILENAME, /* specialfile */ }, }, 781 .arg_scnprintf = { [0] = SCA_FILENAME, /* specialfile */ }, },
776 { .name = "swapon", .errmsg = true, 782 { .name = "swapon", .errmsg = true,
@@ -821,12 +827,21 @@ struct syscall {
821 void **arg_parm; 827 void **arg_parm;
822}; 828};
823 829
824static size_t fprintf_duration(unsigned long t, FILE *fp) 830/*
831 * We need to have this 'calculated' boolean because in some cases we really
832 * don't know what is the duration of a syscall, for instance, when we start
833 * a session and some threads are waiting for a syscall to finish, say 'poll',
834 * in which case all we can do is to print "( ? ) for duration and for the
835 * start timestamp.
836 */
837static size_t fprintf_duration(unsigned long t, bool calculated, FILE *fp)
825{ 838{
826 double duration = (double)t / NSEC_PER_MSEC; 839 double duration = (double)t / NSEC_PER_MSEC;
827 size_t printed = fprintf(fp, "("); 840 size_t printed = fprintf(fp, "(");
828 841
829 if (duration >= 1.0) 842 if (!calculated)
843 printed += fprintf(fp, " ? ");
844 else if (duration >= 1.0)
830 printed += color_fprintf(fp, PERF_COLOR_RED, "%6.3f ms", duration); 845 printed += color_fprintf(fp, PERF_COLOR_RED, "%6.3f ms", duration);
831 else if (duration >= 0.01) 846 else if (duration >= 0.01)
832 printed += color_fprintf(fp, PERF_COLOR_YELLOW, "%6.3f ms", duration); 847 printed += color_fprintf(fp, PERF_COLOR_YELLOW, "%6.3f ms", duration);
@@ -1028,13 +1043,27 @@ static bool trace__filter_duration(struct trace *trace, double t)
1028 return t < (trace->duration_filter * NSEC_PER_MSEC); 1043 return t < (trace->duration_filter * NSEC_PER_MSEC);
1029} 1044}
1030 1045
1031static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) 1046static size_t __trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp)
1032{ 1047{
1033 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; 1048 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC;
1034 1049
1035 return fprintf(fp, "%10.3f ", ts); 1050 return fprintf(fp, "%10.3f ", ts);
1036} 1051}
1037 1052
1053/*
1054 * We're handling tstamp=0 as an undefined tstamp, i.e. like when we are
1055 * using ttrace->entry_time for a thread that receives a sys_exit without
1056 * first having received a sys_enter ("poll" issued before tracing session
1057 * starts, lost sys_enter exit due to ring buffer overflow).
1058 */
1059static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp)
1060{
1061 if (tstamp > 0)
1062 return __trace__fprintf_tstamp(trace, tstamp, fp);
1063
1064 return fprintf(fp, " ? ");
1065}
1066
1038static bool done = false; 1067static bool done = false;
1039static bool interrupted = false; 1068static bool interrupted = false;
1040 1069
@@ -1045,10 +1074,10 @@ static void sig_handler(int sig)
1045} 1074}
1046 1075
1047static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, 1076static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread,
1048 u64 duration, u64 tstamp, FILE *fp) 1077 u64 duration, bool duration_calculated, u64 tstamp, FILE *fp)
1049{ 1078{
1050 size_t printed = trace__fprintf_tstamp(trace, tstamp, fp); 1079 size_t printed = trace__fprintf_tstamp(trace, tstamp, fp);
1051 printed += fprintf_duration(duration, fp); 1080 printed += fprintf_duration(duration, duration_calculated, fp);
1052 1081
1053 if (trace->multiple_threads) { 1082 if (trace->multiple_threads) {
1054 if (trace->show_comm) 1083 if (trace->show_comm)
@@ -1450,7 +1479,7 @@ static int trace__printf_interrupted_entry(struct trace *trace, struct perf_samp
1450 1479
1451 duration = sample->time - ttrace->entry_time; 1480 duration = sample->time - ttrace->entry_time;
1452 1481
1453 printed = trace__fprintf_entry_head(trace, trace->current, duration, ttrace->entry_time, trace->output); 1482 printed = trace__fprintf_entry_head(trace, trace->current, duration, true, ttrace->entry_time, trace->output);
1454 printed += fprintf(trace->output, "%-70s) ...\n", ttrace->entry_str); 1483 printed += fprintf(trace->output, "%-70s) ...\n", ttrace->entry_str);
1455 ttrace->entry_pending = false; 1484 ttrace->entry_pending = false;
1456 1485
@@ -1497,7 +1526,7 @@ static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
1497 1526
1498 if (sc->is_exit) { 1527 if (sc->is_exit) {
1499 if (!(trace->duration_filter || trace->summary_only || trace->min_stack)) { 1528 if (!(trace->duration_filter || trace->summary_only || trace->min_stack)) {
1500 trace__fprintf_entry_head(trace, thread, 1, ttrace->entry_time, trace->output); 1529 trace__fprintf_entry_head(trace, thread, 0, false, ttrace->entry_time, trace->output);
1501 fprintf(trace->output, "%-70s)\n", ttrace->entry_str); 1530 fprintf(trace->output, "%-70s)\n", ttrace->entry_str);
1502 } 1531 }
1503 } else { 1532 } else {
@@ -1545,6 +1574,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
1545{ 1574{
1546 long ret; 1575 long ret;
1547 u64 duration = 0; 1576 u64 duration = 0;
1577 bool duration_calculated = false;
1548 struct thread *thread; 1578 struct thread *thread;
1549 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1, callchain_ret = 0; 1579 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1, callchain_ret = 0;
1550 struct syscall *sc = trace__syscall_info(trace, evsel, id); 1580 struct syscall *sc = trace__syscall_info(trace, evsel, id);
@@ -1573,6 +1603,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
1573 duration = sample->time - ttrace->entry_time; 1603 duration = sample->time - ttrace->entry_time;
1574 if (trace__filter_duration(trace, duration)) 1604 if (trace__filter_duration(trace, duration))
1575 goto out; 1605 goto out;
1606 duration_calculated = true;
1576 } else if (trace->duration_filter) 1607 } else if (trace->duration_filter)
1577 goto out; 1608 goto out;
1578 1609
@@ -1588,7 +1619,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
1588 if (trace->summary_only) 1619 if (trace->summary_only)
1589 goto out; 1620 goto out;
1590 1621
1591 trace__fprintf_entry_head(trace, thread, duration, ttrace->entry_time, trace->output); 1622 trace__fprintf_entry_head(trace, thread, duration, duration_calculated, ttrace->entry_time, trace->output);
1592 1623
1593 if (ttrace->entry_pending) { 1624 if (ttrace->entry_pending) {
1594 fprintf(trace->output, "%-70s", ttrace->entry_str); 1625 fprintf(trace->output, "%-70s", ttrace->entry_str);
@@ -1653,15 +1684,17 @@ static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel,
1653 1684
1654 ttrace = thread__priv(thread); 1685 ttrace = thread__priv(thread);
1655 if (!ttrace) 1686 if (!ttrace)
1656 goto out; 1687 goto out_put;
1657 1688
1658 filename_len = strlen(filename); 1689 filename_len = strlen(filename);
1690 if (filename_len == 0)
1691 goto out_put;
1659 1692
1660 if (ttrace->filename.namelen < filename_len) { 1693 if (ttrace->filename.namelen < filename_len) {
1661 char *f = realloc(ttrace->filename.name, filename_len + 1); 1694 char *f = realloc(ttrace->filename.name, filename_len + 1);
1662 1695
1663 if (f == NULL) 1696 if (f == NULL)
1664 goto out; 1697 goto out_put;
1665 1698
1666 ttrace->filename.namelen = filename_len; 1699 ttrace->filename.namelen = filename_len;
1667 ttrace->filename.name = f; 1700 ttrace->filename.name = f;
@@ -1671,12 +1704,12 @@ static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel,
1671 ttrace->filename.pending_open = true; 1704 ttrace->filename.pending_open = true;
1672 1705
1673 if (!ttrace->filename.ptr) 1706 if (!ttrace->filename.ptr)
1674 goto out; 1707 goto out_put;
1675 1708
1676 entry_str_len = strlen(ttrace->entry_str); 1709 entry_str_len = strlen(ttrace->entry_str);
1677 remaining_space = trace__entry_str_size - entry_str_len - 1; /* \0 */ 1710 remaining_space = trace__entry_str_size - entry_str_len - 1; /* \0 */
1678 if (remaining_space <= 0) 1711 if (remaining_space <= 0)
1679 goto out; 1712 goto out_put;
1680 1713
1681 if (filename_len > (size_t)remaining_space) { 1714 if (filename_len > (size_t)remaining_space) {
1682 filename += filename_len - remaining_space; 1715 filename += filename_len - remaining_space;
@@ -1690,6 +1723,8 @@ static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel,
1690 1723
1691 ttrace->filename.ptr = 0; 1724 ttrace->filename.ptr = 0;
1692 ttrace->filename.entry_str_pos = 0; 1725 ttrace->filename.entry_str_pos = 0;
1726out_put:
1727 thread__put(thread);
1693out: 1728out:
1694 return 0; 1729 return 0;
1695} 1730}
@@ -1710,6 +1745,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evs
1710 1745
1711 ttrace->runtime_ms += runtime_ms; 1746 ttrace->runtime_ms += runtime_ms;
1712 trace->runtime_ms += runtime_ms; 1747 trace->runtime_ms += runtime_ms;
1748out_put:
1713 thread__put(thread); 1749 thread__put(thread);
1714 return 0; 1750 return 0;
1715 1751
@@ -1720,8 +1756,7 @@ out_dump:
1720 (pid_t)perf_evsel__intval(evsel, sample, "pid"), 1756 (pid_t)perf_evsel__intval(evsel, sample, "pid"),
1721 runtime, 1757 runtime,
1722 perf_evsel__intval(evsel, sample, "vruntime")); 1758 perf_evsel__intval(evsel, sample, "vruntime"));
1723 thread__put(thread); 1759 goto out_put;
1724 return 0;
1725} 1760}
1726 1761
1727static void bpf_output__printer(enum binary_printer_ops op, 1762static void bpf_output__printer(enum binary_printer_ops op,
@@ -1851,7 +1886,7 @@ static int trace__pgfault(struct trace *trace,
1851 thread__find_addr_location(thread, sample->cpumode, MAP__FUNCTION, 1886 thread__find_addr_location(thread, sample->cpumode, MAP__FUNCTION,
1852 sample->ip, &al); 1887 sample->ip, &al);
1853 1888
1854 trace__fprintf_entry_head(trace, thread, 0, sample->time, trace->output); 1889 trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output);
1855 1890
1856 fprintf(trace->output, "%sfault [", 1891 fprintf(trace->output, "%sfault [",
1857 evsel->attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ ? 1892 evsel->attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ ?
@@ -1920,7 +1955,7 @@ static int trace__process_sample(struct perf_tool *tool,
1920 1955
1921 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); 1956 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
1922 if (thread && thread__is_filtered(thread)) 1957 if (thread && thread__is_filtered(thread))
1923 return 0; 1958 goto out;
1924 1959
1925 trace__set_base_time(trace, evsel, sample); 1960 trace__set_base_time(trace, evsel, sample);
1926 1961
@@ -1928,7 +1963,8 @@ static int trace__process_sample(struct perf_tool *tool,
1928 ++trace->nr_events; 1963 ++trace->nr_events;
1929 handler(trace, evsel, event, sample); 1964 handler(trace, evsel, event, sample);
1930 } 1965 }
1931 1966out:
1967 thread__put(thread);
1932 return err; 1968 return err;
1933} 1969}
1934 1970
@@ -1988,7 +2024,7 @@ static int trace__record(struct trace *trace, int argc, const char **argv)
1988 for (i = 0; i < (unsigned int)argc; i++) 2024 for (i = 0; i < (unsigned int)argc; i++)
1989 rec_argv[j++] = argv[i]; 2025 rec_argv[j++] = argv[i];
1990 2026
1991 return cmd_record(j, rec_argv, NULL); 2027 return cmd_record(j, rec_argv);
1992} 2028}
1993 2029
1994static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp); 2030static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);
@@ -2415,8 +2451,9 @@ static int trace__replay(struct trace *trace)
2415 trace->tool.exit = perf_event__process_exit; 2451 trace->tool.exit = perf_event__process_exit;
2416 trace->tool.fork = perf_event__process_fork; 2452 trace->tool.fork = perf_event__process_fork;
2417 trace->tool.attr = perf_event__process_attr; 2453 trace->tool.attr = perf_event__process_attr;
2418 trace->tool.tracing_data = perf_event__process_tracing_data; 2454 trace->tool.tracing_data = perf_event__process_tracing_data;
2419 trace->tool.build_id = perf_event__process_build_id; 2455 trace->tool.build_id = perf_event__process_build_id;
2456 trace->tool.namespaces = perf_event__process_namespaces;
2420 2457
2421 trace->tool.ordered_events = true; 2458 trace->tool.ordered_events = true;
2422 trace->tool.ordering_requires_timestamps = true; 2459 trace->tool.ordering_requires_timestamps = true;
@@ -2785,7 +2822,7 @@ out:
2785 return err; 2822 return err;
2786} 2823}
2787 2824
2788int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) 2825int cmd_trace(int argc, const char **argv)
2789{ 2826{
2790 const char *trace_usage[] = { 2827 const char *trace_usage[] = {
2791 "perf trace [<options>] [<command>]", 2828 "perf trace [<options>] [<command>]",
diff --git a/tools/perf/builtin-version.c b/tools/perf/builtin-version.c
index 9b10cda6b6dc..d25149456a2f 100644
--- a/tools/perf/builtin-version.c
+++ b/tools/perf/builtin-version.c
@@ -1,9 +1,9 @@
1#include "util/util.h"
2#include "builtin.h" 1#include "builtin.h"
3#include "perf.h" 2#include "perf.h"
3#include <linux/compiler.h>
4#include <stdio.h>
4 5
5int cmd_version(int argc __maybe_unused, const char **argv __maybe_unused, 6int cmd_version(int argc __maybe_unused, const char **argv __maybe_unused)
6 const char *prefix __maybe_unused)
7{ 7{
8 printf("perf version %s\n", perf_version_string); 8 printf("perf version %s\n", perf_version_string);
9 return 0; 9 return 0;
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index 036e1e35b1a8..d4d19fe3d050 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -2,46 +2,42 @@
2#define BUILTIN_H 2#define BUILTIN_H
3 3
4#include "util/util.h" 4#include "util/util.h"
5#include "util/strbuf.h"
6 5
7extern const char perf_usage_string[]; 6extern const char perf_usage_string[];
8extern const char perf_more_info_string[]; 7extern const char perf_more_info_string[];
9 8
10void list_common_cmds_help(void); 9void list_common_cmds_help(void);
11const char *help_unknown_cmd(const char *cmd); 10const char *help_unknown_cmd(const char *cmd);
12void prune_packed_objects(int);
13int read_line_with_nul(char *buf, int size, FILE *file);
14int check_pager_config(const char *cmd);
15 11
16int cmd_annotate(int argc, const char **argv, const char *prefix); 12int cmd_annotate(int argc, const char **argv);
17int cmd_bench(int argc, const char **argv, const char *prefix); 13int cmd_bench(int argc, const char **argv);
18int cmd_buildid_cache(int argc, const char **argv, const char *prefix); 14int cmd_buildid_cache(int argc, const char **argv);
19int cmd_buildid_list(int argc, const char **argv, const char *prefix); 15int cmd_buildid_list(int argc, const char **argv);
20int cmd_config(int argc, const char **argv, const char *prefix); 16int cmd_config(int argc, const char **argv);
21int cmd_c2c(int argc, const char **argv, const char *prefix); 17int cmd_c2c(int argc, const char **argv);
22int cmd_diff(int argc, const char **argv, const char *prefix); 18int cmd_diff(int argc, const char **argv);
23int cmd_evlist(int argc, const char **argv, const char *prefix); 19int cmd_evlist(int argc, const char **argv);
24int cmd_help(int argc, const char **argv, const char *prefix); 20int cmd_help(int argc, const char **argv);
25int cmd_sched(int argc, const char **argv, const char *prefix); 21int cmd_sched(int argc, const char **argv);
26int cmd_kallsyms(int argc, const char **argv, const char *prefix); 22int cmd_kallsyms(int argc, const char **argv);
27int cmd_list(int argc, const char **argv, const char *prefix); 23int cmd_list(int argc, const char **argv);
28int cmd_record(int argc, const char **argv, const char *prefix); 24int cmd_record(int argc, const char **argv);
29int cmd_report(int argc, const char **argv, const char *prefix); 25int cmd_report(int argc, const char **argv);
30int cmd_stat(int argc, const char **argv, const char *prefix); 26int cmd_stat(int argc, const char **argv);
31int cmd_timechart(int argc, const char **argv, const char *prefix); 27int cmd_timechart(int argc, const char **argv);
32int cmd_top(int argc, const char **argv, const char *prefix); 28int cmd_top(int argc, const char **argv);
33int cmd_script(int argc, const char **argv, const char *prefix); 29int cmd_script(int argc, const char **argv);
34int cmd_version(int argc, const char **argv, const char *prefix); 30int cmd_version(int argc, const char **argv);
35int cmd_probe(int argc, const char **argv, const char *prefix); 31int cmd_probe(int argc, const char **argv);
36int cmd_kmem(int argc, const char **argv, const char *prefix); 32int cmd_kmem(int argc, const char **argv);
37int cmd_lock(int argc, const char **argv, const char *prefix); 33int cmd_lock(int argc, const char **argv);
38int cmd_kvm(int argc, const char **argv, const char *prefix); 34int cmd_kvm(int argc, const char **argv);
39int cmd_test(int argc, const char **argv, const char *prefix); 35int cmd_test(int argc, const char **argv);
40int cmd_trace(int argc, const char **argv, const char *prefix); 36int cmd_trace(int argc, const char **argv);
41int cmd_inject(int argc, const char **argv, const char *prefix); 37int cmd_inject(int argc, const char **argv);
42int cmd_mem(int argc, const char **argv, const char *prefix); 38int cmd_mem(int argc, const char **argv);
43int cmd_data(int argc, const char **argv, const char *prefix); 39int cmd_data(int argc, const char **argv);
44int cmd_ftrace(int argc, const char **argv, const char *prefix); 40int cmd_ftrace(int argc, const char **argv);
45 41
46int find_scripts(char **scripts_array, char **scripts_path_array); 42int find_scripts(char **scripts_array, char **scripts_path_array);
47#endif 43#endif
diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index c747bfd7f14d..83fe2202382e 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -1,7 +1,9 @@
1#!/bin/sh 1#!/bin/sh
2 2
3HEADERS=' 3HEADERS='
4include/uapi/linux/fcntl.h
4include/uapi/linux/perf_event.h 5include/uapi/linux/perf_event.h
6include/uapi/linux/stat.h
5include/linux/hash.h 7include/linux/hash.h
6include/uapi/linux/hw_breakpoint.h 8include/uapi/linux/hw_breakpoint.h
7arch/x86/include/asm/disabled-features.h 9arch/x86/include/asm/disabled-features.h
diff --git a/tools/perf/command-list.txt b/tools/perf/command-list.txt
index ac3efd396a72..2d0caf20ff3a 100644
--- a/tools/perf/command-list.txt
+++ b/tools/perf/command-list.txt
@@ -9,6 +9,7 @@ perf-buildid-cache mainporcelain common
9perf-buildid-list mainporcelain common 9perf-buildid-list mainporcelain common
10perf-data mainporcelain common 10perf-data mainporcelain common
11perf-diff mainporcelain common 11perf-diff mainporcelain common
12perf-c2c mainporcelain common
12perf-config mainporcelain common 13perf-config mainporcelain common
13perf-evlist mainporcelain common 14perf-evlist mainporcelain common
14perf-ftrace mainporcelain common 15perf-ftrace mainporcelain common
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 6d5479e03e0d..4cc6960f6226 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -19,9 +19,15 @@
19#include "util/debug.h" 19#include "util/debug.h"
20#include <api/fs/fs.h> 20#include <api/fs/fs.h>
21#include <api/fs/tracing_path.h> 21#include <api/fs/tracing_path.h>
22#include <errno.h>
22#include <pthread.h> 23#include <pthread.h>
24#include <signal.h>
23#include <stdlib.h> 25#include <stdlib.h>
24#include <time.h> 26#include <time.h>
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <unistd.h>
30#include <linux/kernel.h>
25 31
26const char perf_usage_string[] = 32const char perf_usage_string[] =
27 "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]"; 33 "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
@@ -34,7 +40,7 @@ const char *input_name;
34 40
35struct cmd_struct { 41struct cmd_struct {
36 const char *cmd; 42 const char *cmd;
37 int (*fn)(int, const char **, const char *); 43 int (*fn)(int, const char **);
38 int option; 44 int option;
39}; 45};
40 46
@@ -88,7 +94,7 @@ static int pager_command_config(const char *var, const char *value, void *data)
88} 94}
89 95
90/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */ 96/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
91int check_pager_config(const char *cmd) 97static int check_pager_config(const char *cmd)
92{ 98{
93 int err; 99 int err;
94 struct pager_config c; 100 struct pager_config c;
@@ -267,71 +273,6 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
267 return handled; 273 return handled;
268} 274}
269 275
270static int handle_alias(int *argcp, const char ***argv)
271{
272 int envchanged = 0, ret = 0, saved_errno = errno;
273 int count, option_count;
274 const char **new_argv;
275 const char *alias_command;
276 char *alias_string;
277
278 alias_command = (*argv)[0];
279 alias_string = alias_lookup(alias_command);
280 if (alias_string) {
281 if (alias_string[0] == '!') {
282 if (*argcp > 1) {
283 struct strbuf buf;
284
285 if (strbuf_init(&buf, PATH_MAX) < 0 ||
286 strbuf_addstr(&buf, alias_string) < 0 ||
287 sq_quote_argv(&buf, (*argv) + 1,
288 PATH_MAX) < 0)
289 die("Failed to allocate memory.");
290 free(alias_string);
291 alias_string = buf.buf;
292 }
293 ret = system(alias_string + 1);
294 if (ret >= 0 && WIFEXITED(ret) &&
295 WEXITSTATUS(ret) != 127)
296 exit(WEXITSTATUS(ret));
297 die("Failed to run '%s' when expanding alias '%s'",
298 alias_string + 1, alias_command);
299 }
300 count = split_cmdline(alias_string, &new_argv);
301 if (count < 0)
302 die("Bad alias.%s string", alias_command);
303 option_count = handle_options(&new_argv, &count, &envchanged);
304 if (envchanged)
305 die("alias '%s' changes environment variables\n"
306 "You can use '!perf' in the alias to do this.",
307 alias_command);
308 memmove(new_argv - option_count, new_argv,
309 count * sizeof(char *));
310 new_argv -= option_count;
311
312 if (count < 1)
313 die("empty alias for %s", alias_command);
314
315 if (!strcmp(alias_command, new_argv[0]))
316 die("recursive alias: %s", alias_command);
317
318 new_argv = realloc(new_argv, sizeof(char *) *
319 (count + *argcp + 1));
320 /* insert after command name */
321 memcpy(new_argv + count, *argv + 1, sizeof(char *) * *argcp);
322 new_argv[count + *argcp] = NULL;
323
324 *argv = new_argv;
325 *argcp += count - 1;
326
327 ret = 1;
328 }
329
330 errno = saved_errno;
331
332 return ret;
333}
334
335#define RUN_SETUP (1<<0) 276#define RUN_SETUP (1<<0)
336#define USE_PAGER (1<<1) 277#define USE_PAGER (1<<1)
337 278
@@ -339,13 +280,8 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
339{ 280{
340 int status; 281 int status;
341 struct stat st; 282 struct stat st;
342 const char *prefix;
343 char sbuf[STRERR_BUFSIZE]; 283 char sbuf[STRERR_BUFSIZE];
344 284
345 prefix = NULL;
346 if (p->option & RUN_SETUP)
347 prefix = NULL; /* setup_perf_directory(); */
348
349 if (use_browser == -1) 285 if (use_browser == -1)
350 use_browser = check_browser_config(p->cmd); 286 use_browser = check_browser_config(p->cmd);
351 287
@@ -356,7 +292,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
356 commit_pager_choice(); 292 commit_pager_choice();
357 293
358 perf_env__set_cmdline(&perf_env, argc, argv); 294 perf_env__set_cmdline(&perf_env, argc, argv);
359 status = p->fn(argc, argv, prefix); 295 status = p->fn(argc, argv);
360 perf_config__exit(); 296 perf_config__exit();
361 exit_browser(status); 297 exit_browser(status);
362 perf_env__exit(&perf_env); 298 perf_env__exit(&perf_env);
@@ -397,16 +333,6 @@ static void handle_internal_command(int argc, const char **argv)
397{ 333{
398 const char *cmd = argv[0]; 334 const char *cmd = argv[0];
399 unsigned int i; 335 unsigned int i;
400 static const char ext[] = STRIP_EXTENSION;
401
402 if (sizeof(ext) > 1) {
403 i = strlen(argv[0]) - strlen(ext);
404 if (i > 0 && !strcmp(argv[0] + i, ext)) {
405 char *argv0 = strdup(argv[0]);
406 argv[0] = cmd = argv0;
407 argv0[i] = '\0';
408 }
409 }
410 336
411 /* Turn "perf cmd --help" into "perf help cmd" */ 337 /* Turn "perf cmd --help" into "perf help cmd" */
412 if (argc > 1 && !strcmp(argv[1], "--help")) { 338 if (argc > 1 && !strcmp(argv[1], "--help")) {
@@ -448,7 +374,8 @@ static void execv_dashed_external(const char **argv)
448 if (status != -ERR_RUN_COMMAND_EXEC) { 374 if (status != -ERR_RUN_COMMAND_EXEC) {
449 if (IS_RUN_COMMAND_ERR(status)) { 375 if (IS_RUN_COMMAND_ERR(status)) {
450do_die: 376do_die:
451 die("unable to run '%s'", argv[0]); 377 pr_err("FATAL: unable to run '%s'", argv[0]);
378 status = -128;
452 } 379 }
453 exit(-status); 380 exit(-status);
454 } 381 }
@@ -460,25 +387,12 @@ do_die:
460 387
461static int run_argv(int *argcp, const char ***argv) 388static int run_argv(int *argcp, const char ***argv)
462{ 389{
463 int done_alias = 0; 390 /* See if it's an internal command */
391 handle_internal_command(*argcp, *argv);
464 392
465 while (1) { 393 /* .. then try the external ones */
466 /* See if it's an internal command */ 394 execv_dashed_external(*argv);
467 handle_internal_command(*argcp, *argv); 395 return 0;
468
469 /* .. then try the external ones */
470 execv_dashed_external(*argv);
471
472 /* It could be an alias -- this works around the insanity
473 * of overriding "perf log" with "perf show" by having
474 * alias.log = show
475 */
476 if (done_alias || !handle_alias(argcp, argv))
477 break;
478 done_alias = 1;
479 }
480
481 return done_alias;
482} 396}
483 397
484static void pthread__block_sigwinch(void) 398static void pthread__block_sigwinch(void)
@@ -566,7 +480,7 @@ int main(int argc, const char **argv)
566#ifdef HAVE_LIBAUDIT_SUPPORT 480#ifdef HAVE_LIBAUDIT_SUPPORT
567 setup_path(); 481 setup_path();
568 argv[0] = "trace"; 482 argv[0] = "trace";
569 return cmd_trace(argc, argv, NULL); 483 return cmd_trace(argc, argv);
570#else 484#else
571 fprintf(stderr, 485 fprintf(stderr,
572 "trace command not available: missing audit-libs devel package at build time.\n"); 486 "trace command not available: missing audit-libs devel package at build time.\n");
@@ -611,17 +525,12 @@ int main(int argc, const char **argv)
611 525
612 while (1) { 526 while (1) {
613 static int done_help; 527 static int done_help;
614 int was_alias = run_argv(&argc, &argv); 528
529 run_argv(&argc, &argv);
615 530
616 if (errno != ENOENT) 531 if (errno != ENOENT)
617 break; 532 break;
618 533
619 if (was_alias) {
620 fprintf(stderr, "Expansion of alias '%s' failed; "
621 "'%s' is not a perf-command\n",
622 cmd, argv[0]);
623 goto out;
624 }
625 if (!done_help) { 534 if (!done_help) {
626 cmd = argv[0] = help_unknown_cmd(cmd); 535 cmd = argv[0] = help_unknown_cmd(cmd);
627 done_help = 1; 536 done_help = 1;
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 1c27d947c2fe..806c216a1078 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -50,6 +50,7 @@ struct record_opts {
50 bool running_time; 50 bool running_time;
51 bool full_auxtrace; 51 bool full_auxtrace;
52 bool auxtrace_snapshot_mode; 52 bool auxtrace_snapshot_mode;
53 bool record_namespaces;
53 bool record_switch_events; 54 bool record_switch_events;
54 bool all_kernel; 55 bool all_kernel;
55 bool all_user; 56 bool all_user;
diff --git a/tools/perf/pmu-events/arch/x86/broadwell/uncore.json b/tools/perf/pmu-events/arch/x86/broadwell/uncore.json
new file mode 100644
index 000000000000..28e1e159a3cb
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/broadwell/uncore.json
@@ -0,0 +1,278 @@
1[
2 {
3 "Unit": "CBO",
4 "EventCode": "0x22",
5 "UMask": "0x41",
6 "EventName": "UNC_CBO_XSNP_RESPONSE.MISS_XCORE",
7 "BriefDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which misses in some processor core.",
8 "PublicDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which misses in some processor core.",
9 "Counter": "0,1",
10 "CounterMask": "0",
11 "Invert": "0",
12 "EdgeDetect": "0"
13 },
14 {
15 "Unit": "CBO",
16 "EventCode": "0x22",
17 "UMask": "0x81",
18 "EventName": "UNC_CBO_XSNP_RESPONSE.MISS_EVICTION",
19 "BriefDescription": "A cross-core snoop resulted from L3 Eviction which misses in some processor core.",
20 "PublicDescription": "A cross-core snoop resulted from L3 Eviction which misses in some processor core.",
21 "Counter": "0,1",
22 "CounterMask": "0",
23 "Invert": "0",
24 "EdgeDetect": "0"
25 },
26 {
27 "Unit": "CBO",
28 "EventCode": "0x22",
29 "UMask": "0x44",
30 "EventName": "UNC_CBO_XSNP_RESPONSE.HIT_XCORE",
31 "BriefDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which hits a non-modified line in some processor core.",
32 "PublicDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which hits a non-modified line in some processor core.",
33 "Counter": "0,1",
34 "CounterMask": "0",
35 "Invert": "0",
36 "EdgeDetect": "0"
37 },
38 {
39 "Unit": "CBO",
40 "EventCode": "0x22",
41 "UMask": "0x48",
42 "EventName": "UNC_CBO_XSNP_RESPONSE.HITM_XCORE",
43 "BriefDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which hits a modified line in some processor core.",
44 "PublicDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which hits a modified line in some processor core.",
45 "Counter": "0,1",
46 "CounterMask": "0",
47 "Invert": "0",
48 "EdgeDetect": "0"
49 },
50 {
51 "Unit": "CBO",
52 "EventCode": "0x34",
53 "UMask": "0x11",
54 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_M",
55 "BriefDescription": "L3 Lookup read request that access cache and found line in M-state",
56 "PublicDescription": "L3 Lookup read request that access cache and found line in M-state.",
57 "Counter": "0,1",
58 "CounterMask": "0",
59 "Invert": "0",
60 "EdgeDetect": "0"
61 },
62 {
63 "Unit": "CBO",
64 "EventCode": "0x34",
65 "UMask": "0x21",
66 "EventName": "UNC_CBO_CACHE_LOOKUP.WRITE_M",
67 "BriefDescription": "L3 Lookup write request that access cache and found line in M-state",
68 "PublicDescription": "L3 Lookup write request that access cache and found line in M-state.",
69 "Counter": "0,1",
70 "CounterMask": "0",
71 "Invert": "0",
72 "EdgeDetect": "0"
73 },
74 {
75 "Unit": "CBO",
76 "EventCode": "0x34",
77 "UMask": "0x81",
78 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_M",
79 "BriefDescription": "L3 Lookup any request that access cache and found line in M-state",
80 "PublicDescription": "L3 Lookup any request that access cache and found line in M-state.",
81 "Counter": "0,1",
82 "CounterMask": "0",
83 "Invert": "0",
84 "EdgeDetect": "0"
85 },
86 {
87 "Unit": "CBO",
88 "EventCode": "0x34",
89 "UMask": "0x18",
90 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_I",
91 "BriefDescription": "L3 Lookup read request that access cache and found line in I-state",
92 "PublicDescription": "L3 Lookup read request that access cache and found line in I-state.",
93 "Counter": "0,1",
94 "CounterMask": "0",
95 "Invert": "0",
96 "EdgeDetect": "0"
97 },
98 {
99 "Unit": "CBO",
100 "EventCode": "0x34",
101 "UMask": "0x88",
102 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_I",
103 "BriefDescription": "L3 Lookup any request that access cache and found line in I-state",
104 "PublicDescription": "L3 Lookup any request that access cache and found line in I-state.",
105 "Counter": "0,1",
106 "CounterMask": "0",
107 "Invert": "0",
108 "EdgeDetect": "0"
109 },
110 {
111 "Unit": "CBO",
112 "EventCode": "0x34",
113 "UMask": "0x1f",
114 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_MESI",
115 "BriefDescription": "L3 Lookup read request that access cache and found line in any MESI-state",
116 "PublicDescription": "L3 Lookup read request that access cache and found line in any MESI-state.",
117 "Counter": "0,1",
118 "CounterMask": "0",
119 "Invert": "0",
120 "EdgeDetect": "0"
121 },
122 {
123 "Unit": "CBO",
124 "EventCode": "0x34",
125 "UMask": "0x2f",
126 "EventName": "UNC_CBO_CACHE_LOOKUP.WRITE_MESI",
127 "BriefDescription": "L3 Lookup write request that access cache and found line in MESI-state",
128 "PublicDescription": "L3 Lookup write request that access cache and found line in MESI-state.",
129 "Counter": "0,1",
130 "CounterMask": "0",
131 "Invert": "0",
132 "EdgeDetect": "0"
133 },
134 {
135 "Unit": "CBO",
136 "EventCode": "0x34",
137 "UMask": "0x8f",
138 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_MESI",
139 "BriefDescription": "L3 Lookup any request that access cache and found line in MESI-state",
140 "PublicDescription": "L3 Lookup any request that access cache and found line in MESI-state.",
141 "Counter": "0,1",
142 "CounterMask": "0",
143 "Invert": "0",
144 "EdgeDetect": "0"
145 },
146 {
147 "Unit": "CBO",
148 "EventCode": "0x34",
149 "UMask": "0x86",
150 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_ES",
151 "BriefDescription": "L3 Lookup any request that access cache and found line in E or S-state",
152 "PublicDescription": "L3 Lookup any request that access cache and found line in E or S-state.",
153 "Counter": "0,1",
154 "CounterMask": "0",
155 "Invert": "0",
156 "EdgeDetect": "0"
157 },
158 {
159 "Unit": "CBO",
160 "EventCode": "0x34",
161 "UMask": "0x16",
162 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_ES",
163 "BriefDescription": "L3 Lookup read request that access cache and found line in E or S-state",
164 "PublicDescription": "L3 Lookup read request that access cache and found line in E or S-state.",
165 "Counter": "0,1",
166 "CounterMask": "0",
167 "Invert": "0",
168 "EdgeDetect": "0"
169 },
170 {
171 "Unit": "CBO",
172 "EventCode": "0x34",
173 "UMask": "0x26",
174 "EventName": "UNC_CBO_CACHE_LOOKUP.WRITE_ES",
175 "BriefDescription": "L3 Lookup write request that access cache and found line in E or S-state",
176 "PublicDescription": "L3 Lookup write request that access cache and found line in E or S-state.",
177 "Counter": "0,1",
178 "CounterMask": "0",
179 "Invert": "0",
180 "EdgeDetect": "0"
181 },
182 {
183 "Unit": "iMPH-U",
184 "EventCode": "0x80",
185 "UMask": "0x01",
186 "EventName": "UNC_ARB_TRK_OCCUPANCY.ALL",
187 "BriefDescription": "Each cycle count number of all Core outgoing valid entries. Such entry is defined as valid from it's allocation till first of IDI0 or DRS0 messages is sent out. Accounts for Coherent and non-coherent traffic.",
188 "PublicDescription": "Each cycle count number of all Core outgoing valid entries. Such entry is defined as valid from it's allocation till first of IDI0 or DRS0 messages is sent out. Accounts for Coherent and non-coherent traffic.",
189 "Counter": "0,",
190 "CounterMask": "0",
191 "Invert": "0",
192 "EdgeDetect": "0"
193 },
194 {
195 "Unit": "iMPH-U",
196 "EventCode": "0x80",
197 "UMask": "0x02",
198 "EventName": "UNC_ARB_TRK_OCCUPANCY.DRD_DIRECT",
199 "BriefDescription": "Each cycle count number of 'valid' coherent Data Read entries that are in DirectData mode. Such entry is defined as valid when it is allocated till data sent to Core (first chunk, IDI0). Applicable for IA Cores' requests in normal case.",
200 "PublicDescription": "Each cycle count number of 'valid' coherent Data Read entries that are in DirectData mode. Such entry is defined as valid when it is allocated till data sent to Core (first chunk, IDI0). Applicable for IA Cores' requests in normal case.",
201 "Counter": "0,",
202 "CounterMask": "0",
203 "Invert": "0",
204 "EdgeDetect": "0"
205 },
206 {
207 "Unit": "iMPH-U",
208 "EventCode": "0x81",
209 "UMask": "0x01",
210 "EventName": "UNC_ARB_TRK_REQUESTS.ALL",
211 "BriefDescription": "Total number of Core outgoing entries allocated. Accounts for Coherent and non-coherent traffic.",
212 "PublicDescription": "Total number of Core outgoing entries allocated. Accounts for Coherent and non-coherent traffic.",
213 "Counter": "0,1",
214 "CounterMask": "0",
215 "Invert": "0",
216 "EdgeDetect": "0"
217 },
218 {
219 "Unit": "iMPH-U",
220 "EventCode": "0x81",
221 "UMask": "0x02",
222 "EventName": "UNC_ARB_TRK_REQUESTS.DRD_DIRECT",
223 "BriefDescription": "Number of Core coherent Data Read entries allocated in DirectData mode",
224 "PublicDescription": "Number of Core coherent Data Read entries allocated in DirectData mode.",
225 "Counter": "0,1",
226 "CounterMask": "0",
227 "Invert": "0",
228 "EdgeDetect": "0"
229 },
230 {
231 "Unit": "iMPH-U",
232 "EventCode": "0x81",
233 "UMask": "0x20",
234 "EventName": "UNC_ARB_TRK_REQUESTS.WRITES",
235 "BriefDescription": "Number of Writes allocated - any write transactions: full/partials writes and evictions.",
236 "PublicDescription": "Number of Writes allocated - any write transactions: full/partials writes and evictions.",
237 "Counter": "0,1",
238 "CounterMask": "0",
239 "Invert": "0",
240 "EdgeDetect": "0"
241 },
242 {
243 "Unit": "iMPH-U",
244 "EventCode": "0x84",
245 "UMask": "0x01",
246 "EventName": "UNC_ARB_COH_TRK_REQUESTS.ALL",
247 "BriefDescription": "Number of entries allocated. Account for Any type: e.g. Snoop, Core aperture, etc.",
248 "PublicDescription": "Number of entries allocated. Account for Any type: e.g. Snoop, Core aperture, etc.",
249 "Counter": "0,1",
250 "CounterMask": "0",
251 "Invert": "0",
252 "EdgeDetect": "0"
253 },
254 {
255 "Unit": "iMPH-U",
256 "EventCode": "0x80",
257 "UMask": "0x01",
258 "EventName": "UNC_ARB_TRK_OCCUPANCY.CYCLES_WITH_ANY_REQUEST",
259 "BriefDescription": "Cycles with at least one request outstanding is waiting for data return from memory controller. Account for coherent and non-coherent requests initiated by IA Cores, Processor Graphics Unit, or LLC.;",
260 "PublicDescription": "Cycles with at least one request outstanding is waiting for data return from memory controller. Account for coherent and non-coherent requests initiated by IA Cores, Processor Graphics Unit, or LLC.",
261 "Counter": "0,",
262 "CounterMask": "1",
263 "Invert": "0",
264 "EdgeDetect": "0"
265 },
266 {
267 "Unit": "NCU",
268 "EventCode": "0x0",
269 "UMask": "0x01",
270 "EventName": "UNC_CLOCK.SOCKET",
271 "BriefDescription": "This 48-bit fixed counter counts the UCLK cycles",
272 "PublicDescription": "This 48-bit fixed counter counts the UCLK cycles.",
273 "Counter": "FIXED",
274 "CounterMask": "0",
275 "Invert": "0",
276 "EdgeDetect": "0"
277 }
278] \ No newline at end of file
diff --git a/tools/perf/pmu-events/arch/x86/broadwellde/uncore-cache.json b/tools/perf/pmu-events/arch/x86/broadwellde/uncore-cache.json
index 076459c51d4e..58ed6d33d1f4 100644
--- a/tools/perf/pmu-events/arch/x86/broadwellde/uncore-cache.json
+++ b/tools/perf/pmu-events/arch/x86/broadwellde/uncore-cache.json
@@ -1,13 +1,13 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "Uncore cache clock ticks. Derived from unc_c_clockticks", 3 "BriefDescription": "Uncore cache clock ticks",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventName": "UNC_C_CLOCKTICKS", 5 "EventName": "UNC_C_CLOCKTICKS",
6 "PerPkg": "1", 6 "PerPkg": "1",
7 "Unit": "CBO" 7 "Unit": "CBO"
8 }, 8 },
9 { 9 {
10 "BriefDescription": "All LLC Misses (code+ data rd + data wr - including demand and prefetch). Derived from unc_c_llc_lookup.any", 10 "BriefDescription": "All LLC Misses (code+ data rd + data wr - including demand and prefetch)",
11 "Counter": "0,1,2,3", 11 "Counter": "0,1,2,3",
12 "EventCode": "0x34", 12 "EventCode": "0x34",
13 "EventName": "UNC_C_LLC_LOOKUP.ANY", 13 "EventName": "UNC_C_LLC_LOOKUP.ANY",
@@ -18,7 +18,7 @@
18 "Unit": "CBO" 18 "Unit": "CBO"
19 }, 19 },
20 { 20 {
21 "BriefDescription": "M line evictions from LLC (writebacks to memory). Derived from unc_c_llc_victims.m_state", 21 "BriefDescription": "M line evictions from LLC (writebacks to memory)",
22 "Counter": "0,1,2,3", 22 "Counter": "0,1,2,3",
23 "EventCode": "0x37", 23 "EventCode": "0x37",
24 "EventName": "UNC_C_LLC_VICTIMS.M_STATE", 24 "EventName": "UNC_C_LLC_VICTIMS.M_STATE",
@@ -212,7 +212,7 @@
212 "Unit": "CBO" 212 "Unit": "CBO"
213 }, 213 },
214 { 214 {
215 "BriefDescription": "read requests to home agent. Derived from unc_h_requests.reads", 215 "BriefDescription": "read requests to home agent",
216 "Counter": "0,1,2,3", 216 "Counter": "0,1,2,3",
217 "EventCode": "0x1", 217 "EventCode": "0x1",
218 "EventName": "UNC_H_REQUESTS.READS", 218 "EventName": "UNC_H_REQUESTS.READS",
@@ -221,7 +221,7 @@
221 "Unit": "HA" 221 "Unit": "HA"
222 }, 222 },
223 { 223 {
224 "BriefDescription": "read requests to local home agent. Derived from unc_h_requests.reads_local", 224 "BriefDescription": "read requests to local home agent",
225 "Counter": "0,1,2,3", 225 "Counter": "0,1,2,3",
226 "EventCode": "0x1", 226 "EventCode": "0x1",
227 "EventName": "UNC_H_REQUESTS.READS_LOCAL", 227 "EventName": "UNC_H_REQUESTS.READS_LOCAL",
@@ -230,7 +230,7 @@
230 "Unit": "HA" 230 "Unit": "HA"
231 }, 231 },
232 { 232 {
233 "BriefDescription": "read requests to remote home agent. Derived from unc_h_requests.reads_remote", 233 "BriefDescription": "read requests to remote home agent",
234 "Counter": "0,1,2,3", 234 "Counter": "0,1,2,3",
235 "EventCode": "0x1", 235 "EventCode": "0x1",
236 "EventName": "UNC_H_REQUESTS.READS_REMOTE", 236 "EventName": "UNC_H_REQUESTS.READS_REMOTE",
@@ -239,7 +239,7 @@
239 "Unit": "HA" 239 "Unit": "HA"
240 }, 240 },
241 { 241 {
242 "BriefDescription": "write requests to home agent. Derived from unc_h_requests.writes", 242 "BriefDescription": "write requests to home agent",
243 "Counter": "0,1,2,3", 243 "Counter": "0,1,2,3",
244 "EventCode": "0x1", 244 "EventCode": "0x1",
245 "EventName": "UNC_H_REQUESTS.WRITES", 245 "EventName": "UNC_H_REQUESTS.WRITES",
@@ -248,7 +248,7 @@
248 "Unit": "HA" 248 "Unit": "HA"
249 }, 249 },
250 { 250 {
251 "BriefDescription": "write requests to local home agent. Derived from unc_h_requests.writes_local", 251 "BriefDescription": "write requests to local home agent",
252 "Counter": "0,1,2,3", 252 "Counter": "0,1,2,3",
253 "EventCode": "0x1", 253 "EventCode": "0x1",
254 "EventName": "UNC_H_REQUESTS.WRITES_LOCAL", 254 "EventName": "UNC_H_REQUESTS.WRITES_LOCAL",
@@ -257,7 +257,7 @@
257 "Unit": "HA" 257 "Unit": "HA"
258 }, 258 },
259 { 259 {
260 "BriefDescription": "write requests to remote home agent. Derived from unc_h_requests.writes_remote", 260 "BriefDescription": "write requests to remote home agent",
261 "Counter": "0,1,2,3", 261 "Counter": "0,1,2,3",
262 "EventCode": "0x1", 262 "EventCode": "0x1",
263 "EventName": "UNC_H_REQUESTS.WRITES_REMOTE", 263 "EventName": "UNC_H_REQUESTS.WRITES_REMOTE",
@@ -266,7 +266,7 @@
266 "Unit": "HA" 266 "Unit": "HA"
267 }, 267 },
268 { 268 {
269 "BriefDescription": "Conflict requests (requests for same address from multiple agents simultaneously). Derived from unc_h_snoop_resp.rspcnflct", 269 "BriefDescription": "Conflict requests (requests for same address from multiple agents simultaneously)",
270 "Counter": "0,1,2,3", 270 "Counter": "0,1,2,3",
271 "EventCode": "0x21", 271 "EventCode": "0x21",
272 "EventName": "UNC_H_SNOOP_RESP.RSPCNFLCT", 272 "EventName": "UNC_H_SNOOP_RESP.RSPCNFLCT",
@@ -275,7 +275,7 @@
275 "Unit": "HA" 275 "Unit": "HA"
276 }, 276 },
277 { 277 {
278 "BriefDescription": "M line forwarded from remote cache along with writeback to memory. Derived from unc_h_snoop_resp.rsp_fwd_wb", 278 "BriefDescription": "M line forwarded from remote cache along with writeback to memory",
279 "Counter": "0,1,2,3", 279 "Counter": "0,1,2,3",
280 "EventCode": "0x21", 280 "EventCode": "0x21",
281 "EventName": "UNC_H_SNOOP_RESP.RSP_FWD_WB", 281 "EventName": "UNC_H_SNOOP_RESP.RSP_FWD_WB",
@@ -285,7 +285,7 @@
285 "Unit": "HA" 285 "Unit": "HA"
286 }, 286 },
287 { 287 {
288 "BriefDescription": "M line forwarded from remote cache with no writeback to memory. Derived from unc_h_snoop_resp.rspifwd", 288 "BriefDescription": "M line forwarded from remote cache with no writeback to memory",
289 "Counter": "0,1,2,3", 289 "Counter": "0,1,2,3",
290 "EventCode": "0x21", 290 "EventCode": "0x21",
291 "EventName": "UNC_H_SNOOP_RESP.RSPIFWD", 291 "EventName": "UNC_H_SNOOP_RESP.RSPIFWD",
@@ -295,7 +295,7 @@
295 "Unit": "HA" 295 "Unit": "HA"
296 }, 296 },
297 { 297 {
298 "BriefDescription": "Shared line response from remote cache. Derived from unc_h_snoop_resp.rsps", 298 "BriefDescription": "Shared line response from remote cache",
299 "Counter": "0,1,2,3", 299 "Counter": "0,1,2,3",
300 "EventCode": "0x21", 300 "EventCode": "0x21",
301 "EventName": "UNC_H_SNOOP_RESP.RSPS", 301 "EventName": "UNC_H_SNOOP_RESP.RSPS",
@@ -305,7 +305,7 @@
305 "Unit": "HA" 305 "Unit": "HA"
306 }, 306 },
307 { 307 {
308 "BriefDescription": "Shared line forwarded from remote cache. Derived from unc_h_snoop_resp.rspsfwd", 308 "BriefDescription": "Shared line forwarded from remote cache",
309 "Counter": "0,1,2,3", 309 "Counter": "0,1,2,3",
310 "EventCode": "0x21", 310 "EventCode": "0x21",
311 "EventName": "UNC_H_SNOOP_RESP.RSPSFWD", 311 "EventName": "UNC_H_SNOOP_RESP.RSPSFWD",
diff --git a/tools/perf/pmu-events/arch/x86/broadwellde/uncore-memory.json b/tools/perf/pmu-events/arch/x86/broadwellde/uncore-memory.json
index d17dc235f734..f4b0745cdbbf 100644
--- a/tools/perf/pmu-events/arch/x86/broadwellde/uncore-memory.json
+++ b/tools/perf/pmu-events/arch/x86/broadwellde/uncore-memory.json
@@ -3,7 +3,7 @@
3 "BriefDescription": "read requests to memory controller. Derived from unc_m_cas_count.rd", 3 "BriefDescription": "read requests to memory controller. Derived from unc_m_cas_count.rd",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventCode": "0x4", 5 "EventCode": "0x4",
6 "EventName": "UNC_M_CAS_COUNT.RD", 6 "EventName": "LLC_MISSES.MEM_READ",
7 "PerPkg": "1", 7 "PerPkg": "1",
8 "ScaleUnit": "64Bytes", 8 "ScaleUnit": "64Bytes",
9 "UMask": "0x3", 9 "UMask": "0x3",
@@ -13,48 +13,51 @@
13 "BriefDescription": "write requests to memory controller. Derived from unc_m_cas_count.wr", 13 "BriefDescription": "write requests to memory controller. Derived from unc_m_cas_count.wr",
14 "Counter": "0,1,2,3", 14 "Counter": "0,1,2,3",
15 "EventCode": "0x4", 15 "EventCode": "0x4",
16 "EventName": "UNC_M_CAS_COUNT.WR", 16 "EventName": "LLC_MISSES.MEM_WRITE",
17 "PerPkg": "1", 17 "PerPkg": "1",
18 "ScaleUnit": "64Bytes", 18 "ScaleUnit": "64Bytes",
19 "UMask": "0xC", 19 "UMask": "0xC",
20 "Unit": "iMC" 20 "Unit": "iMC"
21 }, 21 },
22 { 22 {
23 "BriefDescription": "Memory controller clock ticks. Derived from unc_m_clockticks", 23 "BriefDescription": "Memory controller clock ticks",
24 "Counter": "0,1,2,3", 24 "Counter": "0,1,2,3",
25 "EventName": "UNC_M_CLOCKTICKS", 25 "EventName": "UNC_M_DCLOCKTICKS",
26 "PerPkg": "1", 26 "PerPkg": "1",
27 "Unit": "iMC" 27 "Unit": "iMC"
28 }, 28 },
29 { 29 {
30 "BriefDescription": "Cycles where DRAM ranks are in power down (CKE) mode. Derived from unc_m_power_channel_ppd", 30 "BriefDescription": "Cycles where DRAM ranks are in power down (CKE) mode",
31 "Counter": "0,1,2,3", 31 "Counter": "0,1,2,3",
32 "EventCode": "0x85", 32 "EventCode": "0x85",
33 "EventName": "UNC_M_POWER_CHANNEL_PPD", 33 "EventName": "UNC_M_POWER_CHANNEL_PPD",
34 "MetricExpr": "(UNC_M_POWER_CHANNEL_PPD / UNC_M_CLOCKTICKS) * 100.", 34 "MetricExpr": "(UNC_M_POWER_CHANNEL_PPD / UNC_M_DCLOCKTICKS) * 100.",
35 "MetricName": "power_channel_ppd %",
35 "PerPkg": "1", 36 "PerPkg": "1",
36 "Unit": "iMC" 37 "Unit": "iMC"
37 }, 38 },
38 { 39 {
39 "BriefDescription": "Cycles all ranks are in critical thermal throttle. Derived from unc_m_power_critical_throttle_cycles", 40 "BriefDescription": "Cycles all ranks are in critical thermal throttle",
40 "Counter": "0,1,2,3", 41 "Counter": "0,1,2,3",
41 "EventCode": "0x86", 42 "EventCode": "0x86",
42 "EventName": "UNC_M_POWER_CRITICAL_THROTTLE_CYCLES", 43 "EventName": "UNC_M_POWER_CRITICAL_THROTTLE_CYCLES",
43 "MetricExpr": "(UNC_M_POWER_CRITICAL_THROTTLE_CYCLES / UNC_M_CLOCKTICKS) * 100.", 44 "MetricExpr": "(UNC_M_POWER_CRITICAL_THROTTLE_CYCLES / UNC_M_DCLOCKTICKS) * 100.",
45 "MetricName": "power_critical_throttle_cycles %",
44 "PerPkg": "1", 46 "PerPkg": "1",
45 "Unit": "iMC" 47 "Unit": "iMC"
46 }, 48 },
47 { 49 {
48 "BriefDescription": "Cycles Memory is in self refresh power mode. Derived from unc_m_power_self_refresh", 50 "BriefDescription": "Cycles Memory is in self refresh power mode",
49 "Counter": "0,1,2,3", 51 "Counter": "0,1,2,3",
50 "EventCode": "0x43", 52 "EventCode": "0x43",
51 "EventName": "UNC_M_POWER_SELF_REFRESH", 53 "EventName": "UNC_M_POWER_SELF_REFRESH",
52 "MetricExpr": "(UNC_M_POWER_SELF_REFRESH / UNC_M_CLOCKTICKS) * 100.", 54 "MetricExpr": "(UNC_M_POWER_SELF_REFRESH / UNC_M_DCLOCKTICKS) * 100.",
55 "MetricName": "power_self_refresh %",
53 "PerPkg": "1", 56 "PerPkg": "1",
54 "Unit": "iMC" 57 "Unit": "iMC"
55 }, 58 },
56 { 59 {
57 "BriefDescription": "Pre-charges due to page misses. Derived from unc_m_pre_count.page_miss", 60 "BriefDescription": "Pre-charges due to page misses",
58 "Counter": "0,1,2,3", 61 "Counter": "0,1,2,3",
59 "EventCode": "0x2", 62 "EventCode": "0x2",
60 "EventName": "UNC_M_PRE_COUNT.PAGE_MISS", 63 "EventName": "UNC_M_PRE_COUNT.PAGE_MISS",
@@ -63,7 +66,7 @@
63 "Unit": "iMC" 66 "Unit": "iMC"
64 }, 67 },
65 { 68 {
66 "BriefDescription": "Pre-charge for reads. Derived from unc_m_pre_count.rd", 69 "BriefDescription": "Pre-charge for reads",
67 "Counter": "0,1,2,3", 70 "Counter": "0,1,2,3",
68 "EventCode": "0x2", 71 "EventCode": "0x2",
69 "EventName": "UNC_M_PRE_COUNT.RD", 72 "EventName": "UNC_M_PRE_COUNT.RD",
@@ -72,7 +75,7 @@
72 "Unit": "iMC" 75 "Unit": "iMC"
73 }, 76 },
74 { 77 {
75 "BriefDescription": "Pre-charge for writes. Derived from unc_m_pre_count.wr", 78 "BriefDescription": "Pre-charge for writes",
76 "Counter": "0,1,2,3", 79 "Counter": "0,1,2,3",
77 "EventCode": "0x2", 80 "EventCode": "0x2",
78 "EventName": "UNC_M_PRE_COUNT.WR", 81 "EventName": "UNC_M_PRE_COUNT.WR",
diff --git a/tools/perf/pmu-events/arch/x86/broadwellde/uncore-power.json b/tools/perf/pmu-events/arch/x86/broadwellde/uncore-power.json
index b44d43088bbb..dd1b95655d1d 100644
--- a/tools/perf/pmu-events/arch/x86/broadwellde/uncore-power.json
+++ b/tools/perf/pmu-events/arch/x86/broadwellde/uncore-power.json
@@ -1,83 +1,91 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "PCU clock ticks. Use to get percentages of PCU cycles events. Derived from unc_p_clockticks", 3 "BriefDescription": "PCU clock ticks. Use to get percentages of PCU cycles events",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventName": "UNC_P_CLOCKTICKS", 5 "EventName": "UNC_P_CLOCKTICKS",
6 "PerPkg": "1", 6 "PerPkg": "1",
7 "Unit": "PCU" 7 "Unit": "PCU"
8 }, 8 },
9 { 9 {
10 "BriefDescription": "C0 and C1. Derived from unc_p_power_state_occupancy.cores_c0", 10 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C0. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details",
11 "Counter": "0,1,2,3", 11 "Counter": "0,1,2,3",
12 "EventCode": "0x80", 12 "EventCode": "0x80",
13 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C0", 13 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C0",
14 "Filter": "occ_sel=1", 14 "Filter": "occ_sel=1",
15 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C0 / UNC_P_CLOCKTICKS) * 100.", 15 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C0 / UNC_P_CLOCKTICKS) * 100.",
16 "MetricName": "power_state_occupancy.cores_c0 %",
16 "PerPkg": "1", 17 "PerPkg": "1",
17 "Unit": "PCU" 18 "Unit": "PCU"
18 }, 19 },
19 { 20 {
20 "BriefDescription": "C3. Derived from unc_p_power_state_occupancy.cores_c3", 21 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C3. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details",
21 "Counter": "0,1,2,3", 22 "Counter": "0,1,2,3",
22 "EventCode": "0x80", 23 "EventCode": "0x80",
23 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C3", 24 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C3",
24 "Filter": "occ_sel=2", 25 "Filter": "occ_sel=2",
25 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C3 / UNC_P_CLOCKTICKS) * 100.", 26 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C3 / UNC_P_CLOCKTICKS) * 100.",
27 "MetricName": "power_state_occupancy.cores_c3 %",
26 "PerPkg": "1", 28 "PerPkg": "1",
27 "Unit": "PCU" 29 "Unit": "PCU"
28 }, 30 },
29 { 31 {
30 "BriefDescription": "C6 and C7. Derived from unc_p_power_state_occupancy.cores_c6", 32 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C6. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events ",
31 "Counter": "0,1,2,3", 33 "Counter": "0,1,2,3",
32 "EventCode": "0x80", 34 "EventCode": "0x80",
33 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C6", 35 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C6",
34 "Filter": "occ_sel=3", 36 "Filter": "occ_sel=3",
35 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C6 / UNC_P_CLOCKTICKS) * 100.", 37 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C6 / UNC_P_CLOCKTICKS) * 100.",
38 "MetricName": "power_state_occupancy.cores_c6 %",
36 "PerPkg": "1", 39 "PerPkg": "1",
37 "Unit": "PCU" 40 "Unit": "PCU"
38 }, 41 },
39 { 42 {
40 "BriefDescription": "External Prochot. Derived from unc_p_prochot_external_cycles", 43 "BriefDescription": "Counts the number of cycles that we are in external PROCHOT mode. This mode is triggered when a sensor off the die determines that something off-die (like DRAM) is too hot and must throttle to avoid damaging the chip",
41 "Counter": "0,1,2,3", 44 "Counter": "0,1,2,3",
42 "EventCode": "0xA", 45 "EventCode": "0xA",
43 "EventName": "UNC_P_PROCHOT_EXTERNAL_CYCLES", 46 "EventName": "UNC_P_PROCHOT_EXTERNAL_CYCLES",
44 "MetricExpr": "(UNC_P_PROCHOT_EXTERNAL_CYCLES / UNC_P_CLOCKTICKS) * 100.", 47 "MetricExpr": "(UNC_P_PROCHOT_EXTERNAL_CYCLES / UNC_P_CLOCKTICKS) * 100.",
48 "MetricName": "prochot_external_cycles %",
45 "PerPkg": "1", 49 "PerPkg": "1",
46 "Unit": "PCU" 50 "Unit": "PCU"
47 }, 51 },
48 { 52 {
49 "BriefDescription": "Thermal Strongest Upper Limit Cycles. Derived from unc_p_freq_max_limit_thermal_cycles", 53 "BriefDescription": "Counts the number of cycles when temperature is the upper limit on frequency",
50 "Counter": "0,1,2,3", 54 "Counter": "0,1,2,3",
51 "EventCode": "0x4", 55 "EventCode": "0x4",
52 "EventName": "UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES", 56 "EventName": "UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES",
53 "MetricExpr": "(UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES / UNC_P_CLOCKTICKS) * 100.", 57 "MetricExpr": "(UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES / UNC_P_CLOCKTICKS) * 100.",
58 "MetricName": "freq_max_limit_thermal_cycles %",
54 "PerPkg": "1", 59 "PerPkg": "1",
55 "Unit": "PCU" 60 "Unit": "PCU"
56 }, 61 },
57 { 62 {
58 "BriefDescription": "OS Strongest Upper Limit Cycles. Derived from unc_p_freq_max_os_cycles", 63 "BriefDescription": "Counts the number of cycles when the OS is the upper limit on frequency",
59 "Counter": "0,1,2,3", 64 "Counter": "0,1,2,3",
60 "EventCode": "0x6", 65 "EventCode": "0x6",
61 "EventName": "UNC_P_FREQ_MAX_OS_CYCLES", 66 "EventName": "UNC_P_FREQ_MAX_OS_CYCLES",
62 "MetricExpr": "(UNC_P_FREQ_MAX_OS_CYCLES / UNC_P_CLOCKTICKS) * 100.", 67 "MetricExpr": "(UNC_P_FREQ_MAX_OS_CYCLES / UNC_P_CLOCKTICKS) * 100.",
68 "MetricName": "freq_max_os_cycles %",
63 "PerPkg": "1", 69 "PerPkg": "1",
64 "Unit": "PCU" 70 "Unit": "PCU"
65 }, 71 },
66 { 72 {
67 "BriefDescription": "Power Strongest Upper Limit Cycles. Derived from unc_p_freq_max_power_cycles", 73 "BriefDescription": "Counts the number of cycles when power is the upper limit on frequency",
68 "Counter": "0,1,2,3", 74 "Counter": "0,1,2,3",
69 "EventCode": "0x5", 75 "EventCode": "0x5",
70 "EventName": "UNC_P_FREQ_MAX_POWER_CYCLES", 76 "EventName": "UNC_P_FREQ_MAX_POWER_CYCLES",
71 "MetricExpr": "(UNC_P_FREQ_MAX_POWER_CYCLES / UNC_P_CLOCKTICKS) * 100.", 77 "MetricExpr": "(UNC_P_FREQ_MAX_POWER_CYCLES / UNC_P_CLOCKTICKS) * 100.",
78 "MetricName": "freq_max_power_cycles %",
72 "PerPkg": "1", 79 "PerPkg": "1",
73 "Unit": "PCU" 80 "Unit": "PCU"
74 }, 81 },
75 { 82 {
76 "BriefDescription": "Cycles spent changing Frequency. Derived from unc_p_freq_trans_cycles", 83 "BriefDescription": "Counts the number of cycles when current is the upper limit on frequency",
77 "Counter": "0,1,2,3", 84 "Counter": "0,1,2,3",
78 "EventCode": "0x74", 85 "EventCode": "0x74",
79 "EventName": "UNC_P_FREQ_TRANS_CYCLES", 86 "EventName": "UNC_P_FREQ_TRANS_CYCLES",
80 "MetricExpr": "(UNC_P_FREQ_TRANS_CYCLES / UNC_P_CLOCKTICKS) * 100.", 87 "MetricExpr": "(UNC_P_FREQ_TRANS_CYCLES / UNC_P_CLOCKTICKS) * 100.",
88 "MetricName": "freq_trans_cycles %",
81 "PerPkg": "1", 89 "PerPkg": "1",
82 "Unit": "PCU" 90 "Unit": "PCU"
83 } 91 }
diff --git a/tools/perf/pmu-events/arch/x86/broadwellx/uncore-cache.json b/tools/perf/pmu-events/arch/x86/broadwellx/uncore-cache.json
index 076459c51d4e..58ed6d33d1f4 100644
--- a/tools/perf/pmu-events/arch/x86/broadwellx/uncore-cache.json
+++ b/tools/perf/pmu-events/arch/x86/broadwellx/uncore-cache.json
@@ -1,13 +1,13 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "Uncore cache clock ticks. Derived from unc_c_clockticks", 3 "BriefDescription": "Uncore cache clock ticks",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventName": "UNC_C_CLOCKTICKS", 5 "EventName": "UNC_C_CLOCKTICKS",
6 "PerPkg": "1", 6 "PerPkg": "1",
7 "Unit": "CBO" 7 "Unit": "CBO"
8 }, 8 },
9 { 9 {
10 "BriefDescription": "All LLC Misses (code+ data rd + data wr - including demand and prefetch). Derived from unc_c_llc_lookup.any", 10 "BriefDescription": "All LLC Misses (code+ data rd + data wr - including demand and prefetch)",
11 "Counter": "0,1,2,3", 11 "Counter": "0,1,2,3",
12 "EventCode": "0x34", 12 "EventCode": "0x34",
13 "EventName": "UNC_C_LLC_LOOKUP.ANY", 13 "EventName": "UNC_C_LLC_LOOKUP.ANY",
@@ -18,7 +18,7 @@
18 "Unit": "CBO" 18 "Unit": "CBO"
19 }, 19 },
20 { 20 {
21 "BriefDescription": "M line evictions from LLC (writebacks to memory). Derived from unc_c_llc_victims.m_state", 21 "BriefDescription": "M line evictions from LLC (writebacks to memory)",
22 "Counter": "0,1,2,3", 22 "Counter": "0,1,2,3",
23 "EventCode": "0x37", 23 "EventCode": "0x37",
24 "EventName": "UNC_C_LLC_VICTIMS.M_STATE", 24 "EventName": "UNC_C_LLC_VICTIMS.M_STATE",
@@ -212,7 +212,7 @@
212 "Unit": "CBO" 212 "Unit": "CBO"
213 }, 213 },
214 { 214 {
215 "BriefDescription": "read requests to home agent. Derived from unc_h_requests.reads", 215 "BriefDescription": "read requests to home agent",
216 "Counter": "0,1,2,3", 216 "Counter": "0,1,2,3",
217 "EventCode": "0x1", 217 "EventCode": "0x1",
218 "EventName": "UNC_H_REQUESTS.READS", 218 "EventName": "UNC_H_REQUESTS.READS",
@@ -221,7 +221,7 @@
221 "Unit": "HA" 221 "Unit": "HA"
222 }, 222 },
223 { 223 {
224 "BriefDescription": "read requests to local home agent. Derived from unc_h_requests.reads_local", 224 "BriefDescription": "read requests to local home agent",
225 "Counter": "0,1,2,3", 225 "Counter": "0,1,2,3",
226 "EventCode": "0x1", 226 "EventCode": "0x1",
227 "EventName": "UNC_H_REQUESTS.READS_LOCAL", 227 "EventName": "UNC_H_REQUESTS.READS_LOCAL",
@@ -230,7 +230,7 @@
230 "Unit": "HA" 230 "Unit": "HA"
231 }, 231 },
232 { 232 {
233 "BriefDescription": "read requests to remote home agent. Derived from unc_h_requests.reads_remote", 233 "BriefDescription": "read requests to remote home agent",
234 "Counter": "0,1,2,3", 234 "Counter": "0,1,2,3",
235 "EventCode": "0x1", 235 "EventCode": "0x1",
236 "EventName": "UNC_H_REQUESTS.READS_REMOTE", 236 "EventName": "UNC_H_REQUESTS.READS_REMOTE",
@@ -239,7 +239,7 @@
239 "Unit": "HA" 239 "Unit": "HA"
240 }, 240 },
241 { 241 {
242 "BriefDescription": "write requests to home agent. Derived from unc_h_requests.writes", 242 "BriefDescription": "write requests to home agent",
243 "Counter": "0,1,2,3", 243 "Counter": "0,1,2,3",
244 "EventCode": "0x1", 244 "EventCode": "0x1",
245 "EventName": "UNC_H_REQUESTS.WRITES", 245 "EventName": "UNC_H_REQUESTS.WRITES",
@@ -248,7 +248,7 @@
248 "Unit": "HA" 248 "Unit": "HA"
249 }, 249 },
250 { 250 {
251 "BriefDescription": "write requests to local home agent. Derived from unc_h_requests.writes_local", 251 "BriefDescription": "write requests to local home agent",
252 "Counter": "0,1,2,3", 252 "Counter": "0,1,2,3",
253 "EventCode": "0x1", 253 "EventCode": "0x1",
254 "EventName": "UNC_H_REQUESTS.WRITES_LOCAL", 254 "EventName": "UNC_H_REQUESTS.WRITES_LOCAL",
@@ -257,7 +257,7 @@
257 "Unit": "HA" 257 "Unit": "HA"
258 }, 258 },
259 { 259 {
260 "BriefDescription": "write requests to remote home agent. Derived from unc_h_requests.writes_remote", 260 "BriefDescription": "write requests to remote home agent",
261 "Counter": "0,1,2,3", 261 "Counter": "0,1,2,3",
262 "EventCode": "0x1", 262 "EventCode": "0x1",
263 "EventName": "UNC_H_REQUESTS.WRITES_REMOTE", 263 "EventName": "UNC_H_REQUESTS.WRITES_REMOTE",
@@ -266,7 +266,7 @@
266 "Unit": "HA" 266 "Unit": "HA"
267 }, 267 },
268 { 268 {
269 "BriefDescription": "Conflict requests (requests for same address from multiple agents simultaneously). Derived from unc_h_snoop_resp.rspcnflct", 269 "BriefDescription": "Conflict requests (requests for same address from multiple agents simultaneously)",
270 "Counter": "0,1,2,3", 270 "Counter": "0,1,2,3",
271 "EventCode": "0x21", 271 "EventCode": "0x21",
272 "EventName": "UNC_H_SNOOP_RESP.RSPCNFLCT", 272 "EventName": "UNC_H_SNOOP_RESP.RSPCNFLCT",
@@ -275,7 +275,7 @@
275 "Unit": "HA" 275 "Unit": "HA"
276 }, 276 },
277 { 277 {
278 "BriefDescription": "M line forwarded from remote cache along with writeback to memory. Derived from unc_h_snoop_resp.rsp_fwd_wb", 278 "BriefDescription": "M line forwarded from remote cache along with writeback to memory",
279 "Counter": "0,1,2,3", 279 "Counter": "0,1,2,3",
280 "EventCode": "0x21", 280 "EventCode": "0x21",
281 "EventName": "UNC_H_SNOOP_RESP.RSP_FWD_WB", 281 "EventName": "UNC_H_SNOOP_RESP.RSP_FWD_WB",
@@ -285,7 +285,7 @@
285 "Unit": "HA" 285 "Unit": "HA"
286 }, 286 },
287 { 287 {
288 "BriefDescription": "M line forwarded from remote cache with no writeback to memory. Derived from unc_h_snoop_resp.rspifwd", 288 "BriefDescription": "M line forwarded from remote cache with no writeback to memory",
289 "Counter": "0,1,2,3", 289 "Counter": "0,1,2,3",
290 "EventCode": "0x21", 290 "EventCode": "0x21",
291 "EventName": "UNC_H_SNOOP_RESP.RSPIFWD", 291 "EventName": "UNC_H_SNOOP_RESP.RSPIFWD",
@@ -295,7 +295,7 @@
295 "Unit": "HA" 295 "Unit": "HA"
296 }, 296 },
297 { 297 {
298 "BriefDescription": "Shared line response from remote cache. Derived from unc_h_snoop_resp.rsps", 298 "BriefDescription": "Shared line response from remote cache",
299 "Counter": "0,1,2,3", 299 "Counter": "0,1,2,3",
300 "EventCode": "0x21", 300 "EventCode": "0x21",
301 "EventName": "UNC_H_SNOOP_RESP.RSPS", 301 "EventName": "UNC_H_SNOOP_RESP.RSPS",
@@ -305,7 +305,7 @@
305 "Unit": "HA" 305 "Unit": "HA"
306 }, 306 },
307 { 307 {
308 "BriefDescription": "Shared line forwarded from remote cache. Derived from unc_h_snoop_resp.rspsfwd", 308 "BriefDescription": "Shared line forwarded from remote cache",
309 "Counter": "0,1,2,3", 309 "Counter": "0,1,2,3",
310 "EventCode": "0x21", 310 "EventCode": "0x21",
311 "EventName": "UNC_H_SNOOP_RESP.RSPSFWD", 311 "EventName": "UNC_H_SNOOP_RESP.RSPSFWD",
diff --git a/tools/perf/pmu-events/arch/x86/broadwellx/uncore-interconnect.json b/tools/perf/pmu-events/arch/x86/broadwellx/uncore-interconnect.json
index 39387f7909b2..824961318c1e 100644
--- a/tools/perf/pmu-events/arch/x86/broadwellx/uncore-interconnect.json
+++ b/tools/perf/pmu-events/arch/x86/broadwellx/uncore-interconnect.json
@@ -1,6 +1,6 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "QPI clock ticks. Derived from unc_q_clockticks", 3 "BriefDescription": "QPI clock ticks",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventCode": "0x14", 5 "EventCode": "0x14",
6 "EventName": "UNC_Q_CLOCKTICKS", 6 "EventName": "UNC_Q_CLOCKTICKS",
@@ -10,7 +10,7 @@
10 { 10 {
11 "BriefDescription": "Number of data flits transmitted . Derived from unc_q_txl_flits_g0.data", 11 "BriefDescription": "Number of data flits transmitted . Derived from unc_q_txl_flits_g0.data",
12 "Counter": "0,1,2,3", 12 "Counter": "0,1,2,3",
13 "EventName": "UNC_Q_TxL_FLITS_G0.DATA", 13 "EventName": "QPI_DATA_BANDWIDTH_TX",
14 "PerPkg": "1", 14 "PerPkg": "1",
15 "ScaleUnit": "8Bytes", 15 "ScaleUnit": "8Bytes",
16 "UMask": "0x2", 16 "UMask": "0x2",
@@ -19,7 +19,7 @@
19 { 19 {
20 "BriefDescription": "Number of non data (control) flits transmitted . Derived from unc_q_txl_flits_g0.non_data", 20 "BriefDescription": "Number of non data (control) flits transmitted . Derived from unc_q_txl_flits_g0.non_data",
21 "Counter": "0,1,2,3", 21 "Counter": "0,1,2,3",
22 "EventName": "UNC_Q_TxL_FLITS_G0.NON_DATA", 22 "EventName": "QPI_CTL_BANDWIDTH_TX",
23 "PerPkg": "1", 23 "PerPkg": "1",
24 "ScaleUnit": "8Bytes", 24 "ScaleUnit": "8Bytes",
25 "UMask": "0x4", 25 "UMask": "0x4",
diff --git a/tools/perf/pmu-events/arch/x86/broadwellx/uncore-memory.json b/tools/perf/pmu-events/arch/x86/broadwellx/uncore-memory.json
index d17dc235f734..66eed399724c 100644
--- a/tools/perf/pmu-events/arch/x86/broadwellx/uncore-memory.json
+++ b/tools/perf/pmu-events/arch/x86/broadwellx/uncore-memory.json
@@ -3,7 +3,7 @@
3 "BriefDescription": "read requests to memory controller. Derived from unc_m_cas_count.rd", 3 "BriefDescription": "read requests to memory controller. Derived from unc_m_cas_count.rd",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventCode": "0x4", 5 "EventCode": "0x4",
6 "EventName": "UNC_M_CAS_COUNT.RD", 6 "EventName": "LLC_MISSES.MEM_READ",
7 "PerPkg": "1", 7 "PerPkg": "1",
8 "ScaleUnit": "64Bytes", 8 "ScaleUnit": "64Bytes",
9 "UMask": "0x3", 9 "UMask": "0x3",
@@ -13,48 +13,51 @@
13 "BriefDescription": "write requests to memory controller. Derived from unc_m_cas_count.wr", 13 "BriefDescription": "write requests to memory controller. Derived from unc_m_cas_count.wr",
14 "Counter": "0,1,2,3", 14 "Counter": "0,1,2,3",
15 "EventCode": "0x4", 15 "EventCode": "0x4",
16 "EventName": "UNC_M_CAS_COUNT.WR", 16 "EventName": "LLC_MISSES.MEM_WRITE",
17 "PerPkg": "1", 17 "PerPkg": "1",
18 "ScaleUnit": "64Bytes", 18 "ScaleUnit": "64Bytes",
19 "UMask": "0xC", 19 "UMask": "0xC",
20 "Unit": "iMC" 20 "Unit": "iMC"
21 }, 21 },
22 { 22 {
23 "BriefDescription": "Memory controller clock ticks. Derived from unc_m_clockticks", 23 "BriefDescription": "Memory controller clock ticks",
24 "Counter": "0,1,2,3", 24 "Counter": "0,1,2,3",
25 "EventName": "UNC_M_CLOCKTICKS", 25 "EventName": "UNC_M_CLOCKTICKS",
26 "PerPkg": "1", 26 "PerPkg": "1",
27 "Unit": "iMC" 27 "Unit": "iMC"
28 }, 28 },
29 { 29 {
30 "BriefDescription": "Cycles where DRAM ranks are in power down (CKE) mode. Derived from unc_m_power_channel_ppd", 30 "BriefDescription": "Cycles where DRAM ranks are in power down (CKE) mode",
31 "Counter": "0,1,2,3", 31 "Counter": "0,1,2,3",
32 "EventCode": "0x85", 32 "EventCode": "0x85",
33 "EventName": "UNC_M_POWER_CHANNEL_PPD", 33 "EventName": "UNC_M_POWER_CHANNEL_PPD",
34 "MetricExpr": "(UNC_M_POWER_CHANNEL_PPD / UNC_M_CLOCKTICKS) * 100.", 34 "MetricExpr": "(UNC_M_POWER_CHANNEL_PPD / UNC_M_CLOCKTICKS) * 100.",
35 "MetricName": "power_channel_ppd %",
35 "PerPkg": "1", 36 "PerPkg": "1",
36 "Unit": "iMC" 37 "Unit": "iMC"
37 }, 38 },
38 { 39 {
39 "BriefDescription": "Cycles all ranks are in critical thermal throttle. Derived from unc_m_power_critical_throttle_cycles", 40 "BriefDescription": "Cycles all ranks are in critical thermal throttle",
40 "Counter": "0,1,2,3", 41 "Counter": "0,1,2,3",
41 "EventCode": "0x86", 42 "EventCode": "0x86",
42 "EventName": "UNC_M_POWER_CRITICAL_THROTTLE_CYCLES", 43 "EventName": "UNC_M_POWER_CRITICAL_THROTTLE_CYCLES",
43 "MetricExpr": "(UNC_M_POWER_CRITICAL_THROTTLE_CYCLES / UNC_M_CLOCKTICKS) * 100.", 44 "MetricExpr": "(UNC_M_POWER_CRITICAL_THROTTLE_CYCLES / UNC_M_CLOCKTICKS) * 100.",
45 "MetricName": "power_critical_throttle_cycles %",
44 "PerPkg": "1", 46 "PerPkg": "1",
45 "Unit": "iMC" 47 "Unit": "iMC"
46 }, 48 },
47 { 49 {
48 "BriefDescription": "Cycles Memory is in self refresh power mode. Derived from unc_m_power_self_refresh", 50 "BriefDescription": "Cycles Memory is in self refresh power mode",
49 "Counter": "0,1,2,3", 51 "Counter": "0,1,2,3",
50 "EventCode": "0x43", 52 "EventCode": "0x43",
51 "EventName": "UNC_M_POWER_SELF_REFRESH", 53 "EventName": "UNC_M_POWER_SELF_REFRESH",
52 "MetricExpr": "(UNC_M_POWER_SELF_REFRESH / UNC_M_CLOCKTICKS) * 100.", 54 "MetricExpr": "(UNC_M_POWER_SELF_REFRESH / UNC_M_CLOCKTICKS) * 100.",
55 "MetricName": "power_self_refresh %",
53 "PerPkg": "1", 56 "PerPkg": "1",
54 "Unit": "iMC" 57 "Unit": "iMC"
55 }, 58 },
56 { 59 {
57 "BriefDescription": "Pre-charges due to page misses. Derived from unc_m_pre_count.page_miss", 60 "BriefDescription": "Pre-charges due to page misses",
58 "Counter": "0,1,2,3", 61 "Counter": "0,1,2,3",
59 "EventCode": "0x2", 62 "EventCode": "0x2",
60 "EventName": "UNC_M_PRE_COUNT.PAGE_MISS", 63 "EventName": "UNC_M_PRE_COUNT.PAGE_MISS",
@@ -63,7 +66,7 @@
63 "Unit": "iMC" 66 "Unit": "iMC"
64 }, 67 },
65 { 68 {
66 "BriefDescription": "Pre-charge for reads. Derived from unc_m_pre_count.rd", 69 "BriefDescription": "Pre-charge for reads",
67 "Counter": "0,1,2,3", 70 "Counter": "0,1,2,3",
68 "EventCode": "0x2", 71 "EventCode": "0x2",
69 "EventName": "UNC_M_PRE_COUNT.RD", 72 "EventName": "UNC_M_PRE_COUNT.RD",
@@ -72,7 +75,7 @@
72 "Unit": "iMC" 75 "Unit": "iMC"
73 }, 76 },
74 { 77 {
75 "BriefDescription": "Pre-charge for writes. Derived from unc_m_pre_count.wr", 78 "BriefDescription": "Pre-charge for writes",
76 "Counter": "0,1,2,3", 79 "Counter": "0,1,2,3",
77 "EventCode": "0x2", 80 "EventCode": "0x2",
78 "EventName": "UNC_M_PRE_COUNT.WR", 81 "EventName": "UNC_M_PRE_COUNT.WR",
diff --git a/tools/perf/pmu-events/arch/x86/broadwellx/uncore-power.json b/tools/perf/pmu-events/arch/x86/broadwellx/uncore-power.json
index b44d43088bbb..dd1b95655d1d 100644
--- a/tools/perf/pmu-events/arch/x86/broadwellx/uncore-power.json
+++ b/tools/perf/pmu-events/arch/x86/broadwellx/uncore-power.json
@@ -1,83 +1,91 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "PCU clock ticks. Use to get percentages of PCU cycles events. Derived from unc_p_clockticks", 3 "BriefDescription": "PCU clock ticks. Use to get percentages of PCU cycles events",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventName": "UNC_P_CLOCKTICKS", 5 "EventName": "UNC_P_CLOCKTICKS",
6 "PerPkg": "1", 6 "PerPkg": "1",
7 "Unit": "PCU" 7 "Unit": "PCU"
8 }, 8 },
9 { 9 {
10 "BriefDescription": "C0 and C1. Derived from unc_p_power_state_occupancy.cores_c0", 10 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C0. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details",
11 "Counter": "0,1,2,3", 11 "Counter": "0,1,2,3",
12 "EventCode": "0x80", 12 "EventCode": "0x80",
13 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C0", 13 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C0",
14 "Filter": "occ_sel=1", 14 "Filter": "occ_sel=1",
15 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C0 / UNC_P_CLOCKTICKS) * 100.", 15 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C0 / UNC_P_CLOCKTICKS) * 100.",
16 "MetricName": "power_state_occupancy.cores_c0 %",
16 "PerPkg": "1", 17 "PerPkg": "1",
17 "Unit": "PCU" 18 "Unit": "PCU"
18 }, 19 },
19 { 20 {
20 "BriefDescription": "C3. Derived from unc_p_power_state_occupancy.cores_c3", 21 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C3. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details",
21 "Counter": "0,1,2,3", 22 "Counter": "0,1,2,3",
22 "EventCode": "0x80", 23 "EventCode": "0x80",
23 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C3", 24 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C3",
24 "Filter": "occ_sel=2", 25 "Filter": "occ_sel=2",
25 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C3 / UNC_P_CLOCKTICKS) * 100.", 26 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C3 / UNC_P_CLOCKTICKS) * 100.",
27 "MetricName": "power_state_occupancy.cores_c3 %",
26 "PerPkg": "1", 28 "PerPkg": "1",
27 "Unit": "PCU" 29 "Unit": "PCU"
28 }, 30 },
29 { 31 {
30 "BriefDescription": "C6 and C7. Derived from unc_p_power_state_occupancy.cores_c6", 32 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C6. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events ",
31 "Counter": "0,1,2,3", 33 "Counter": "0,1,2,3",
32 "EventCode": "0x80", 34 "EventCode": "0x80",
33 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C6", 35 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C6",
34 "Filter": "occ_sel=3", 36 "Filter": "occ_sel=3",
35 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C6 / UNC_P_CLOCKTICKS) * 100.", 37 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C6 / UNC_P_CLOCKTICKS) * 100.",
38 "MetricName": "power_state_occupancy.cores_c6 %",
36 "PerPkg": "1", 39 "PerPkg": "1",
37 "Unit": "PCU" 40 "Unit": "PCU"
38 }, 41 },
39 { 42 {
40 "BriefDescription": "External Prochot. Derived from unc_p_prochot_external_cycles", 43 "BriefDescription": "Counts the number of cycles that we are in external PROCHOT mode. This mode is triggered when a sensor off the die determines that something off-die (like DRAM) is too hot and must throttle to avoid damaging the chip",
41 "Counter": "0,1,2,3", 44 "Counter": "0,1,2,3",
42 "EventCode": "0xA", 45 "EventCode": "0xA",
43 "EventName": "UNC_P_PROCHOT_EXTERNAL_CYCLES", 46 "EventName": "UNC_P_PROCHOT_EXTERNAL_CYCLES",
44 "MetricExpr": "(UNC_P_PROCHOT_EXTERNAL_CYCLES / UNC_P_CLOCKTICKS) * 100.", 47 "MetricExpr": "(UNC_P_PROCHOT_EXTERNAL_CYCLES / UNC_P_CLOCKTICKS) * 100.",
48 "MetricName": "prochot_external_cycles %",
45 "PerPkg": "1", 49 "PerPkg": "1",
46 "Unit": "PCU" 50 "Unit": "PCU"
47 }, 51 },
48 { 52 {
49 "BriefDescription": "Thermal Strongest Upper Limit Cycles. Derived from unc_p_freq_max_limit_thermal_cycles", 53 "BriefDescription": "Counts the number of cycles when temperature is the upper limit on frequency",
50 "Counter": "0,1,2,3", 54 "Counter": "0,1,2,3",
51 "EventCode": "0x4", 55 "EventCode": "0x4",
52 "EventName": "UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES", 56 "EventName": "UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES",
53 "MetricExpr": "(UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES / UNC_P_CLOCKTICKS) * 100.", 57 "MetricExpr": "(UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES / UNC_P_CLOCKTICKS) * 100.",
58 "MetricName": "freq_max_limit_thermal_cycles %",
54 "PerPkg": "1", 59 "PerPkg": "1",
55 "Unit": "PCU" 60 "Unit": "PCU"
56 }, 61 },
57 { 62 {
58 "BriefDescription": "OS Strongest Upper Limit Cycles. Derived from unc_p_freq_max_os_cycles", 63 "BriefDescription": "Counts the number of cycles when the OS is the upper limit on frequency",
59 "Counter": "0,1,2,3", 64 "Counter": "0,1,2,3",
60 "EventCode": "0x6", 65 "EventCode": "0x6",
61 "EventName": "UNC_P_FREQ_MAX_OS_CYCLES", 66 "EventName": "UNC_P_FREQ_MAX_OS_CYCLES",
62 "MetricExpr": "(UNC_P_FREQ_MAX_OS_CYCLES / UNC_P_CLOCKTICKS) * 100.", 67 "MetricExpr": "(UNC_P_FREQ_MAX_OS_CYCLES / UNC_P_CLOCKTICKS) * 100.",
68 "MetricName": "freq_max_os_cycles %",
63 "PerPkg": "1", 69 "PerPkg": "1",
64 "Unit": "PCU" 70 "Unit": "PCU"
65 }, 71 },
66 { 72 {
67 "BriefDescription": "Power Strongest Upper Limit Cycles. Derived from unc_p_freq_max_power_cycles", 73 "BriefDescription": "Counts the number of cycles when power is the upper limit on frequency",
68 "Counter": "0,1,2,3", 74 "Counter": "0,1,2,3",
69 "EventCode": "0x5", 75 "EventCode": "0x5",
70 "EventName": "UNC_P_FREQ_MAX_POWER_CYCLES", 76 "EventName": "UNC_P_FREQ_MAX_POWER_CYCLES",
71 "MetricExpr": "(UNC_P_FREQ_MAX_POWER_CYCLES / UNC_P_CLOCKTICKS) * 100.", 77 "MetricExpr": "(UNC_P_FREQ_MAX_POWER_CYCLES / UNC_P_CLOCKTICKS) * 100.",
78 "MetricName": "freq_max_power_cycles %",
72 "PerPkg": "1", 79 "PerPkg": "1",
73 "Unit": "PCU" 80 "Unit": "PCU"
74 }, 81 },
75 { 82 {
76 "BriefDescription": "Cycles spent changing Frequency. Derived from unc_p_freq_trans_cycles", 83 "BriefDescription": "Counts the number of cycles when current is the upper limit on frequency",
77 "Counter": "0,1,2,3", 84 "Counter": "0,1,2,3",
78 "EventCode": "0x74", 85 "EventCode": "0x74",
79 "EventName": "UNC_P_FREQ_TRANS_CYCLES", 86 "EventName": "UNC_P_FREQ_TRANS_CYCLES",
80 "MetricExpr": "(UNC_P_FREQ_TRANS_CYCLES / UNC_P_CLOCKTICKS) * 100.", 87 "MetricExpr": "(UNC_P_FREQ_TRANS_CYCLES / UNC_P_CLOCKTICKS) * 100.",
88 "MetricName": "freq_trans_cycles %",
81 "PerPkg": "1", 89 "PerPkg": "1",
82 "Unit": "PCU" 90 "Unit": "PCU"
83 } 91 }
diff --git a/tools/perf/pmu-events/arch/x86/haswell/uncore.json b/tools/perf/pmu-events/arch/x86/haswell/uncore.json
new file mode 100644
index 000000000000..3ef5c21fef56
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/haswell/uncore.json
@@ -0,0 +1,374 @@
1[
2 {
3 "Unit": "CBO",
4 "EventCode": "0x22",
5 "UMask": "0x21",
6 "EventName": "UNC_CBO_XSNP_RESPONSE.MISS_EXTERNAL",
7 "BriefDescription": "An external snoop misses in some processor core.",
8 "PublicDescription": "An external snoop misses in some processor core.",
9 "Counter": "0,1",
10 "CounterMask": "0",
11 "Invert": "0",
12 "EdgeDetect": "0"
13 },
14 {
15 "Unit": "CBO",
16 "EventCode": "0x22",
17 "UMask": "0x41",
18 "EventName": "UNC_CBO_XSNP_RESPONSE.MISS_XCORE",
19 "BriefDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which misses in some processor core.",
20 "PublicDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which misses in some processor core.",
21 "Counter": "0,1",
22 "CounterMask": "0",
23 "Invert": "0",
24 "EdgeDetect": "0"
25 },
26 {
27 "Unit": "CBO",
28 "EventCode": "0x22",
29 "UMask": "0x81",
30 "EventName": "UNC_CBO_XSNP_RESPONSE.MISS_EVICTION",
31 "BriefDescription": "A cross-core snoop resulted from L3 Eviction which misses in some processor core.",
32 "PublicDescription": "A cross-core snoop resulted from L3 Eviction which misses in some processor core.",
33 "Counter": "0,1",
34 "CounterMask": "0",
35 "Invert": "0",
36 "EdgeDetect": "0"
37 },
38 {
39 "Unit": "CBO",
40 "EventCode": "0x22",
41 "UMask": "0x24",
42 "EventName": "UNC_CBO_XSNP_RESPONSE.HIT_EXTERNAL",
43 "BriefDescription": "An external snoop hits a non-modified line in some processor core.",
44 "PublicDescription": "An external snoop hits a non-modified line in some processor core.",
45 "Counter": "0,1",
46 "CounterMask": "0",
47 "Invert": "0",
48 "EdgeDetect": "0"
49 },
50 {
51 "Unit": "CBO",
52 "EventCode": "0x22",
53 "UMask": "0x44",
54 "EventName": "UNC_CBO_XSNP_RESPONSE.HIT_XCORE",
55 "BriefDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which hits a non-modified line in some processor core.",
56 "PublicDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which hits a non-modified line in some processor core.",
57 "Counter": "0,1",
58 "CounterMask": "0",
59 "Invert": "0",
60 "EdgeDetect": "0"
61 },
62 {
63 "Unit": "CBO",
64 "EventCode": "0x22",
65 "UMask": "0x84",
66 "EventName": "UNC_CBO_XSNP_RESPONSE.HIT_EVICTION",
67 "BriefDescription": "A cross-core snoop resulted from L3 Eviction which hits a non-modified line in some processor core.",
68 "PublicDescription": "A cross-core snoop resulted from L3 Eviction which hits a non-modified line in some processor core.",
69 "Counter": "0,1",
70 "CounterMask": "0",
71 "Invert": "0",
72 "EdgeDetect": "0"
73 },
74 {
75 "Unit": "CBO",
76 "EventCode": "0x22",
77 "UMask": "0x28",
78 "EventName": "UNC_CBO_XSNP_RESPONSE.HITM_EXTERNAL",
79 "BriefDescription": "An external snoop hits a modified line in some processor core.",
80 "PublicDescription": "An external snoop hits a modified line in some processor core.",
81 "Counter": "0,1",
82 "CounterMask": "0",
83 "Invert": "0",
84 "EdgeDetect": "0"
85 },
86 {
87 "Unit": "CBO",
88 "EventCode": "0x22",
89 "UMask": "0x48",
90 "EventName": "UNC_CBO_XSNP_RESPONSE.HITM_XCORE",
91 "BriefDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which hits a modified line in some processor core.",
92 "PublicDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which hits a modified line in some processor core.",
93 "Counter": "0,1",
94 "CounterMask": "0",
95 "Invert": "0",
96 "EdgeDetect": "0"
97 },
98 {
99 "Unit": "CBO",
100 "EventCode": "0x22",
101 "UMask": "0x88",
102 "EventName": "UNC_CBO_XSNP_RESPONSE.HITM_EVICTION",
103 "BriefDescription": "A cross-core snoop resulted from L3 Eviction which hits a modified line in some processor core.",
104 "PublicDescription": "A cross-core snoop resulted from L3 Eviction which hits a modified line in some processor core.",
105 "Counter": "0,1",
106 "CounterMask": "0",
107 "Invert": "0",
108 "EdgeDetect": "0"
109 },
110 {
111 "Unit": "CBO",
112 "EventCode": "0x34",
113 "UMask": "0x11",
114 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_M",
115 "BriefDescription": "L3 Lookup read request that access cache and found line in M-state.",
116 "PublicDescription": "L3 Lookup read request that access cache and found line in M-state.",
117 "Counter": "0,1",
118 "CounterMask": "0",
119 "Invert": "0",
120 "EdgeDetect": "0"
121 },
122 {
123 "Unit": "CBO",
124 "EventCode": "0x34",
125 "UMask": "0x21",
126 "EventName": "UNC_CBO_CACHE_LOOKUP.WRITE_M",
127 "BriefDescription": "L3 Lookup write request that access cache and found line in M-state.",
128 "PublicDescription": "L3 Lookup write request that access cache and found line in M-state.",
129 "Counter": "0,1",
130 "CounterMask": "0",
131 "Invert": "0",
132 "EdgeDetect": "0"
133 },
134 {
135 "Unit": "CBO",
136 "EventCode": "0x34",
137 "UMask": "0x41",
138 "EventName": "UNC_CBO_CACHE_LOOKUP.EXTSNP_M",
139 "BriefDescription": "L3 Lookup external snoop request that access cache and found line in M-state.",
140 "PublicDescription": "L3 Lookup external snoop request that access cache and found line in M-state.",
141 "Counter": "0,1",
142 "CounterMask": "0",
143 "Invert": "0",
144 "EdgeDetect": "0"
145 },
146 {
147 "Unit": "CBO",
148 "EventCode": "0x34",
149 "UMask": "0x81",
150 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_M",
151 "BriefDescription": "L3 Lookup any request that access cache and found line in M-state.",
152 "PublicDescription": "L3 Lookup any request that access cache and found line in M-state.",
153 "Counter": "0,1",
154 "CounterMask": "0",
155 "Invert": "0",
156 "EdgeDetect": "0"
157 },
158 {
159 "Unit": "CBO",
160 "EventCode": "0x34",
161 "UMask": "0x18",
162 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_I",
163 "BriefDescription": "L3 Lookup read request that access cache and found line in I-state.",
164 "PublicDescription": "L3 Lookup read request that access cache and found line in I-state.",
165 "Counter": "0,1",
166 "CounterMask": "0",
167 "Invert": "0",
168 "EdgeDetect": "0"
169 },
170 {
171 "Unit": "CBO",
172 "EventCode": "0x34",
173 "UMask": "0x28",
174 "EventName": "UNC_CBO_CACHE_LOOKUP.WRITE_I",
175 "BriefDescription": "L3 Lookup write request that access cache and found line in I-state.",
176 "PublicDescription": "L3 Lookup write request that access cache and found line in I-state.",
177 "Counter": "0,1",
178 "CounterMask": "0",
179 "Invert": "0",
180 "EdgeDetect": "0"
181 },
182 {
183 "Unit": "CBO",
184 "EventCode": "0x34",
185 "UMask": "0x48",
186 "EventName": "UNC_CBO_CACHE_LOOKUP.EXTSNP_I",
187 "BriefDescription": "L3 Lookup external snoop request that access cache and found line in I-state.",
188 "PublicDescription": "L3 Lookup external snoop request that access cache and found line in I-state.",
189 "Counter": "0,1",
190 "CounterMask": "0",
191 "Invert": "0",
192 "EdgeDetect": "0"
193 },
194 {
195 "Unit": "CBO",
196 "EventCode": "0x34",
197 "UMask": "0x88",
198 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_I",
199 "BriefDescription": "L3 Lookup any request that access cache and found line in I-state.",
200 "PublicDescription": "L3 Lookup any request that access cache and found line in I-state.",
201 "Counter": "0,1",
202 "CounterMask": "0",
203 "Invert": "0",
204 "EdgeDetect": "0"
205 },
206 {
207 "Unit": "CBO",
208 "EventCode": "0x34",
209 "UMask": "0x1f",
210 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_MESI",
211 "BriefDescription": "L3 Lookup read request that access cache and found line in any MESI-state.",
212 "PublicDescription": "L3 Lookup read request that access cache and found line in any MESI-state.",
213 "Counter": "0,1",
214 "CounterMask": "0",
215 "Invert": "0",
216 "EdgeDetect": "0"
217 },
218 {
219 "Unit": "CBO",
220 "EventCode": "0x34",
221 "UMask": "0x2f",
222 "EventName": "UNC_CBO_CACHE_LOOKUP.WRITE_MESI",
223 "BriefDescription": "L3 Lookup write request that access cache and found line in MESI-state.",
224 "PublicDescription": "L3 Lookup write request that access cache and found line in MESI-state.",
225 "Counter": "0,1",
226 "CounterMask": "0",
227 "Invert": "0",
228 "EdgeDetect": "0"
229 },
230 {
231 "Unit": "CBO",
232 "EventCode": "0x34",
233 "UMask": "0x4f",
234 "EventName": "UNC_CBO_CACHE_LOOKUP.EXTSNP_MESI",
235 "BriefDescription": "L3 Lookup external snoop request that access cache and found line in MESI-state.",
236 "PublicDescription": "L3 Lookup external snoop request that access cache and found line in MESI-state.",
237 "Counter": "0,1",
238 "CounterMask": "0",
239 "Invert": "0",
240 "EdgeDetect": "0"
241 },
242 {
243 "Unit": "CBO",
244 "EventCode": "0x34",
245 "UMask": "0x8f",
246 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_MESI",
247 "BriefDescription": "L3 Lookup any request that access cache and found line in MESI-state.",
248 "PublicDescription": "L3 Lookup any request that access cache and found line in MESI-state.",
249 "Counter": "0,1",
250 "CounterMask": "0",
251 "Invert": "0",
252 "EdgeDetect": "0"
253 },
254 {
255 "Unit": "CBO",
256 "EventCode": "0x34",
257 "UMask": "0x86",
258 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_ES",
259 "BriefDescription": "L3 Lookup any request that access cache and found line in E or S-state.",
260 "PublicDescription": "L3 Lookup any request that access cache and found line in E or S-state.",
261 "Counter": "0,1",
262 "CounterMask": "0",
263 "Invert": "0",
264 "EdgeDetect": "0"
265 },
266 {
267 "Unit": "CBO",
268 "EventCode": "0x34",
269 "UMask": "0x46",
270 "EventName": "UNC_CBO_CACHE_LOOKUP.EXTSNP_ES",
271 "BriefDescription": "L3 Lookup external snoop request that access cache and found line in E or S-state.",
272 "PublicDescription": "L3 Lookup external snoop request that access cache and found line in E or S-state.",
273 "Counter": "0,1",
274 "CounterMask": "0",
275 "Invert": "0",
276 "EdgeDetect": "0"
277 },
278 {
279 "Unit": "CBO",
280 "EventCode": "0x34",
281 "UMask": "0x16",
282 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_ES",
283 "BriefDescription": "L3 Lookup read request that access cache and found line in E or S-state.",
284 "PublicDescription": "L3 Lookup read request that access cache and found line in E or S-state.",
285 "Counter": "0,1",
286 "CounterMask": "0",
287 "Invert": "0",
288 "EdgeDetect": "0"
289 },
290 {
291 "Unit": "CBO",
292 "EventCode": "0x34",
293 "UMask": "0x26",
294 "EventName": "UNC_CBO_CACHE_LOOKUP.WRITE_ES",
295 "BriefDescription": "L3 Lookup write request that access cache and found line in E or S-state.",
296 "PublicDescription": "L3 Lookup write request that access cache and found line in E or S-state.",
297 "Counter": "0,1",
298 "CounterMask": "0",
299 "Invert": "0",
300 "EdgeDetect": "0"
301 },
302 {
303 "Unit": "iMPH-U",
304 "EventCode": "0x80",
305 "UMask": "0x01",
306 "EventName": "UNC_ARB_TRK_OCCUPANCY.ALL",
307 "BriefDescription": "Each cycle count number of all Core outgoing valid entries. Such entry is defined as valid from it's allocation till first of IDI0 or DRS0 messages is sent out. Accounts for Coherent and non-coherent traffic.",
308 "PublicDescription": "Each cycle count number of all Core outgoing valid entries. Such entry is defined as valid from it's allocation till first of IDI0 or DRS0 messages is sent out. Accounts for Coherent and non-coherent traffic.",
309 "Counter": "0",
310 "CounterMask": "0",
311 "Invert": "0",
312 "EdgeDetect": "0"
313 },
314 {
315 "Unit": "iMPH-U",
316 "EventCode": "0x81",
317 "UMask": "0x01",
318 "EventName": "UNC_ARB_TRK_REQUESTS.ALL",
319 "BriefDescription": "Total number of Core outgoing entries allocated. Accounts for Coherent and non-coherent traffic.",
320 "PublicDescription": "Total number of Core outgoing entries allocated. Accounts for Coherent and non-coherent traffic.",
321 "Counter": "0,1",
322 "CounterMask": "0",
323 "Invert": "0",
324 "EdgeDetect": "0"
325 },
326 {
327 "Unit": "iMPH-U",
328 "EventCode": "0x81",
329 "UMask": "0x20",
330 "EventName": "UNC_ARB_TRK_REQUESTS.WRITES",
331 "BriefDescription": "Number of Writes allocated - any write transactions: full/partials writes and evictions.",
332 "PublicDescription": "Number of Writes allocated - any write transactions: full/partials writes and evictions.",
333 "Counter": "0,1",
334 "CounterMask": "0",
335 "Invert": "0",
336 "EdgeDetect": "0"
337 },
338 {
339 "Unit": "iMPH-U",
340 "EventCode": "0x83",
341 "UMask": "0x01",
342 "EventName": "UNC_ARB_COH_TRK_OCCUPANCY.All",
343 "BriefDescription": "Each cycle count number of valid entries in Coherency Tracker queue from allocation till deallocation. Aperture requests (snoops) appear as NC decoded internally and become coherent (snoop L3, access memory)",
344 "PublicDescription": "Each cycle count number of valid entries in Coherency Tracker queue from allocation till deallocation. Aperture requests (snoops) appear as NC decoded internally and become coherent (snoop L3, access memory).",
345 "Counter": "0",
346 "CounterMask": "0",
347 "Invert": "0",
348 "EdgeDetect": "0"
349 },
350 {
351 "Unit": "iMPH-U",
352 "EventCode": "0x84",
353 "UMask": "0x01",
354 "EventName": "UNC_ARB_COH_TRK_REQUESTS.ALL",
355 "BriefDescription": "Number of entries allocated. Account for Any type: e.g. Snoop, Core aperture, etc.",
356 "PublicDescription": "Number of entries allocated. Account for Any type: e.g. Snoop, Core aperture, etc.",
357 "Counter": "0,1",
358 "CounterMask": "0",
359 "Invert": "0",
360 "EdgeDetect": "0"
361 },
362 {
363 "Unit": "NCU",
364 "EventCode": "0x0",
365 "UMask": "0x01",
366 "EventName": "UNC_CLOCK.SOCKET",
367 "BriefDescription": "This 48-bit fixed counter counts the UCLK cycles.",
368 "PublicDescription": "This 48-bit fixed counter counts the UCLK cycles.",
369 "Counter": "FIXED",
370 "CounterMask": "0",
371 "Invert": "0",
372 "EdgeDetect": "0"
373 }
374] \ No newline at end of file
diff --git a/tools/perf/pmu-events/arch/x86/haswellx/uncore-cache.json b/tools/perf/pmu-events/arch/x86/haswellx/uncore-cache.json
index 076459c51d4e..58ed6d33d1f4 100644
--- a/tools/perf/pmu-events/arch/x86/haswellx/uncore-cache.json
+++ b/tools/perf/pmu-events/arch/x86/haswellx/uncore-cache.json
@@ -1,13 +1,13 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "Uncore cache clock ticks. Derived from unc_c_clockticks", 3 "BriefDescription": "Uncore cache clock ticks",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventName": "UNC_C_CLOCKTICKS", 5 "EventName": "UNC_C_CLOCKTICKS",
6 "PerPkg": "1", 6 "PerPkg": "1",
7 "Unit": "CBO" 7 "Unit": "CBO"
8 }, 8 },
9 { 9 {
10 "BriefDescription": "All LLC Misses (code+ data rd + data wr - including demand and prefetch). Derived from unc_c_llc_lookup.any", 10 "BriefDescription": "All LLC Misses (code+ data rd + data wr - including demand and prefetch)",
11 "Counter": "0,1,2,3", 11 "Counter": "0,1,2,3",
12 "EventCode": "0x34", 12 "EventCode": "0x34",
13 "EventName": "UNC_C_LLC_LOOKUP.ANY", 13 "EventName": "UNC_C_LLC_LOOKUP.ANY",
@@ -18,7 +18,7 @@
18 "Unit": "CBO" 18 "Unit": "CBO"
19 }, 19 },
20 { 20 {
21 "BriefDescription": "M line evictions from LLC (writebacks to memory). Derived from unc_c_llc_victims.m_state", 21 "BriefDescription": "M line evictions from LLC (writebacks to memory)",
22 "Counter": "0,1,2,3", 22 "Counter": "0,1,2,3",
23 "EventCode": "0x37", 23 "EventCode": "0x37",
24 "EventName": "UNC_C_LLC_VICTIMS.M_STATE", 24 "EventName": "UNC_C_LLC_VICTIMS.M_STATE",
@@ -212,7 +212,7 @@
212 "Unit": "CBO" 212 "Unit": "CBO"
213 }, 213 },
214 { 214 {
215 "BriefDescription": "read requests to home agent. Derived from unc_h_requests.reads", 215 "BriefDescription": "read requests to home agent",
216 "Counter": "0,1,2,3", 216 "Counter": "0,1,2,3",
217 "EventCode": "0x1", 217 "EventCode": "0x1",
218 "EventName": "UNC_H_REQUESTS.READS", 218 "EventName": "UNC_H_REQUESTS.READS",
@@ -221,7 +221,7 @@
221 "Unit": "HA" 221 "Unit": "HA"
222 }, 222 },
223 { 223 {
224 "BriefDescription": "read requests to local home agent. Derived from unc_h_requests.reads_local", 224 "BriefDescription": "read requests to local home agent",
225 "Counter": "0,1,2,3", 225 "Counter": "0,1,2,3",
226 "EventCode": "0x1", 226 "EventCode": "0x1",
227 "EventName": "UNC_H_REQUESTS.READS_LOCAL", 227 "EventName": "UNC_H_REQUESTS.READS_LOCAL",
@@ -230,7 +230,7 @@
230 "Unit": "HA" 230 "Unit": "HA"
231 }, 231 },
232 { 232 {
233 "BriefDescription": "read requests to remote home agent. Derived from unc_h_requests.reads_remote", 233 "BriefDescription": "read requests to remote home agent",
234 "Counter": "0,1,2,3", 234 "Counter": "0,1,2,3",
235 "EventCode": "0x1", 235 "EventCode": "0x1",
236 "EventName": "UNC_H_REQUESTS.READS_REMOTE", 236 "EventName": "UNC_H_REQUESTS.READS_REMOTE",
@@ -239,7 +239,7 @@
239 "Unit": "HA" 239 "Unit": "HA"
240 }, 240 },
241 { 241 {
242 "BriefDescription": "write requests to home agent. Derived from unc_h_requests.writes", 242 "BriefDescription": "write requests to home agent",
243 "Counter": "0,1,2,3", 243 "Counter": "0,1,2,3",
244 "EventCode": "0x1", 244 "EventCode": "0x1",
245 "EventName": "UNC_H_REQUESTS.WRITES", 245 "EventName": "UNC_H_REQUESTS.WRITES",
@@ -248,7 +248,7 @@
248 "Unit": "HA" 248 "Unit": "HA"
249 }, 249 },
250 { 250 {
251 "BriefDescription": "write requests to local home agent. Derived from unc_h_requests.writes_local", 251 "BriefDescription": "write requests to local home agent",
252 "Counter": "0,1,2,3", 252 "Counter": "0,1,2,3",
253 "EventCode": "0x1", 253 "EventCode": "0x1",
254 "EventName": "UNC_H_REQUESTS.WRITES_LOCAL", 254 "EventName": "UNC_H_REQUESTS.WRITES_LOCAL",
@@ -257,7 +257,7 @@
257 "Unit": "HA" 257 "Unit": "HA"
258 }, 258 },
259 { 259 {
260 "BriefDescription": "write requests to remote home agent. Derived from unc_h_requests.writes_remote", 260 "BriefDescription": "write requests to remote home agent",
261 "Counter": "0,1,2,3", 261 "Counter": "0,1,2,3",
262 "EventCode": "0x1", 262 "EventCode": "0x1",
263 "EventName": "UNC_H_REQUESTS.WRITES_REMOTE", 263 "EventName": "UNC_H_REQUESTS.WRITES_REMOTE",
@@ -266,7 +266,7 @@
266 "Unit": "HA" 266 "Unit": "HA"
267 }, 267 },
268 { 268 {
269 "BriefDescription": "Conflict requests (requests for same address from multiple agents simultaneously). Derived from unc_h_snoop_resp.rspcnflct", 269 "BriefDescription": "Conflict requests (requests for same address from multiple agents simultaneously)",
270 "Counter": "0,1,2,3", 270 "Counter": "0,1,2,3",
271 "EventCode": "0x21", 271 "EventCode": "0x21",
272 "EventName": "UNC_H_SNOOP_RESP.RSPCNFLCT", 272 "EventName": "UNC_H_SNOOP_RESP.RSPCNFLCT",
@@ -275,7 +275,7 @@
275 "Unit": "HA" 275 "Unit": "HA"
276 }, 276 },
277 { 277 {
278 "BriefDescription": "M line forwarded from remote cache along with writeback to memory. Derived from unc_h_snoop_resp.rsp_fwd_wb", 278 "BriefDescription": "M line forwarded from remote cache along with writeback to memory",
279 "Counter": "0,1,2,3", 279 "Counter": "0,1,2,3",
280 "EventCode": "0x21", 280 "EventCode": "0x21",
281 "EventName": "UNC_H_SNOOP_RESP.RSP_FWD_WB", 281 "EventName": "UNC_H_SNOOP_RESP.RSP_FWD_WB",
@@ -285,7 +285,7 @@
285 "Unit": "HA" 285 "Unit": "HA"
286 }, 286 },
287 { 287 {
288 "BriefDescription": "M line forwarded from remote cache with no writeback to memory. Derived from unc_h_snoop_resp.rspifwd", 288 "BriefDescription": "M line forwarded from remote cache with no writeback to memory",
289 "Counter": "0,1,2,3", 289 "Counter": "0,1,2,3",
290 "EventCode": "0x21", 290 "EventCode": "0x21",
291 "EventName": "UNC_H_SNOOP_RESP.RSPIFWD", 291 "EventName": "UNC_H_SNOOP_RESP.RSPIFWD",
@@ -295,7 +295,7 @@
295 "Unit": "HA" 295 "Unit": "HA"
296 }, 296 },
297 { 297 {
298 "BriefDescription": "Shared line response from remote cache. Derived from unc_h_snoop_resp.rsps", 298 "BriefDescription": "Shared line response from remote cache",
299 "Counter": "0,1,2,3", 299 "Counter": "0,1,2,3",
300 "EventCode": "0x21", 300 "EventCode": "0x21",
301 "EventName": "UNC_H_SNOOP_RESP.RSPS", 301 "EventName": "UNC_H_SNOOP_RESP.RSPS",
@@ -305,7 +305,7 @@
305 "Unit": "HA" 305 "Unit": "HA"
306 }, 306 },
307 { 307 {
308 "BriefDescription": "Shared line forwarded from remote cache. Derived from unc_h_snoop_resp.rspsfwd", 308 "BriefDescription": "Shared line forwarded from remote cache",
309 "Counter": "0,1,2,3", 309 "Counter": "0,1,2,3",
310 "EventCode": "0x21", 310 "EventCode": "0x21",
311 "EventName": "UNC_H_SNOOP_RESP.RSPSFWD", 311 "EventName": "UNC_H_SNOOP_RESP.RSPSFWD",
diff --git a/tools/perf/pmu-events/arch/x86/haswellx/uncore-interconnect.json b/tools/perf/pmu-events/arch/x86/haswellx/uncore-interconnect.json
index 39387f7909b2..824961318c1e 100644
--- a/tools/perf/pmu-events/arch/x86/haswellx/uncore-interconnect.json
+++ b/tools/perf/pmu-events/arch/x86/haswellx/uncore-interconnect.json
@@ -1,6 +1,6 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "QPI clock ticks. Derived from unc_q_clockticks", 3 "BriefDescription": "QPI clock ticks",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventCode": "0x14", 5 "EventCode": "0x14",
6 "EventName": "UNC_Q_CLOCKTICKS", 6 "EventName": "UNC_Q_CLOCKTICKS",
@@ -10,7 +10,7 @@
10 { 10 {
11 "BriefDescription": "Number of data flits transmitted . Derived from unc_q_txl_flits_g0.data", 11 "BriefDescription": "Number of data flits transmitted . Derived from unc_q_txl_flits_g0.data",
12 "Counter": "0,1,2,3", 12 "Counter": "0,1,2,3",
13 "EventName": "UNC_Q_TxL_FLITS_G0.DATA", 13 "EventName": "QPI_DATA_BANDWIDTH_TX",
14 "PerPkg": "1", 14 "PerPkg": "1",
15 "ScaleUnit": "8Bytes", 15 "ScaleUnit": "8Bytes",
16 "UMask": "0x2", 16 "UMask": "0x2",
@@ -19,7 +19,7 @@
19 { 19 {
20 "BriefDescription": "Number of non data (control) flits transmitted . Derived from unc_q_txl_flits_g0.non_data", 20 "BriefDescription": "Number of non data (control) flits transmitted . Derived from unc_q_txl_flits_g0.non_data",
21 "Counter": "0,1,2,3", 21 "Counter": "0,1,2,3",
22 "EventName": "UNC_Q_TxL_FLITS_G0.NON_DATA", 22 "EventName": "QPI_CTL_BANDWIDTH_TX",
23 "PerPkg": "1", 23 "PerPkg": "1",
24 "ScaleUnit": "8Bytes", 24 "ScaleUnit": "8Bytes",
25 "UMask": "0x4", 25 "UMask": "0x4",
diff --git a/tools/perf/pmu-events/arch/x86/haswellx/uncore-memory.json b/tools/perf/pmu-events/arch/x86/haswellx/uncore-memory.json
index d17dc235f734..66eed399724c 100644
--- a/tools/perf/pmu-events/arch/x86/haswellx/uncore-memory.json
+++ b/tools/perf/pmu-events/arch/x86/haswellx/uncore-memory.json
@@ -3,7 +3,7 @@
3 "BriefDescription": "read requests to memory controller. Derived from unc_m_cas_count.rd", 3 "BriefDescription": "read requests to memory controller. Derived from unc_m_cas_count.rd",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventCode": "0x4", 5 "EventCode": "0x4",
6 "EventName": "UNC_M_CAS_COUNT.RD", 6 "EventName": "LLC_MISSES.MEM_READ",
7 "PerPkg": "1", 7 "PerPkg": "1",
8 "ScaleUnit": "64Bytes", 8 "ScaleUnit": "64Bytes",
9 "UMask": "0x3", 9 "UMask": "0x3",
@@ -13,48 +13,51 @@
13 "BriefDescription": "write requests to memory controller. Derived from unc_m_cas_count.wr", 13 "BriefDescription": "write requests to memory controller. Derived from unc_m_cas_count.wr",
14 "Counter": "0,1,2,3", 14 "Counter": "0,1,2,3",
15 "EventCode": "0x4", 15 "EventCode": "0x4",
16 "EventName": "UNC_M_CAS_COUNT.WR", 16 "EventName": "LLC_MISSES.MEM_WRITE",
17 "PerPkg": "1", 17 "PerPkg": "1",
18 "ScaleUnit": "64Bytes", 18 "ScaleUnit": "64Bytes",
19 "UMask": "0xC", 19 "UMask": "0xC",
20 "Unit": "iMC" 20 "Unit": "iMC"
21 }, 21 },
22 { 22 {
23 "BriefDescription": "Memory controller clock ticks. Derived from unc_m_clockticks", 23 "BriefDescription": "Memory controller clock ticks",
24 "Counter": "0,1,2,3", 24 "Counter": "0,1,2,3",
25 "EventName": "UNC_M_CLOCKTICKS", 25 "EventName": "UNC_M_CLOCKTICKS",
26 "PerPkg": "1", 26 "PerPkg": "1",
27 "Unit": "iMC" 27 "Unit": "iMC"
28 }, 28 },
29 { 29 {
30 "BriefDescription": "Cycles where DRAM ranks are in power down (CKE) mode. Derived from unc_m_power_channel_ppd", 30 "BriefDescription": "Cycles where DRAM ranks are in power down (CKE) mode",
31 "Counter": "0,1,2,3", 31 "Counter": "0,1,2,3",
32 "EventCode": "0x85", 32 "EventCode": "0x85",
33 "EventName": "UNC_M_POWER_CHANNEL_PPD", 33 "EventName": "UNC_M_POWER_CHANNEL_PPD",
34 "MetricExpr": "(UNC_M_POWER_CHANNEL_PPD / UNC_M_CLOCKTICKS) * 100.", 34 "MetricExpr": "(UNC_M_POWER_CHANNEL_PPD / UNC_M_CLOCKTICKS) * 100.",
35 "MetricName": "power_channel_ppd %",
35 "PerPkg": "1", 36 "PerPkg": "1",
36 "Unit": "iMC" 37 "Unit": "iMC"
37 }, 38 },
38 { 39 {
39 "BriefDescription": "Cycles all ranks are in critical thermal throttle. Derived from unc_m_power_critical_throttle_cycles", 40 "BriefDescription": "Cycles all ranks are in critical thermal throttle",
40 "Counter": "0,1,2,3", 41 "Counter": "0,1,2,3",
41 "EventCode": "0x86", 42 "EventCode": "0x86",
42 "EventName": "UNC_M_POWER_CRITICAL_THROTTLE_CYCLES", 43 "EventName": "UNC_M_POWER_CRITICAL_THROTTLE_CYCLES",
43 "MetricExpr": "(UNC_M_POWER_CRITICAL_THROTTLE_CYCLES / UNC_M_CLOCKTICKS) * 100.", 44 "MetricExpr": "(UNC_M_POWER_CRITICAL_THROTTLE_CYCLES / UNC_M_CLOCKTICKS) * 100.",
45 "MetricName": "power_critical_throttle_cycles %",
44 "PerPkg": "1", 46 "PerPkg": "1",
45 "Unit": "iMC" 47 "Unit": "iMC"
46 }, 48 },
47 { 49 {
48 "BriefDescription": "Cycles Memory is in self refresh power mode. Derived from unc_m_power_self_refresh", 50 "BriefDescription": "Cycles Memory is in self refresh power mode",
49 "Counter": "0,1,2,3", 51 "Counter": "0,1,2,3",
50 "EventCode": "0x43", 52 "EventCode": "0x43",
51 "EventName": "UNC_M_POWER_SELF_REFRESH", 53 "EventName": "UNC_M_POWER_SELF_REFRESH",
52 "MetricExpr": "(UNC_M_POWER_SELF_REFRESH / UNC_M_CLOCKTICKS) * 100.", 54 "MetricExpr": "(UNC_M_POWER_SELF_REFRESH / UNC_M_CLOCKTICKS) * 100.",
55 "MetricName": "power_self_refresh %",
53 "PerPkg": "1", 56 "PerPkg": "1",
54 "Unit": "iMC" 57 "Unit": "iMC"
55 }, 58 },
56 { 59 {
57 "BriefDescription": "Pre-charges due to page misses. Derived from unc_m_pre_count.page_miss", 60 "BriefDescription": "Pre-charges due to page misses",
58 "Counter": "0,1,2,3", 61 "Counter": "0,1,2,3",
59 "EventCode": "0x2", 62 "EventCode": "0x2",
60 "EventName": "UNC_M_PRE_COUNT.PAGE_MISS", 63 "EventName": "UNC_M_PRE_COUNT.PAGE_MISS",
@@ -63,7 +66,7 @@
63 "Unit": "iMC" 66 "Unit": "iMC"
64 }, 67 },
65 { 68 {
66 "BriefDescription": "Pre-charge for reads. Derived from unc_m_pre_count.rd", 69 "BriefDescription": "Pre-charge for reads",
67 "Counter": "0,1,2,3", 70 "Counter": "0,1,2,3",
68 "EventCode": "0x2", 71 "EventCode": "0x2",
69 "EventName": "UNC_M_PRE_COUNT.RD", 72 "EventName": "UNC_M_PRE_COUNT.RD",
@@ -72,7 +75,7 @@
72 "Unit": "iMC" 75 "Unit": "iMC"
73 }, 76 },
74 { 77 {
75 "BriefDescription": "Pre-charge for writes. Derived from unc_m_pre_count.wr", 78 "BriefDescription": "Pre-charge for writes",
76 "Counter": "0,1,2,3", 79 "Counter": "0,1,2,3",
77 "EventCode": "0x2", 80 "EventCode": "0x2",
78 "EventName": "UNC_M_PRE_COUNT.WR", 81 "EventName": "UNC_M_PRE_COUNT.WR",
diff --git a/tools/perf/pmu-events/arch/x86/haswellx/uncore-power.json b/tools/perf/pmu-events/arch/x86/haswellx/uncore-power.json
index b44d43088bbb..dd1b95655d1d 100644
--- a/tools/perf/pmu-events/arch/x86/haswellx/uncore-power.json
+++ b/tools/perf/pmu-events/arch/x86/haswellx/uncore-power.json
@@ -1,83 +1,91 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "PCU clock ticks. Use to get percentages of PCU cycles events. Derived from unc_p_clockticks", 3 "BriefDescription": "PCU clock ticks. Use to get percentages of PCU cycles events",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventName": "UNC_P_CLOCKTICKS", 5 "EventName": "UNC_P_CLOCKTICKS",
6 "PerPkg": "1", 6 "PerPkg": "1",
7 "Unit": "PCU" 7 "Unit": "PCU"
8 }, 8 },
9 { 9 {
10 "BriefDescription": "C0 and C1. Derived from unc_p_power_state_occupancy.cores_c0", 10 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C0. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details",
11 "Counter": "0,1,2,3", 11 "Counter": "0,1,2,3",
12 "EventCode": "0x80", 12 "EventCode": "0x80",
13 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C0", 13 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C0",
14 "Filter": "occ_sel=1", 14 "Filter": "occ_sel=1",
15 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C0 / UNC_P_CLOCKTICKS) * 100.", 15 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C0 / UNC_P_CLOCKTICKS) * 100.",
16 "MetricName": "power_state_occupancy.cores_c0 %",
16 "PerPkg": "1", 17 "PerPkg": "1",
17 "Unit": "PCU" 18 "Unit": "PCU"
18 }, 19 },
19 { 20 {
20 "BriefDescription": "C3. Derived from unc_p_power_state_occupancy.cores_c3", 21 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C3. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details",
21 "Counter": "0,1,2,3", 22 "Counter": "0,1,2,3",
22 "EventCode": "0x80", 23 "EventCode": "0x80",
23 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C3", 24 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C3",
24 "Filter": "occ_sel=2", 25 "Filter": "occ_sel=2",
25 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C3 / UNC_P_CLOCKTICKS) * 100.", 26 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C3 / UNC_P_CLOCKTICKS) * 100.",
27 "MetricName": "power_state_occupancy.cores_c3 %",
26 "PerPkg": "1", 28 "PerPkg": "1",
27 "Unit": "PCU" 29 "Unit": "PCU"
28 }, 30 },
29 { 31 {
30 "BriefDescription": "C6 and C7. Derived from unc_p_power_state_occupancy.cores_c6", 32 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C6. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events ",
31 "Counter": "0,1,2,3", 33 "Counter": "0,1,2,3",
32 "EventCode": "0x80", 34 "EventCode": "0x80",
33 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C6", 35 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C6",
34 "Filter": "occ_sel=3", 36 "Filter": "occ_sel=3",
35 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C6 / UNC_P_CLOCKTICKS) * 100.", 37 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C6 / UNC_P_CLOCKTICKS) * 100.",
38 "MetricName": "power_state_occupancy.cores_c6 %",
36 "PerPkg": "1", 39 "PerPkg": "1",
37 "Unit": "PCU" 40 "Unit": "PCU"
38 }, 41 },
39 { 42 {
40 "BriefDescription": "External Prochot. Derived from unc_p_prochot_external_cycles", 43 "BriefDescription": "Counts the number of cycles that we are in external PROCHOT mode. This mode is triggered when a sensor off the die determines that something off-die (like DRAM) is too hot and must throttle to avoid damaging the chip",
41 "Counter": "0,1,2,3", 44 "Counter": "0,1,2,3",
42 "EventCode": "0xA", 45 "EventCode": "0xA",
43 "EventName": "UNC_P_PROCHOT_EXTERNAL_CYCLES", 46 "EventName": "UNC_P_PROCHOT_EXTERNAL_CYCLES",
44 "MetricExpr": "(UNC_P_PROCHOT_EXTERNAL_CYCLES / UNC_P_CLOCKTICKS) * 100.", 47 "MetricExpr": "(UNC_P_PROCHOT_EXTERNAL_CYCLES / UNC_P_CLOCKTICKS) * 100.",
48 "MetricName": "prochot_external_cycles %",
45 "PerPkg": "1", 49 "PerPkg": "1",
46 "Unit": "PCU" 50 "Unit": "PCU"
47 }, 51 },
48 { 52 {
49 "BriefDescription": "Thermal Strongest Upper Limit Cycles. Derived from unc_p_freq_max_limit_thermal_cycles", 53 "BriefDescription": "Counts the number of cycles when temperature is the upper limit on frequency",
50 "Counter": "0,1,2,3", 54 "Counter": "0,1,2,3",
51 "EventCode": "0x4", 55 "EventCode": "0x4",
52 "EventName": "UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES", 56 "EventName": "UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES",
53 "MetricExpr": "(UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES / UNC_P_CLOCKTICKS) * 100.", 57 "MetricExpr": "(UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES / UNC_P_CLOCKTICKS) * 100.",
58 "MetricName": "freq_max_limit_thermal_cycles %",
54 "PerPkg": "1", 59 "PerPkg": "1",
55 "Unit": "PCU" 60 "Unit": "PCU"
56 }, 61 },
57 { 62 {
58 "BriefDescription": "OS Strongest Upper Limit Cycles. Derived from unc_p_freq_max_os_cycles", 63 "BriefDescription": "Counts the number of cycles when the OS is the upper limit on frequency",
59 "Counter": "0,1,2,3", 64 "Counter": "0,1,2,3",
60 "EventCode": "0x6", 65 "EventCode": "0x6",
61 "EventName": "UNC_P_FREQ_MAX_OS_CYCLES", 66 "EventName": "UNC_P_FREQ_MAX_OS_CYCLES",
62 "MetricExpr": "(UNC_P_FREQ_MAX_OS_CYCLES / UNC_P_CLOCKTICKS) * 100.", 67 "MetricExpr": "(UNC_P_FREQ_MAX_OS_CYCLES / UNC_P_CLOCKTICKS) * 100.",
68 "MetricName": "freq_max_os_cycles %",
63 "PerPkg": "1", 69 "PerPkg": "1",
64 "Unit": "PCU" 70 "Unit": "PCU"
65 }, 71 },
66 { 72 {
67 "BriefDescription": "Power Strongest Upper Limit Cycles. Derived from unc_p_freq_max_power_cycles", 73 "BriefDescription": "Counts the number of cycles when power is the upper limit on frequency",
68 "Counter": "0,1,2,3", 74 "Counter": "0,1,2,3",
69 "EventCode": "0x5", 75 "EventCode": "0x5",
70 "EventName": "UNC_P_FREQ_MAX_POWER_CYCLES", 76 "EventName": "UNC_P_FREQ_MAX_POWER_CYCLES",
71 "MetricExpr": "(UNC_P_FREQ_MAX_POWER_CYCLES / UNC_P_CLOCKTICKS) * 100.", 77 "MetricExpr": "(UNC_P_FREQ_MAX_POWER_CYCLES / UNC_P_CLOCKTICKS) * 100.",
78 "MetricName": "freq_max_power_cycles %",
72 "PerPkg": "1", 79 "PerPkg": "1",
73 "Unit": "PCU" 80 "Unit": "PCU"
74 }, 81 },
75 { 82 {
76 "BriefDescription": "Cycles spent changing Frequency. Derived from unc_p_freq_trans_cycles", 83 "BriefDescription": "Counts the number of cycles when current is the upper limit on frequency",
77 "Counter": "0,1,2,3", 84 "Counter": "0,1,2,3",
78 "EventCode": "0x74", 85 "EventCode": "0x74",
79 "EventName": "UNC_P_FREQ_TRANS_CYCLES", 86 "EventName": "UNC_P_FREQ_TRANS_CYCLES",
80 "MetricExpr": "(UNC_P_FREQ_TRANS_CYCLES / UNC_P_CLOCKTICKS) * 100.", 87 "MetricExpr": "(UNC_P_FREQ_TRANS_CYCLES / UNC_P_CLOCKTICKS) * 100.",
88 "MetricName": "freq_trans_cycles %",
81 "PerPkg": "1", 89 "PerPkg": "1",
82 "Unit": "PCU" 90 "Unit": "PCU"
83 } 91 }
diff --git a/tools/perf/pmu-events/arch/x86/ivybridge/uncore.json b/tools/perf/pmu-events/arch/x86/ivybridge/uncore.json
new file mode 100644
index 000000000000..42c70eed05a2
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/ivybridge/uncore.json
@@ -0,0 +1,314 @@
1[
2 {
3 "Unit": "CBO",
4 "EventCode": "0x22",
5 "UMask": "0x01",
6 "EventName": "UNC_CBO_XSNP_RESPONSE.MISS",
7 "BriefDescription": "A snoop misses in some processor core.",
8 "PublicDescription": "A snoop misses in some processor core.",
9 "Counter": "0,1",
10 "CounterMask": "0",
11 "Invert": "0",
12 "EdgeDetect": "0"
13 },
14 {
15 "Unit": "CBO",
16 "EventCode": "0x22",
17 "UMask": "0x02",
18 "EventName": "UNC_CBO_XSNP_RESPONSE.INVAL",
19 "BriefDescription": "A snoop invalidates a non-modified line in some processor core.",
20 "PublicDescription": "A snoop invalidates a non-modified line in some processor core.",
21 "Counter": "0,1",
22 "CounterMask": "0",
23 "Invert": "0",
24 "EdgeDetect": "0"
25 },
26 {
27 "Unit": "CBO",
28 "EventCode": "0x22",
29 "UMask": "0x04",
30 "EventName": "UNC_CBO_XSNP_RESPONSE.HIT",
31 "BriefDescription": "A snoop hits a non-modified line in some processor core.",
32 "PublicDescription": "A snoop hits a non-modified line in some processor core.",
33 "Counter": "0,1",
34 "CounterMask": "0",
35 "Invert": "0",
36 "EdgeDetect": "0"
37 },
38 {
39 "Unit": "CBO",
40 "EventCode": "0x22",
41 "UMask": "0x08",
42 "EventName": "UNC_CBO_XSNP_RESPONSE.HITM",
43 "BriefDescription": "A snoop hits a modified line in some processor core.",
44 "PublicDescription": "A snoop hits a modified line in some processor core.",
45 "Counter": "0,1",
46 "CounterMask": "0",
47 "Invert": "0",
48 "EdgeDetect": "0"
49 },
50 {
51 "Unit": "CBO",
52 "EventCode": "0x22",
53 "UMask": "0x10",
54 "EventName": "UNC_CBO_XSNP_RESPONSE.INVAL_M",
55 "BriefDescription": "A snoop invalidates a modified line in some processor core.",
56 "PublicDescription": "A snoop invalidates a modified line in some processor core.",
57 "Counter": "0,1",
58 "CounterMask": "0",
59 "Invert": "0",
60 "EdgeDetect": "0"
61 },
62 {
63 "Unit": "CBO",
64 "EventCode": "0x22",
65 "UMask": "0x20",
66 "EventName": "UNC_CBO_XSNP_RESPONSE.EXTERNAL_FILTER",
67 "BriefDescription": "Filter on cross-core snoops initiated by this Cbox due to external snoop request.",
68 "PublicDescription": "Filter on cross-core snoops initiated by this Cbox due to external snoop request.",
69 "Counter": "0,1",
70 "CounterMask": "0",
71 "Invert": "0",
72 "EdgeDetect": "0"
73 },
74 {
75 "Unit": "CBO",
76 "EventCode": "0x22",
77 "UMask": "0x40",
78 "EventName": "UNC_CBO_XSNP_RESPONSE.XCORE_FILTER",
79 "BriefDescription": "Filter on cross-core snoops initiated by this Cbox due to processor core memory request.",
80 "PublicDescription": "Filter on cross-core snoops initiated by this Cbox due to processor core memory request.",
81 "Counter": "0,1",
82 "CounterMask": "0",
83 "Invert": "0",
84 "EdgeDetect": "0"
85 },
86 {
87 "Unit": "CBO",
88 "EventCode": "0x22",
89 "UMask": "0x80",
90 "EventName": "UNC_CBO_XSNP_RESPONSE.EVICTION_FILTER",
91 "BriefDescription": "Filter on cross-core snoops initiated by this Cbox due to LLC eviction.",
92 "PublicDescription": "Filter on cross-core snoops initiated by this Cbox due to LLC eviction.",
93 "Counter": "0,1",
94 "CounterMask": "0",
95 "Invert": "0",
96 "EdgeDetect": "0"
97 },
98 {
99 "Unit": "CBO",
100 "EventCode": "0x34",
101 "UMask": "0x01",
102 "EventName": "UNC_CBO_CACHE_LOOKUP.M",
103 "BriefDescription": "LLC lookup request that access cache and found line in M-state.",
104 "PublicDescription": "LLC lookup request that access cache and found line in M-state.",
105 "Counter": "0,1",
106 "CounterMask": "0",
107 "Invert": "0",
108 "EdgeDetect": "0"
109 },
110 {
111 "Unit": "CBO",
112 "EventCode": "0x34",
113 "UMask": "0x02",
114 "EventName": "UNC_CBO_CACHE_LOOKUP.E",
115 "BriefDescription": "LLC lookup request that access cache and found line in E-state.",
116 "PublicDescription": "LLC lookup request that access cache and found line in E-state.",
117 "Counter": "0,1",
118 "CounterMask": "0",
119 "Invert": "0",
120 "EdgeDetect": "0"
121 },
122 {
123 "Unit": "CBO",
124 "EventCode": "0x34",
125 "UMask": "0x04",
126 "EventName": "UNC_CBO_CACHE_LOOKUP.S",
127 "BriefDescription": "LLC lookup request that access cache and found line in S-state.",
128 "PublicDescription": "LLC lookup request that access cache and found line in S-state.",
129 "Counter": "0,1",
130 "CounterMask": "0",
131 "Invert": "0",
132 "EdgeDetect": "0"
133 },
134 {
135 "Unit": "CBO",
136 "EventCode": "0x34",
137 "UMask": "0x08",
138 "EventName": "UNC_CBO_CACHE_LOOKUP.I",
139 "BriefDescription": "LLC lookup request that access cache and found line in I-state.",
140 "PublicDescription": "LLC lookup request that access cache and found line in I-state.",
141 "Counter": "0,1",
142 "CounterMask": "0",
143 "Invert": "0",
144 "EdgeDetect": "0"
145 },
146 {
147 "Unit": "CBO",
148 "EventCode": "0x34",
149 "UMask": "0x10",
150 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_FILTER",
151 "BriefDescription": "Filter on processor core initiated cacheable read requests.",
152 "PublicDescription": "Filter on processor core initiated cacheable read requests.",
153 "Counter": "0,1",
154 "CounterMask": "0",
155 "Invert": "0",
156 "EdgeDetect": "0"
157 },
158 {
159 "Unit": "CBO",
160 "EventCode": "0x34",
161 "UMask": "0x20",
162 "EventName": "UNC_CBO_CACHE_LOOKUP.WRITE_FILTER",
163 "BriefDescription": "Filter on processor core initiated cacheable write requests.",
164 "PublicDescription": "Filter on processor core initiated cacheable write requests.",
165 "Counter": "0,1",
166 "CounterMask": "0",
167 "Invert": "0",
168 "EdgeDetect": "0"
169 },
170 {
171 "Unit": "CBO",
172 "EventCode": "0x34",
173 "UMask": "0x40",
174 "EventName": "UNC_CBO_CACHE_LOOKUP.EXTSNP_FILTER",
175 "BriefDescription": "Filter on external snoop requests.",
176 "PublicDescription": "Filter on external snoop requests.",
177 "Counter": "0,1",
178 "CounterMask": "0",
179 "Invert": "0",
180 "EdgeDetect": "0"
181 },
182 {
183 "Unit": "CBO",
184 "EventCode": "0x34",
185 "UMask": "0x80",
186 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_REQUEST_FILTER",
187 "BriefDescription": "Filter on any IRQ or IPQ initiated requests including uncacheable, non-coherent requests.",
188 "PublicDescription": "Filter on any IRQ or IPQ initiated requests including uncacheable, non-coherent requests.",
189 "Counter": "0,1",
190 "CounterMask": "0",
191 "Invert": "0",
192 "EdgeDetect": "0"
193 },
194 {
195 "Unit": "ARB",
196 "EventCode": "0x80",
197 "UMask": "0x01",
198 "EventName": "UNC_ARB_TRK_OCCUPANCY.ALL",
199 "BriefDescription": "Counts cycles weighted by the number of requests waiting for data returning from the memory controller. Accounts for coherent and non-coherent requests initiated by IA cores, processor graphic units, or LLC.",
200 "PublicDescription": "Counts cycles weighted by the number of requests waiting for data returning from the memory controller. Accounts for coherent and non-coherent requests initiated by IA cores, processor graphic units, or LLC.",
201 "Counter": "0",
202 "CounterMask": "0",
203 "Invert": "0",
204 "EdgeDetect": "0"
205 },
206 {
207 "Unit": "ARB",
208 "EventCode": "0x81",
209 "UMask": "0x01",
210 "EventName": "UNC_ARB_TRK_REQUESTS.ALL",
211 "BriefDescription": "Counts the number of coherent and in-coherent requests initiated by IA cores, processor graphic units, or LLC.",
212 "PublicDescription": "Counts the number of coherent and in-coherent requests initiated by IA cores, processor graphic units, or LLC.",
213 "Counter": "0,1",
214 "CounterMask": "0",
215 "Invert": "0",
216 "EdgeDetect": "0"
217 },
218 {
219 "Unit": "ARB",
220 "EventCode": "0x81",
221 "UMask": "0x20",
222 "EventName": "UNC_ARB_TRK_REQUESTS.WRITES",
223 "BriefDescription": "Counts the number of allocated write entries, include full, partial, and LLC evictions.",
224 "PublicDescription": "Counts the number of allocated write entries, include full, partial, and LLC evictions.",
225 "Counter": "0,1",
226 "CounterMask": "0",
227 "Invert": "0",
228 "EdgeDetect": "0"
229 },
230 {
231 "Unit": "ARB",
232 "EventCode": "0x81",
233 "UMask": "0x80",
234 "EventName": "UNC_ARB_TRK_REQUESTS.EVICTIONS",
235 "BriefDescription": "Counts the number of LLC evictions allocated.",
236 "PublicDescription": "Counts the number of LLC evictions allocated.",
237 "Counter": "0,1",
238 "CounterMask": "0",
239 "Invert": "0",
240 "EdgeDetect": "0"
241 },
242 {
243 "Unit": "ARB",
244 "EventCode": "0x83",
245 "UMask": "0x01",
246 "EventName": "UNC_ARB_COH_TRK_OCCUPANCY.ALL",
247 "BriefDescription": "Cycles weighted by number of requests pending in Coherency Tracker.",
248 "PublicDescription": "Cycles weighted by number of requests pending in Coherency Tracker.",
249 "Counter": "0",
250 "CounterMask": "0",
251 "Invert": "0",
252 "EdgeDetect": "0"
253 },
254 {
255 "Unit": "ARB",
256 "EventCode": "0x84",
257 "UMask": "0x01",
258 "EventName": "UNC_ARB_COH_TRK_REQUESTS.ALL",
259 "BriefDescription": "Number of requests allocated in Coherency Tracker.",
260 "PublicDescription": "Number of requests allocated in Coherency Tracker.",
261 "Counter": "0,1",
262 "CounterMask": "0",
263 "Invert": "0",
264 "EdgeDetect": "0"
265 },
266 {
267 "Unit": "ARB",
268 "EventCode": "0x80",
269 "UMask": "0x01",
270 "EventName": "UNC_ARB_TRK_OCCUPANCY.CYCLES_WITH_ANY_REQUEST",
271 "BriefDescription": "Cycles with at least one request outstanding is waiting for data return from memory controller. Account for coherent and non-coherent requests initiated by IA Cores, Processor Graphics Unit, or LLC.",
272 "PublicDescription": "Cycles with at least one request outstanding is waiting for data return from memory controller. Account for coherent and non-coherent requests initiated by IA Cores, Processor Graphics Unit, or LLC.",
273 "Counter": "0,1",
274 "CounterMask": "1",
275 "Invert": "0",
276 "EdgeDetect": "0"
277 },
278 {
279 "Unit": "ARB",
280 "EventCode": "0x80",
281 "UMask": "0x01",
282 "EventName": "UNC_ARB_TRK_OCCUPANCY.CYCLES_OVER_HALF_FULL",
283 "BriefDescription": "Cycles with at least half of the requests outstanding are waiting for data return from memory controller. Account for coherent and non-coherent requests initiated by IA Cores, Processor Graphics Unit, or LLC.",
284 "PublicDescription": "Cycles with at least half of the requests outstanding are waiting for data return from memory controller. Account for coherent and non-coherent requests initiated by IA Cores, Processor Graphics Unit, or LLC.",
285 "Counter": "0,1",
286 "CounterMask": "10",
287 "Invert": "0",
288 "EdgeDetect": "0"
289 },
290 {
291 "Unit": "ARB",
292 "EventCode": "0x0",
293 "UMask": "0x01",
294 "EventName": "UNC_CLOCK.SOCKET",
295 "BriefDescription": "This 48-bit fixed counter counts the UCLK cycles.",
296 "PublicDescription": "This 48-bit fixed counter counts the UCLK cycles.",
297 "Counter": "Fixed",
298 "CounterMask": "0",
299 "Invert": "0",
300 "EdgeDetect": "0"
301 },
302 {
303 "Unit": "CBO",
304 "EventCode": "0x34",
305 "UMask": "0x06",
306 "EventName": "UNC_CBO_CACHE_LOOKUP.ES",
307 "BriefDescription": "LLC lookup request that access cache and found line in E-state or S-state.",
308 "PublicDescription": "LLC lookup request that access cache and found line in E-state or S-state.",
309 "Counter": "0,1",
310 "CounterMask": "0",
311 "Invert": "0",
312 "EdgeDetect": "0"
313 }
314] \ No newline at end of file
diff --git a/tools/perf/pmu-events/arch/x86/ivytown/uncore-cache.json b/tools/perf/pmu-events/arch/x86/ivytown/uncore-cache.json
index 2efdc6772e0b..267410594833 100644
--- a/tools/perf/pmu-events/arch/x86/ivytown/uncore-cache.json
+++ b/tools/perf/pmu-events/arch/x86/ivytown/uncore-cache.json
@@ -1,13 +1,13 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "Uncore cache clock ticks. Derived from unc_c_clockticks", 3 "BriefDescription": "Uncore cache clock ticks",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventName": "UNC_C_CLOCKTICKS", 5 "EventName": "UNC_C_CLOCKTICKS",
6 "PerPkg": "1", 6 "PerPkg": "1",
7 "Unit": "CBO" 7 "Unit": "CBO"
8 }, 8 },
9 { 9 {
10 "BriefDescription": "All LLC Misses (code+ data rd + data wr - including demand and prefetch). Derived from unc_c_llc_lookup.any", 10 "BriefDescription": "All LLC Misses (code+ data rd + data wr - including demand and prefetch)",
11 "Counter": "0,1", 11 "Counter": "0,1",
12 "EventCode": "0x34", 12 "EventCode": "0x34",
13 "EventName": "UNC_C_LLC_LOOKUP.ANY", 13 "EventName": "UNC_C_LLC_LOOKUP.ANY",
@@ -18,7 +18,7 @@
18 "Unit": "CBO" 18 "Unit": "CBO"
19 }, 19 },
20 { 20 {
21 "BriefDescription": "M line evictions from LLC (writebacks to memory). Derived from unc_c_llc_victims.m_state", 21 "BriefDescription": "M line evictions from LLC (writebacks to memory)",
22 "Counter": "0,1", 22 "Counter": "0,1",
23 "EventCode": "0x37", 23 "EventCode": "0x37",
24 "EventName": "UNC_C_LLC_VICTIMS.M_STATE", 24 "EventName": "UNC_C_LLC_VICTIMS.M_STATE",
@@ -237,7 +237,7 @@
237 "Unit": "CBO" 237 "Unit": "CBO"
238 }, 238 },
239 { 239 {
240 "BriefDescription": "Occupancy for all LLC misses that are addressed to local memory. Derived from unc_c_tor_occupancy.miss_local", 240 "BriefDescription": "Occupancy for all LLC misses that are addressed to local memory",
241 "EventCode": "0x36", 241 "EventCode": "0x36",
242 "EventName": "UNC_C_TOR_OCCUPANCY.MISS_LOCAL", 242 "EventName": "UNC_C_TOR_OCCUPANCY.MISS_LOCAL",
243 "PerPkg": "1", 243 "PerPkg": "1",
@@ -254,7 +254,7 @@
254 "Unit": "CBO" 254 "Unit": "CBO"
255 }, 255 },
256 { 256 {
257 "BriefDescription": "Occupancy for all LLC misses that are addressed to remote memory. Derived from unc_c_tor_occupancy.miss_remote", 257 "BriefDescription": "Occupancy for all LLC misses that are addressed to remote memory",
258 "EventCode": "0x36", 258 "EventCode": "0x36",
259 "EventName": "UNC_C_TOR_OCCUPANCY.MISS_REMOTE", 259 "EventName": "UNC_C_TOR_OCCUPANCY.MISS_REMOTE",
260 "PerPkg": "1", 260 "PerPkg": "1",
@@ -262,7 +262,7 @@
262 "Unit": "CBO" 262 "Unit": "CBO"
263 }, 263 },
264 { 264 {
265 "BriefDescription": "Read requests to home agent. Derived from unc_h_requests.reads", 265 "BriefDescription": "Read requests to home agent",
266 "Counter": "0,1,2,3", 266 "Counter": "0,1,2,3",
267 "EventCode": "0x1", 267 "EventCode": "0x1",
268 "EventName": "UNC_H_REQUESTS.READS", 268 "EventName": "UNC_H_REQUESTS.READS",
@@ -271,7 +271,7 @@
271 "Unit": "HA" 271 "Unit": "HA"
272 }, 272 },
273 { 273 {
274 "BriefDescription": "Write requests to home agent. Derived from unc_h_requests.writes", 274 "BriefDescription": "Write requests to home agent",
275 "Counter": "0,1,2,3", 275 "Counter": "0,1,2,3",
276 "EventCode": "0x1", 276 "EventCode": "0x1",
277 "EventName": "UNC_H_REQUESTS.WRITES", 277 "EventName": "UNC_H_REQUESTS.WRITES",
@@ -280,7 +280,7 @@
280 "Unit": "HA" 280 "Unit": "HA"
281 }, 281 },
282 { 282 {
283 "BriefDescription": "M line forwarded from remote cache along with writeback to memory. Derived from unc_h_snoop_resp.rsp_fwd_wb", 283 "BriefDescription": "M line forwarded from remote cache along with writeback to memory",
284 "Counter": "0,1,2,3", 284 "Counter": "0,1,2,3",
285 "EventCode": "0x21", 285 "EventCode": "0x21",
286 "EventName": "UNC_H_SNOOP_RESP.RSP_FWD_WB", 286 "EventName": "UNC_H_SNOOP_RESP.RSP_FWD_WB",
@@ -290,7 +290,7 @@
290 "Unit": "HA" 290 "Unit": "HA"
291 }, 291 },
292 { 292 {
293 "BriefDescription": "M line forwarded from remote cache with no writeback to memory. Derived from unc_h_snoop_resp.rspifwd", 293 "BriefDescription": "M line forwarded from remote cache with no writeback to memory",
294 "Counter": "0,1,2,3", 294 "Counter": "0,1,2,3",
295 "EventCode": "0x21", 295 "EventCode": "0x21",
296 "EventName": "UNC_H_SNOOP_RESP.RSPIFWD", 296 "EventName": "UNC_H_SNOOP_RESP.RSPIFWD",
@@ -300,7 +300,7 @@
300 "Unit": "HA" 300 "Unit": "HA"
301 }, 301 },
302 { 302 {
303 "BriefDescription": "Shared line response from remote cache. Derived from unc_h_snoop_resp.rsps", 303 "BriefDescription": "Shared line response from remote cache",
304 "Counter": "0,1,2,3", 304 "Counter": "0,1,2,3",
305 "EventCode": "0x21", 305 "EventCode": "0x21",
306 "EventName": "UNC_H_SNOOP_RESP.RSPS", 306 "EventName": "UNC_H_SNOOP_RESP.RSPS",
@@ -310,7 +310,7 @@
310 "Unit": "HA" 310 "Unit": "HA"
311 }, 311 },
312 { 312 {
313 "BriefDescription": "Shared line forwarded from remote cache. Derived from unc_h_snoop_resp.rspsfwd", 313 "BriefDescription": "Shared line forwarded from remote cache",
314 "Counter": "0,1,2,3", 314 "Counter": "0,1,2,3",
315 "EventCode": "0x21", 315 "EventCode": "0x21",
316 "EventName": "UNC_H_SNOOP_RESP.RSPSFWD", 316 "EventName": "UNC_H_SNOOP_RESP.RSPSFWD",
diff --git a/tools/perf/pmu-events/arch/x86/ivytown/uncore-interconnect.json b/tools/perf/pmu-events/arch/x86/ivytown/uncore-interconnect.json
index d7e2fda1d695..b798a860bc81 100644
--- a/tools/perf/pmu-events/arch/x86/ivytown/uncore-interconnect.json
+++ b/tools/perf/pmu-events/arch/x86/ivytown/uncore-interconnect.json
@@ -1,6 +1,6 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "QPI clock ticks. Use to get percentages for QPI cycles events. Derived from unc_q_clockticks", 3 "BriefDescription": "QPI clock ticks. Use to get percentages for QPI cycles events",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventCode": "0x14", 5 "EventCode": "0x14",
6 "EventName": "UNC_Q_CLOCKTICKS", 6 "EventName": "UNC_Q_CLOCKTICKS",
@@ -8,25 +8,27 @@
8 "Unit": "QPI LL" 8 "Unit": "QPI LL"
9 }, 9 },
10 { 10 {
11 "BriefDescription": "Cycles where receiving QPI link is in half-width mode. Derived from unc_q_rxl0p_power_cycles", 11 "BriefDescription": "Cycles where receiving QPI link is in half-width mode",
12 "Counter": "0,1,2,3", 12 "Counter": "0,1,2,3",
13 "EventCode": "0x10", 13 "EventCode": "0x10",
14 "EventName": "UNC_Q_RxL0P_POWER_CYCLES", 14 "EventName": "UNC_Q_RxL0P_POWER_CYCLES",
15 "MetricExpr": "(UNC_Q_RxL0P_POWER_CYCLES / UNC_Q_CLOCKTICKS) * 100.", 15 "MetricExpr": "(UNC_Q_RxL0P_POWER_CYCLES / UNC_Q_CLOCKTICKS) * 100.",
16 "MetricName": "rxl0p_power_cycles %",
16 "PerPkg": "1", 17 "PerPkg": "1",
17 "Unit": "QPI LL" 18 "Unit": "QPI LL"
18 }, 19 },
19 { 20 {
20 "BriefDescription": "Cycles where transmitting QPI link is in half-width mode. Derived from unc_q_txl0p_power_cycles", 21 "BriefDescription": "Cycles where transmitting QPI link is in half-width mode",
21 "Counter": "0,1,2,3", 22 "Counter": "0,1,2,3",
22 "EventCode": "0xd", 23 "EventCode": "0xd",
23 "EventName": "UNC_Q_TxL0P_POWER_CYCLES", 24 "EventName": "UNC_Q_TxL0P_POWER_CYCLES",
24 "MetricExpr": "(UNC_Q_TxL0P_POWER_CYCLES / UNC_Q_CLOCKTICKS) * 100.", 25 "MetricExpr": "(UNC_Q_TxL0P_POWER_CYCLES / UNC_Q_CLOCKTICKS) * 100.",
26 "MetricName": "txl0p_power_cycles %",
25 "PerPkg": "1", 27 "PerPkg": "1",
26 "Unit": "QPI LL" 28 "Unit": "QPI LL"
27 }, 29 },
28 { 30 {
29 "BriefDescription": "Number of data flits transmitted . Derived from unc_q_txl_flits_g0.data", 31 "BriefDescription": "Number of data flits transmitted ",
30 "Counter": "0,1,2,3", 32 "Counter": "0,1,2,3",
31 "EventName": "UNC_Q_TxL_FLITS_G0.DATA", 33 "EventName": "UNC_Q_TxL_FLITS_G0.DATA",
32 "PerPkg": "1", 34 "PerPkg": "1",
@@ -35,7 +37,7 @@
35 "Unit": "QPI LL" 37 "Unit": "QPI LL"
36 }, 38 },
37 { 39 {
38 "BriefDescription": "Number of non data (control) flits transmitted . Derived from unc_q_txl_flits_g0.non_data", 40 "BriefDescription": "Number of non data (control) flits transmitted ",
39 "Counter": "0,1,2,3", 41 "Counter": "0,1,2,3",
40 "EventName": "UNC_Q_TxL_FLITS_G0.NON_DATA", 42 "EventName": "UNC_Q_TxL_FLITS_G0.NON_DATA",
41 "PerPkg": "1", 43 "PerPkg": "1",
diff --git a/tools/perf/pmu-events/arch/x86/ivytown/uncore-memory.json b/tools/perf/pmu-events/arch/x86/ivytown/uncore-memory.json
index ac4ad4d6357b..df4b43294fa0 100644
--- a/tools/perf/pmu-events/arch/x86/ivytown/uncore-memory.json
+++ b/tools/perf/pmu-events/arch/x86/ivytown/uncore-memory.json
@@ -1,6 +1,6 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "Memory page activates for reads and writes. Derived from unc_m_act_count.rd", 3 "BriefDescription": "Memory page activates for reads and writes",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventCode": "0x1", 5 "EventCode": "0x1",
6 "EventName": "UNC_M_ACT_COUNT.RD", 6 "EventName": "UNC_M_ACT_COUNT.RD",
@@ -13,7 +13,7 @@
13 "BriefDescription": "Read requests to memory controller. Derived from unc_m_cas_count.rd", 13 "BriefDescription": "Read requests to memory controller. Derived from unc_m_cas_count.rd",
14 "Counter": "0,1,2,3", 14 "Counter": "0,1,2,3",
15 "EventCode": "0x4", 15 "EventCode": "0x4",
16 "EventName": "UNC_M_CAS_COUNT.RD", 16 "EventName": "LLC_MISSES.MEM_READ",
17 "PerPkg": "1", 17 "PerPkg": "1",
18 "ScaleUnit": "64Bytes", 18 "ScaleUnit": "64Bytes",
19 "UMask": "0x3", 19 "UMask": "0x3",
@@ -23,48 +23,51 @@
23 "BriefDescription": "Write requests to memory controller. Derived from unc_m_cas_count.wr", 23 "BriefDescription": "Write requests to memory controller. Derived from unc_m_cas_count.wr",
24 "Counter": "0,1,2,3", 24 "Counter": "0,1,2,3",
25 "EventCode": "0x4", 25 "EventCode": "0x4",
26 "EventName": "UNC_M_CAS_COUNT.WR", 26 "EventName": "LLC_MISSES.MEM_WRITE",
27 "PerPkg": "1", 27 "PerPkg": "1",
28 "ScaleUnit": "64Bytes", 28 "ScaleUnit": "64Bytes",
29 "UMask": "0xC", 29 "UMask": "0xC",
30 "Unit": "iMC" 30 "Unit": "iMC"
31 }, 31 },
32 { 32 {
33 "BriefDescription": "Memory controller clock ticks. Use to generate percentages for memory controller CYCLES events. Derived from unc_m_clockticks", 33 "BriefDescription": "Memory controller clock ticks. Use to generate percentages for memory controller CYCLES events",
34 "Counter": "0,1,2,3", 34 "Counter": "0,1,2,3",
35 "EventName": "UNC_M_CLOCKTICKS", 35 "EventName": "UNC_M_CLOCKTICKS",
36 "PerPkg": "1", 36 "PerPkg": "1",
37 "Unit": "iMC" 37 "Unit": "iMC"
38 }, 38 },
39 { 39 {
40 "BriefDescription": "Cycles where DRAM ranks are in power down (CKE) mode. Derived from unc_m_power_channel_ppd", 40 "BriefDescription": "Cycles where DRAM ranks are in power down (CKE) mode",
41 "Counter": "0,1,2,3", 41 "Counter": "0,1,2,3",
42 "EventCode": "0x85", 42 "EventCode": "0x85",
43 "EventName": "UNC_M_POWER_CHANNEL_PPD", 43 "EventName": "UNC_M_POWER_CHANNEL_PPD",
44 "MetricExpr": "(UNC_M_POWER_CHANNEL_PPD / UNC_M_CLOCKTICKS) * 100.", 44 "MetricExpr": "(UNC_M_POWER_CHANNEL_PPD / UNC_M_CLOCKTICKS) * 100.",
45 "MetricName": "power_channel_ppd %",
45 "PerPkg": "1", 46 "PerPkg": "1",
46 "Unit": "iMC" 47 "Unit": "iMC"
47 }, 48 },
48 { 49 {
49 "BriefDescription": "Cycles all ranks are in critical thermal throttle. Derived from unc_m_power_critical_throttle_cycles", 50 "BriefDescription": "Cycles all ranks are in critical thermal throttle",
50 "Counter": "0,1,2,3", 51 "Counter": "0,1,2,3",
51 "EventCode": "0x86", 52 "EventCode": "0x86",
52 "EventName": "UNC_M_POWER_CRITICAL_THROTTLE_CYCLES", 53 "EventName": "UNC_M_POWER_CRITICAL_THROTTLE_CYCLES",
53 "MetricExpr": "(UNC_M_POWER_CRITICAL_THROTTLE_CYCLES / UNC_M_CLOCKTICKS) * 100.", 54 "MetricExpr": "(UNC_M_POWER_CRITICAL_THROTTLE_CYCLES / UNC_M_CLOCKTICKS) * 100.",
55 "MetricName": "power_critical_throttle_cycles %",
54 "PerPkg": "1", 56 "PerPkg": "1",
55 "Unit": "iMC" 57 "Unit": "iMC"
56 }, 58 },
57 { 59 {
58 "BriefDescription": "Cycles Memory is in self refresh power mode. Derived from unc_m_power_self_refresh", 60 "BriefDescription": "Cycles Memory is in self refresh power mode",
59 "Counter": "0,1,2,3", 61 "Counter": "0,1,2,3",
60 "EventCode": "0x43", 62 "EventCode": "0x43",
61 "EventName": "UNC_M_POWER_SELF_REFRESH", 63 "EventName": "UNC_M_POWER_SELF_REFRESH",
62 "MetricExpr": "(UNC_M_POWER_SELF_REFRESH / UNC_M_CLOCKTICKS) * 100.", 64 "MetricExpr": "(UNC_M_POWER_SELF_REFRESH / UNC_M_CLOCKTICKS) * 100.",
65 "MetricName": "power_self_refresh %",
63 "PerPkg": "1", 66 "PerPkg": "1",
64 "Unit": "iMC" 67 "Unit": "iMC"
65 }, 68 },
66 { 69 {
67 "BriefDescription": "Memory page conflicts. Derived from unc_m_pre_count.page_miss", 70 "BriefDescription": "Memory page conflicts",
68 "Counter": "0,1,2,3", 71 "Counter": "0,1,2,3",
69 "EventCode": "0x2", 72 "EventCode": "0x2",
70 "EventName": "UNC_M_PRE_COUNT.PAGE_MISS", 73 "EventName": "UNC_M_PRE_COUNT.PAGE_MISS",
diff --git a/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json b/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json
index dc2586db0dfc..d40498f2cb1e 100644
--- a/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json
+++ b/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json
@@ -1,44 +1,48 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "PCU clock ticks. Use to get percentages of PCU cycles events. Derived from unc_p_clockticks", 3 "BriefDescription": "PCU clock ticks. Use to get percentages of PCU cycles events",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventName": "UNC_P_CLOCKTICKS", 5 "EventName": "UNC_P_CLOCKTICKS",
6 "PerPkg": "1", 6 "PerPkg": "1",
7 "Unit": "PCU" 7 "Unit": "PCU"
8 }, 8 },
9 { 9 {
10 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band0=XXX, with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency. Derived from unc_p_freq_band0_cycles", 10 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band0=XXX, with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency",
11 "Counter": "0,1,2,3", 11 "Counter": "0,1,2,3",
12 "EventCode": "0xb", 12 "EventCode": "0xb",
13 "EventName": "UNC_P_FREQ_BAND0_CYCLES", 13 "EventName": "UNC_P_FREQ_BAND0_CYCLES",
14 "MetricExpr": "(UNC_P_FREQ_BAND0_CYCLES / UNC_P_CLOCKTICKS) * 100.", 14 "MetricExpr": "(UNC_P_FREQ_BAND0_CYCLES / UNC_P_CLOCKTICKS) * 100.",
15 "MetricName": "freq_band0_cycles %",
15 "PerPkg": "1", 16 "PerPkg": "1",
16 "Unit": "PCU" 17 "Unit": "PCU"
17 }, 18 },
18 { 19 {
19 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band1=XXX, with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency. Derived from unc_p_freq_band1_cycles", 20 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band1=XXX, with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency",
20 "Counter": "0,1,2,3", 21 "Counter": "0,1,2,3",
21 "EventCode": "0xc", 22 "EventCode": "0xc",
22 "EventName": "UNC_P_FREQ_BAND1_CYCLES", 23 "EventName": "UNC_P_FREQ_BAND1_CYCLES",
23 "MetricExpr": "(UNC_P_FREQ_BAND1_CYCLES / UNC_P_CLOCKTICKS) * 100.", 24 "MetricExpr": "(UNC_P_FREQ_BAND1_CYCLES / UNC_P_CLOCKTICKS) * 100.",
25 "MetricName": "freq_band1_cycles %",
24 "PerPkg": "1", 26 "PerPkg": "1",
25 "Unit": "PCU" 27 "Unit": "PCU"
26 }, 28 },
27 { 29 {
28 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band2=XXX, with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency. Derived from unc_p_freq_band2_cycles", 30 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band2=XXX, with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency",
29 "Counter": "0,1,2,3", 31 "Counter": "0,1,2,3",
30 "EventCode": "0xd", 32 "EventCode": "0xd",
31 "EventName": "UNC_P_FREQ_BAND2_CYCLES", 33 "EventName": "UNC_P_FREQ_BAND2_CYCLES",
32 "MetricExpr": "(UNC_P_FREQ_BAND2_CYCLES / UNC_P_CLOCKTICKS) * 100.", 34 "MetricExpr": "(UNC_P_FREQ_BAND2_CYCLES / UNC_P_CLOCKTICKS) * 100.",
35 "MetricName": "freq_band2_cycles %",
33 "PerPkg": "1", 36 "PerPkg": "1",
34 "Unit": "PCU" 37 "Unit": "PCU"
35 }, 38 },
36 { 39 {
37 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band3=XXX, with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency. Derived from unc_p_freq_band3_cycles", 40 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band3=XXX, with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency",
38 "Counter": "0,1,2,3", 41 "Counter": "0,1,2,3",
39 "EventCode": "0xe", 42 "EventCode": "0xe",
40 "EventName": "UNC_P_FREQ_BAND3_CYCLES", 43 "EventName": "UNC_P_FREQ_BAND3_CYCLES",
41 "MetricExpr": "(UNC_P_FREQ_BAND3_CYCLES / UNC_P_CLOCKTICKS) * 100.", 44 "MetricExpr": "(UNC_P_FREQ_BAND3_CYCLES / UNC_P_CLOCKTICKS) * 100.",
45 "MetricName": "freq_band3_cycles %",
42 "PerPkg": "1", 46 "PerPkg": "1",
43 "Unit": "PCU" 47 "Unit": "PCU"
44 }, 48 },
@@ -49,6 +53,7 @@
49 "EventName": "UNC_P_FREQ_BAND0_TRANSITIONS", 53 "EventName": "UNC_P_FREQ_BAND0_TRANSITIONS",
50 "Filter": "edge=1", 54 "Filter": "edge=1",
51 "MetricExpr": "(UNC_P_FREQ_BAND0_CYCLES / UNC_P_CLOCKTICKS) * 100.", 55 "MetricExpr": "(UNC_P_FREQ_BAND0_CYCLES / UNC_P_CLOCKTICKS) * 100.",
56 "MetricName": "freq_band0_cycles %",
52 "PerPkg": "1", 57 "PerPkg": "1",
53 "Unit": "PCU" 58 "Unit": "PCU"
54 }, 59 },
@@ -59,6 +64,7 @@
59 "EventName": "UNC_P_FREQ_BAND1_TRANSITIONS", 64 "EventName": "UNC_P_FREQ_BAND1_TRANSITIONS",
60 "Filter": "edge=1", 65 "Filter": "edge=1",
61 "MetricExpr": "(UNC_P_FREQ_BAND1_CYCLES / UNC_P_CLOCKTICKS) * 100.", 66 "MetricExpr": "(UNC_P_FREQ_BAND1_CYCLES / UNC_P_CLOCKTICKS) * 100.",
67 "MetricName": "freq_band1_cycles %",
62 "PerPkg": "1", 68 "PerPkg": "1",
63 "Unit": "PCU" 69 "Unit": "PCU"
64 }, 70 },
@@ -69,6 +75,7 @@
69 "EventName": "UNC_P_FREQ_BAND2_TRANSITIONS", 75 "EventName": "UNC_P_FREQ_BAND2_TRANSITIONS",
70 "Filter": "edge=1", 76 "Filter": "edge=1",
71 "MetricExpr": "(UNC_P_FREQ_BAND2_CYCLES / UNC_P_CLOCKTICKS) * 100.", 77 "MetricExpr": "(UNC_P_FREQ_BAND2_CYCLES / UNC_P_CLOCKTICKS) * 100.",
78 "MetricName": "freq_band2_cycles %",
72 "PerPkg": "1", 79 "PerPkg": "1",
73 "Unit": "PCU" 80 "Unit": "PCU"
74 }, 81 },
@@ -79,90 +86,100 @@
79 "EventName": "UNC_P_FREQ_BAND3_TRANSITIONS", 86 "EventName": "UNC_P_FREQ_BAND3_TRANSITIONS",
80 "Filter": "edge=1", 87 "Filter": "edge=1",
81 "MetricExpr": "(UNC_P_FREQ_BAND3_CYCLES / UNC_P_CLOCKTICKS) * 100.", 88 "MetricExpr": "(UNC_P_FREQ_BAND3_CYCLES / UNC_P_CLOCKTICKS) * 100.",
89 "MetricName": "freq_band3_cycles %",
82 "PerPkg": "1", 90 "PerPkg": "1",
83 "Unit": "PCU" 91 "Unit": "PCU"
84 }, 92 },
85 { 93 {
86 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in the chosen C-State. It can be used by itself to get the average number of cores in that C-state with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details. Derived from unc_p_power_state_occupancy.cores_c0", 94 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C0. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details",
87 "Counter": "0,1,2,3", 95 "Counter": "0,1,2,3",
88 "EventCode": "0x80", 96 "EventCode": "0x80",
89 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C0", 97 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C0",
90 "Filter": "occ_sel=1", 98 "Filter": "occ_sel=1",
91 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C0 / UNC_P_CLOCKTICKS) * 100.", 99 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C0 / UNC_P_CLOCKTICKS) * 100.",
100 "MetricName": "power_state_occupancy.cores_c0 %",
92 "PerPkg": "1", 101 "PerPkg": "1",
93 "Unit": "PCU" 102 "Unit": "PCU"
94 }, 103 },
95 { 104 {
96 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in the chosen C-State. It can be used by itself to get the average number of cores in that C-state with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details. Derived from unc_p_power_state_occupancy.cores_c3", 105 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C3. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details",
97 "Counter": "0,1,2,3", 106 "Counter": "0,1,2,3",
98 "EventCode": "0x80", 107 "EventCode": "0x80",
99 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C3", 108 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C3",
100 "Filter": "occ_sel=2", 109 "Filter": "occ_sel=2",
101 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C3 / UNC_P_CLOCKTICKS) * 100.", 110 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C3 / UNC_P_CLOCKTICKS) * 100.",
111 "MetricName": "power_state_occupancy.cores_c3 %",
102 "PerPkg": "1", 112 "PerPkg": "1",
103 "Unit": "PCU" 113 "Unit": "PCU"
104 }, 114 },
105 { 115 {
106 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in the chosen C-State. It can be used by itself to get the average number of cores in that C-state with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details. Derived from unc_p_power_state_occupancy.cores_c6", 116 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C6. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events ",
107 "Counter": "0,1,2,3", 117 "Counter": "0,1,2,3",
108 "EventCode": "0x80", 118 "EventCode": "0x80",
109 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C6", 119 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C6",
110 "Filter": "occ_sel=3", 120 "Filter": "occ_sel=3",
111 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C6 / UNC_P_CLOCKTICKS) * 100.", 121 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C6 / UNC_P_CLOCKTICKS) * 100.",
122 "MetricName": "power_state_occupancy.cores_c6 %",
112 "PerPkg": "1", 123 "PerPkg": "1",
113 "Unit": "PCU" 124 "Unit": "PCU"
114 }, 125 },
115 { 126 {
116 "BriefDescription": "Counts the number of cycles that we are in external PROCHOT mode. This mode is triggered when a sensor off the die determines that something off-die (like DRAM) is too hot and must throttle to avoid damaging the chip. Derived from unc_p_prochot_external_cycles", 127 "BriefDescription": "Counts the number of cycles that we are in external PROCHOT mode. This mode is triggered when a sensor off the die determines that something off-die (like DRAM) is too hot and must throttle to avoid damaging the chip",
117 "Counter": "0,1,2,3", 128 "Counter": "0,1,2,3",
118 "EventCode": "0xa", 129 "EventCode": "0xa",
119 "EventName": "UNC_P_PROCHOT_EXTERNAL_CYCLES", 130 "EventName": "UNC_P_PROCHOT_EXTERNAL_CYCLES",
120 "MetricExpr": "(UNC_P_PROCHOT_EXTERNAL_CYCLES / UNC_P_CLOCKTICKS) * 100.", 131 "MetricExpr": "(UNC_P_PROCHOT_EXTERNAL_CYCLES / UNC_P_CLOCKTICKS) * 100.",
132 "MetricName": "prochot_external_cycles %",
121 "PerPkg": "1", 133 "PerPkg": "1",
122 "Unit": "PCU" 134 "Unit": "PCU"
123 }, 135 },
124 { 136 {
125 "BriefDescription": "Counts the number of cycles when thermal conditions are the upper limit on frequency. This is related to the THERMAL_THROTTLE CYCLES_ABOVE_TEMP event, which always counts cycles when we are above the thermal temperature. This event (STRONGEST_UPPER_LIMIT) is sampled at the output of the algorithm that determines the actual frequency, while THERMAL_THROTTLE looks at the input. Derived from unc_p_freq_max_limit_thermal_cycles", 137 "BriefDescription": "Counts the number of cycles when temperature is the upper limit on frequency",
126 "Counter": "0,1,2,3", 138 "Counter": "0,1,2,3",
127 "EventCode": "0x4", 139 "EventCode": "0x4",
128 "EventName": "UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES", 140 "EventName": "UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES",
129 "MetricExpr": "(UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES / UNC_P_CLOCKTICKS) * 100.", 141 "MetricExpr": "(UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES / UNC_P_CLOCKTICKS) * 100.",
142 "MetricName": "freq_max_limit_thermal_cycles %",
130 "PerPkg": "1", 143 "PerPkg": "1",
131 "Unit": "PCU" 144 "Unit": "PCU"
132 }, 145 },
133 { 146 {
134 "BriefDescription": "Counts the number of cycles when the OS is the upper limit on frequency. Derived from unc_p_freq_max_os_cycles", 147 "BriefDescription": "Counts the number of cycles when the OS is the upper limit on frequency",
135 "Counter": "0,1,2,3", 148 "Counter": "0,1,2,3",
136 "EventCode": "0x6", 149 "EventCode": "0x6",
137 "EventName": "UNC_P_FREQ_MAX_OS_CYCLES", 150 "EventName": "UNC_P_FREQ_MAX_OS_CYCLES",
138 "MetricExpr": "(UNC_P_FREQ_MAX_OS_CYCLES / UNC_P_CLOCKTICKS) * 100.", 151 "MetricExpr": "(UNC_P_FREQ_MAX_OS_CYCLES / UNC_P_CLOCKTICKS) * 100.",
152 "MetricName": "freq_max_os_cycles %",
139 "PerPkg": "1", 153 "PerPkg": "1",
140 "Unit": "PCU" 154 "Unit": "PCU"
141 }, 155 },
142 { 156 {
143 "BriefDescription": "Counts the number of cycles when power is the upper limit on frequency. Derived from unc_p_freq_max_power_cycles", 157 "BriefDescription": "Counts the number of cycles when power is the upper limit on frequency",
144 "Counter": "0,1,2,3", 158 "Counter": "0,1,2,3",
145 "EventCode": "0x5", 159 "EventCode": "0x5",
146 "EventName": "UNC_P_FREQ_MAX_POWER_CYCLES", 160 "EventName": "UNC_P_FREQ_MAX_POWER_CYCLES",
147 "MetricExpr": "(UNC_P_FREQ_MAX_POWER_CYCLES / UNC_P_CLOCKTICKS) * 100.", 161 "MetricExpr": "(UNC_P_FREQ_MAX_POWER_CYCLES / UNC_P_CLOCKTICKS) * 100.",
162 "MetricName": "freq_max_power_cycles %",
148 "PerPkg": "1", 163 "PerPkg": "1",
149 "Unit": "PCU" 164 "Unit": "PCU"
150 }, 165 },
151 { 166 {
152 "BriefDescription": "Counts the number of cycles when current is the upper limit on frequency. Derived from unc_p_freq_max_current_cycles", 167 "BriefDescription": "Counts the number of cycles when current is the upper limit on frequency",
153 "Counter": "0,1,2,3", 168 "Counter": "0,1,2,3",
154 "EventCode": "0x7", 169 "EventCode": "0x7",
155 "EventName": "UNC_P_FREQ_MAX_CURRENT_CYCLES", 170 "EventName": "UNC_P_FREQ_MAX_CURRENT_CYCLES",
156 "MetricExpr": "(UNC_P_FREQ_MAX_CURRENT_CYCLES / UNC_P_CLOCKTICKS) * 100.", 171 "MetricExpr": "(UNC_P_FREQ_MAX_CURRENT_CYCLES / UNC_P_CLOCKTICKS) * 100.",
172 "MetricName": "freq_max_current_cycles %",
157 "PerPkg": "1", 173 "PerPkg": "1",
158 "Unit": "PCU" 174 "Unit": "PCU"
159 }, 175 },
160 { 176 {
161 "BriefDescription": "Counts the number of cycles when the system is changing frequency. This can not be filtered by thread ID. One can also use it with the occupancy counter that monitors number of threads in C0 to estimate the performance impact that frequency transitions had on the system. Derived from unc_p_freq_trans_cycles", 177 "BriefDescription": "Cycles spent changing Frequency",
162 "Counter": "0,1,2,3", 178 "Counter": "0,1,2,3",
163 "EventCode": "0x60", 179 "EventCode": "0x60",
164 "EventName": "UNC_P_FREQ_TRANS_CYCLES", 180 "EventName": "UNC_P_FREQ_TRANS_CYCLES",
165 "MetricExpr": "(UNC_P_FREQ_TRANS_CYCLES / UNC_P_CLOCKTICKS) * 100.", 181 "MetricExpr": "(UNC_P_FREQ_TRANS_CYCLES / UNC_P_CLOCKTICKS) * 100.",
182 "MetricName": "freq_trans_cycles %",
166 "PerPkg": "1", 183 "PerPkg": "1",
167 "Unit": "PCU" 184 "Unit": "PCU"
168 }, 185 },
@@ -173,6 +190,7 @@
173 "EventName": "UNC_P_FREQ_GE_1200MHZ_CYCLES", 190 "EventName": "UNC_P_FREQ_GE_1200MHZ_CYCLES",
174 "Filter": "filter_band0=1200", 191 "Filter": "filter_band0=1200",
175 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 192 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
193 "MetricName": "freq_ge_1200mhz_cycles %",
176 "PerPkg": "1", 194 "PerPkg": "1",
177 "Unit": "PCU" 195 "Unit": "PCU"
178 }, 196 },
@@ -183,6 +201,7 @@
183 "EventName": "UNC_P_FREQ_GE_2000MHZ_CYCLES", 201 "EventName": "UNC_P_FREQ_GE_2000MHZ_CYCLES",
184 "Filter": "filter_band1=2000", 202 "Filter": "filter_band1=2000",
185 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 203 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
204 "MetricName": "freq_ge_2000mhz_cycles %",
186 "PerPkg": "1", 205 "PerPkg": "1",
187 "Unit": "PCU" 206 "Unit": "PCU"
188 }, 207 },
@@ -193,6 +212,7 @@
193 "EventName": "UNC_P_FREQ_GE_3000MHZ_CYCLES", 212 "EventName": "UNC_P_FREQ_GE_3000MHZ_CYCLES",
194 "Filter": "filter_band2=3000", 213 "Filter": "filter_band2=3000",
195 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 214 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
215 "MetricName": "freq_ge_3000mhz_cycles %",
196 "PerPkg": "1", 216 "PerPkg": "1",
197 "Unit": "PCU" 217 "Unit": "PCU"
198 }, 218 },
@@ -203,6 +223,7 @@
203 "EventName": "UNC_P_FREQ_GE_4000MHZ_CYCLES", 223 "EventName": "UNC_P_FREQ_GE_4000MHZ_CYCLES",
204 "Filter": "filter_band3=4000", 224 "Filter": "filter_band3=4000",
205 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 225 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
226 "MetricName": "freq_ge_4000mhz_cycles %",
206 "PerPkg": "1", 227 "PerPkg": "1",
207 "Unit": "PCU" 228 "Unit": "PCU"
208 }, 229 },
@@ -213,6 +234,7 @@
213 "EventName": "UNC_P_FREQ_GE_1200MHZ_TRANSITIONS", 234 "EventName": "UNC_P_FREQ_GE_1200MHZ_TRANSITIONS",
214 "Filter": "edge=1,filter_band0=1200", 235 "Filter": "edge=1,filter_band0=1200",
215 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 236 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
237 "MetricName": "freq_ge_1200mhz_cycles %",
216 "PerPkg": "1", 238 "PerPkg": "1",
217 "Unit": "PCU" 239 "Unit": "PCU"
218 }, 240 },
@@ -223,6 +245,7 @@
223 "EventName": "UNC_P_FREQ_GE_2000MHZ_TRANSITIONS", 245 "EventName": "UNC_P_FREQ_GE_2000MHZ_TRANSITIONS",
224 "Filter": "edge=1,filter_band1=2000", 246 "Filter": "edge=1,filter_band1=2000",
225 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 247 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
248 "MetricName": "freq_ge_2000mhz_cycles %",
226 "PerPkg": "1", 249 "PerPkg": "1",
227 "Unit": "PCU" 250 "Unit": "PCU"
228 }, 251 },
@@ -233,6 +256,7 @@
233 "EventName": "UNC_P_FREQ_GE_3000MHZ_TRANSITIONS", 256 "EventName": "UNC_P_FREQ_GE_3000MHZ_TRANSITIONS",
234 "Filter": "edge=1,filter_band2=4000", 257 "Filter": "edge=1,filter_band2=4000",
235 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 258 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
259 "MetricName": "freq_ge_3000mhz_cycles %",
236 "PerPkg": "1", 260 "PerPkg": "1",
237 "Unit": "PCU" 261 "Unit": "PCU"
238 }, 262 },
@@ -243,6 +267,7 @@
243 "EventName": "UNC_P_FREQ_GE_4000MHZ_TRANSITIONS", 267 "EventName": "UNC_P_FREQ_GE_4000MHZ_TRANSITIONS",
244 "Filter": "edge=1,filter_band3=4000", 268 "Filter": "edge=1,filter_band3=4000",
245 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 269 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
270 "MetricName": "freq_ge_4000mhz_cycles %",
246 "PerPkg": "1", 271 "PerPkg": "1",
247 "Unit": "PCU" 272 "Unit": "PCU"
248 } 273 }
diff --git a/tools/perf/pmu-events/arch/x86/jaketown/uncore-cache.json b/tools/perf/pmu-events/arch/x86/jaketown/uncore-cache.json
index 2f23cf0129e7..3fa61d962607 100644
--- a/tools/perf/pmu-events/arch/x86/jaketown/uncore-cache.json
+++ b/tools/perf/pmu-events/arch/x86/jaketown/uncore-cache.json
@@ -1,13 +1,13 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "Uncore cache clock ticks. Derived from unc_c_clockticks", 3 "BriefDescription": "Uncore cache clock ticks",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventName": "UNC_C_CLOCKTICKS", 5 "EventName": "UNC_C_CLOCKTICKS",
6 "PerPkg": "1", 6 "PerPkg": "1",
7 "Unit": "CBO" 7 "Unit": "CBO"
8 }, 8 },
9 { 9 {
10 "BriefDescription": "All LLC Misses (code+ data rd + data wr - including demand and prefetch). Derived from unc_c_llc_lookup.any", 10 "BriefDescription": "All LLC Misses (code+ data rd + data wr - including demand and prefetch)",
11 "Counter": "0,1", 11 "Counter": "0,1",
12 "EventCode": "0x34", 12 "EventCode": "0x34",
13 "EventName": "UNC_C_LLC_LOOKUP.ANY", 13 "EventName": "UNC_C_LLC_LOOKUP.ANY",
@@ -18,7 +18,7 @@
18 "Unit": "CBO" 18 "Unit": "CBO"
19 }, 19 },
20 { 20 {
21 "BriefDescription": "M line evictions from LLC (writebacks to memory). Derived from unc_c_llc_victims.m_state", 21 "BriefDescription": "M line evictions from LLC (writebacks to memory)",
22 "Counter": "0,1", 22 "Counter": "0,1",
23 "EventCode": "0x37", 23 "EventCode": "0x37",
24 "EventName": "UNC_C_LLC_VICTIMS.M_STATE", 24 "EventName": "UNC_C_LLC_VICTIMS.M_STATE",
@@ -171,11 +171,12 @@
171 "Unit": "CBO" 171 "Unit": "CBO"
172 }, 172 },
173 { 173 {
174 "BriefDescription": "Occupancy counter for all LLC misses; we divide this by UNC_C_CLOCKTICKS to get average Q depth. Derived from unc_c_tor_occupancy.miss_all", 174 "BriefDescription": "Occupancy counter for all LLC misses; we divide this by UNC_C_CLOCKTICKS to get average Q depth",
175 "EventCode": "0x36", 175 "EventCode": "0x36",
176 "EventName": "UNC_C_TOR_OCCUPANCY.MISS_ALL", 176 "EventName": "UNC_C_TOR_OCCUPANCY.MISS_ALL",
177 "Filter": "filter_opc=0x182", 177 "Filter": "filter_opc=0x182",
178 "MetricExpr": "(UNC_C_TOR_OCCUPANCY.MISS_ALL / UNC_C_CLOCKTICKS) * 100.", 178 "MetricExpr": "(UNC_C_TOR_OCCUPANCY.MISS_ALL / UNC_C_CLOCKTICKS) * 100.",
179 "MetricName": "tor_occupancy.miss_all %",
179 "PerPkg": "1", 180 "PerPkg": "1",
180 "UMask": "0xa", 181 "UMask": "0xa",
181 "Unit": "CBO" 182 "Unit": "CBO"
@@ -189,7 +190,7 @@
189 "Unit": "CBO" 190 "Unit": "CBO"
190 }, 191 },
191 { 192 {
192 "BriefDescription": "read requests to home agent. Derived from unc_h_requests.reads", 193 "BriefDescription": "read requests to home agent",
193 "Counter": "0,1,2,3", 194 "Counter": "0,1,2,3",
194 "EventCode": "0x1", 195 "EventCode": "0x1",
195 "EventName": "UNC_H_REQUESTS.READS", 196 "EventName": "UNC_H_REQUESTS.READS",
@@ -198,7 +199,7 @@
198 "Unit": "HA" 199 "Unit": "HA"
199 }, 200 },
200 { 201 {
201 "BriefDescription": "write requests to home agent. Derived from unc_h_requests.writes", 202 "BriefDescription": "write requests to home agent",
202 "Counter": "0,1,2,3", 203 "Counter": "0,1,2,3",
203 "EventCode": "0x1", 204 "EventCode": "0x1",
204 "EventName": "UNC_H_REQUESTS.WRITES", 205 "EventName": "UNC_H_REQUESTS.WRITES",
diff --git a/tools/perf/pmu-events/arch/x86/jaketown/uncore-interconnect.json b/tools/perf/pmu-events/arch/x86/jaketown/uncore-interconnect.json
index 63351876eb57..1b53c0e609e3 100644
--- a/tools/perf/pmu-events/arch/x86/jaketown/uncore-interconnect.json
+++ b/tools/perf/pmu-events/arch/x86/jaketown/uncore-interconnect.json
@@ -1,6 +1,6 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "QPI clock ticks. Used to get percentages of QPI cycles events. Derived from unc_q_clockticks", 3 "BriefDescription": "QPI clock ticks. Used to get percentages of QPI cycles events",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventCode": "0x14", 5 "EventCode": "0x14",
6 "EventName": "UNC_Q_CLOCKTICKS", 6 "EventName": "UNC_Q_CLOCKTICKS",
@@ -8,25 +8,27 @@
8 "Unit": "QPI LL" 8 "Unit": "QPI LL"
9 }, 9 },
10 { 10 {
11 "BriefDescription": "Cycles where receiving QPI link is in half-width mode. Derived from unc_q_rxl0p_power_cycles", 11 "BriefDescription": "Cycles where receiving QPI link is in half-width mode",
12 "Counter": "0,1,2,3", 12 "Counter": "0,1,2,3",
13 "EventCode": "0x10", 13 "EventCode": "0x10",
14 "EventName": "UNC_Q_RxL0P_POWER_CYCLES", 14 "EventName": "UNC_Q_RxL0P_POWER_CYCLES",
15 "MetricExpr": "(UNC_Q_RxL0P_POWER_CYCLES / UNC_Q_CLOCKTICKS) * 100.", 15 "MetricExpr": "(UNC_Q_RxL0P_POWER_CYCLES / UNC_Q_CLOCKTICKS) * 100.",
16 "MetricName": "rxl0p_power_cycles %",
16 "PerPkg": "1", 17 "PerPkg": "1",
17 "Unit": "QPI LL" 18 "Unit": "QPI LL"
18 }, 19 },
19 { 20 {
20 "BriefDescription": "Cycles where transmitting QPI link is in half-width mode. Derived from unc_q_txl0p_power_cycles", 21 "BriefDescription": "Cycles where transmitting QPI link is in half-width mode",
21 "Counter": "0,1,2,3", 22 "Counter": "0,1,2,3",
22 "EventCode": "0xd", 23 "EventCode": "0xd",
23 "EventName": "UNC_Q_TxL0P_POWER_CYCLES", 24 "EventName": "UNC_Q_TxL0P_POWER_CYCLES",
24 "MetricExpr": "(UNC_Q_TxL0P_POWER_CYCLES / UNC_Q_CLOCKTICKS) * 100.", 25 "MetricExpr": "(UNC_Q_TxL0P_POWER_CYCLES / UNC_Q_CLOCKTICKS) * 100.",
26 "MetricName": "txl0p_power_cycles %",
25 "PerPkg": "1", 27 "PerPkg": "1",
26 "Unit": "QPI LL" 28 "Unit": "QPI LL"
27 }, 29 },
28 { 30 {
29 "BriefDescription": "Number of data flits transmitted . Derived from unc_q_txl_flits_g0.data", 31 "BriefDescription": "Number of data flits transmitted ",
30 "Counter": "0,1,2,3", 32 "Counter": "0,1,2,3",
31 "EventName": "UNC_Q_TxL_FLITS_G0.DATA", 33 "EventName": "UNC_Q_TxL_FLITS_G0.DATA",
32 "PerPkg": "1", 34 "PerPkg": "1",
@@ -35,7 +37,7 @@
35 "Unit": "QPI LL" 37 "Unit": "QPI LL"
36 }, 38 },
37 { 39 {
38 "BriefDescription": "Number of non data (control) flits transmitted . Derived from unc_q_txl_flits_g0.non_data", 40 "BriefDescription": "Number of non data (control) flits transmitted ",
39 "Counter": "0,1,2,3", 41 "Counter": "0,1,2,3",
40 "EventName": "UNC_Q_TxL_FLITS_G0.NON_DATA", 42 "EventName": "UNC_Q_TxL_FLITS_G0.NON_DATA",
41 "PerPkg": "1", 43 "PerPkg": "1",
diff --git a/tools/perf/pmu-events/arch/x86/jaketown/uncore-memory.json b/tools/perf/pmu-events/arch/x86/jaketown/uncore-memory.json
index e2cf6daa7b37..8551cebeba23 100644
--- a/tools/perf/pmu-events/arch/x86/jaketown/uncore-memory.json
+++ b/tools/perf/pmu-events/arch/x86/jaketown/uncore-memory.json
@@ -1,6 +1,6 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "Memory page activates. Derived from unc_m_act_count", 3 "BriefDescription": "Memory page activates",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventCode": "0x1", 5 "EventCode": "0x1",
6 "EventName": "UNC_M_ACT_COUNT", 6 "EventName": "UNC_M_ACT_COUNT",
@@ -11,7 +11,7 @@
11 "BriefDescription": "read requests to memory controller. Derived from unc_m_cas_count.rd", 11 "BriefDescription": "read requests to memory controller. Derived from unc_m_cas_count.rd",
12 "Counter": "0,1,2,3", 12 "Counter": "0,1,2,3",
13 "EventCode": "0x4", 13 "EventCode": "0x4",
14 "EventName": "UNC_M_CAS_COUNT.RD", 14 "EventName": "LLC_MISSES.MEM_READ",
15 "PerPkg": "1", 15 "PerPkg": "1",
16 "UMask": "0x3", 16 "UMask": "0x3",
17 "Unit": "iMC" 17 "Unit": "iMC"
@@ -20,47 +20,50 @@
20 "BriefDescription": "write requests to memory controller. Derived from unc_m_cas_count.wr", 20 "BriefDescription": "write requests to memory controller. Derived from unc_m_cas_count.wr",
21 "Counter": "0,1,2,3", 21 "Counter": "0,1,2,3",
22 "EventCode": "0x4", 22 "EventCode": "0x4",
23 "EventName": "UNC_M_CAS_COUNT.WR", 23 "EventName": "LLC_MISSES.MEM_WRITE",
24 "PerPkg": "1", 24 "PerPkg": "1",
25 "UMask": "0xc", 25 "UMask": "0xc",
26 "Unit": "iMC" 26 "Unit": "iMC"
27 }, 27 },
28 { 28 {
29 "BriefDescription": "Memory controller clock ticks. Used to get percentages of memory controller cycles events. Derived from unc_m_clockticks", 29 "BriefDescription": "Memory controller clock ticks. Used to get percentages of memory controller cycles events",
30 "Counter": "0,1,2,3", 30 "Counter": "0,1,2,3",
31 "EventName": "UNC_M_CLOCKTICKS", 31 "EventName": "UNC_M_CLOCKTICKS",
32 "PerPkg": "1", 32 "PerPkg": "1",
33 "Unit": "iMC" 33 "Unit": "iMC"
34 }, 34 },
35 { 35 {
36 "BriefDescription": "Cycles where DRAM ranks are in power down (CKE) mode. Derived from unc_m_power_channel_ppd", 36 "BriefDescription": "Cycles where DRAM ranks are in power down (CKE) mode",
37 "Counter": "0,1,2,3", 37 "Counter": "0,1,2,3",
38 "EventCode": "0x85", 38 "EventCode": "0x85",
39 "EventName": "UNC_M_POWER_CHANNEL_PPD", 39 "EventName": "UNC_M_POWER_CHANNEL_PPD",
40 "MetricExpr": "(UNC_M_POWER_CHANNEL_PPD / UNC_M_CLOCKTICKS) * 100.", 40 "MetricExpr": "(UNC_M_POWER_CHANNEL_PPD / UNC_M_CLOCKTICKS) * 100.",
41 "MetricName": "power_channel_ppd %",
41 "PerPkg": "1", 42 "PerPkg": "1",
42 "Unit": "iMC" 43 "Unit": "iMC"
43 }, 44 },
44 { 45 {
45 "BriefDescription": "Cycles all ranks are in critical thermal throttle. Derived from unc_m_power_critical_throttle_cycles", 46 "BriefDescription": "Cycles all ranks are in critical thermal throttle",
46 "Counter": "0,1,2,3", 47 "Counter": "0,1,2,3",
47 "EventCode": "0x86", 48 "EventCode": "0x86",
48 "EventName": "UNC_M_POWER_CRITICAL_THROTTLE_CYCLES", 49 "EventName": "UNC_M_POWER_CRITICAL_THROTTLE_CYCLES",
49 "MetricExpr": "(UNC_M_POWER_CRITICAL_THROTTLE_CYCLES / UNC_M_CLOCKTICKS) * 100.", 50 "MetricExpr": "(UNC_M_POWER_CRITICAL_THROTTLE_CYCLES / UNC_M_CLOCKTICKS) * 100.",
51 "MetricName": "power_critical_throttle_cycles %",
50 "PerPkg": "1", 52 "PerPkg": "1",
51 "Unit": "iMC" 53 "Unit": "iMC"
52 }, 54 },
53 { 55 {
54 "BriefDescription": "Cycles Memory is in self refresh power mode. Derived from unc_m_power_self_refresh", 56 "BriefDescription": "Cycles Memory is in self refresh power mode",
55 "Counter": "0,1,2,3", 57 "Counter": "0,1,2,3",
56 "EventCode": "0x43", 58 "EventCode": "0x43",
57 "EventName": "UNC_M_POWER_SELF_REFRESH", 59 "EventName": "UNC_M_POWER_SELF_REFRESH",
58 "MetricExpr": "(UNC_M_POWER_SELF_REFRESH / UNC_M_CLOCKTICKS) * 100.", 60 "MetricExpr": "(UNC_M_POWER_SELF_REFRESH / UNC_M_CLOCKTICKS) * 100.",
61 "MetricName": "power_self_refresh %",
59 "PerPkg": "1", 62 "PerPkg": "1",
60 "Unit": "iMC" 63 "Unit": "iMC"
61 }, 64 },
62 { 65 {
63 "BriefDescription": "Memory page conflicts. Derived from unc_m_pre_count.page_miss", 66 "BriefDescription": "Memory page conflicts",
64 "Counter": "0,1,2,3", 67 "Counter": "0,1,2,3",
65 "EventCode": "0x2", 68 "EventCode": "0x2",
66 "EventName": "UNC_M_PRE_COUNT.PAGE_MISS", 69 "EventName": "UNC_M_PRE_COUNT.PAGE_MISS",
@@ -69,7 +72,7 @@
69 "Unit": "iMC" 72 "Unit": "iMC"
70 }, 73 },
71 { 74 {
72 "BriefDescription": "Occupancy counter for memory read queue. Derived from unc_m_rpq_occupancy", 75 "BriefDescription": "Occupancy counter for memory read queue",
73 "Counter": "0,1,2,3", 76 "Counter": "0,1,2,3",
74 "EventCode": "0x80", 77 "EventCode": "0x80",
75 "EventName": "UNC_M_RPQ_OCCUPANCY", 78 "EventName": "UNC_M_RPQ_OCCUPANCY",
diff --git a/tools/perf/pmu-events/arch/x86/jaketown/uncore-power.json b/tools/perf/pmu-events/arch/x86/jaketown/uncore-power.json
index bbe36d547386..16034bfd06dd 100644
--- a/tools/perf/pmu-events/arch/x86/jaketown/uncore-power.json
+++ b/tools/perf/pmu-events/arch/x86/jaketown/uncore-power.json
@@ -1,44 +1,48 @@
1[ 1[
2 { 2 {
3 "BriefDescription": "PCU clock ticks. Use to get percentages of PCU cycles events. Derived from unc_p_clockticks", 3 "BriefDescription": "PCU clock ticks. Use to get percentages of PCU cycles events",
4 "Counter": "0,1,2,3", 4 "Counter": "0,1,2,3",
5 "EventName": "UNC_P_CLOCKTICKS", 5 "EventName": "UNC_P_CLOCKTICKS",
6 "PerPkg": "1", 6 "PerPkg": "1",
7 "Unit": "PCU" 7 "Unit": "PCU"
8 }, 8 },
9 { 9 {
10 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band0=XXX with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency. Derived from unc_p_freq_band0_cycles", 10 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band0=XXX with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency",
11 "Counter": "0,1,2,3", 11 "Counter": "0,1,2,3",
12 "EventCode": "0xb", 12 "EventCode": "0xb",
13 "EventName": "UNC_P_FREQ_BAND0_CYCLES", 13 "EventName": "UNC_P_FREQ_BAND0_CYCLES",
14 "MetricExpr": "(UNC_P_FREQ_BAND0_CYCLES / UNC_P_CLOCKTICKS) * 100.", 14 "MetricExpr": "(UNC_P_FREQ_BAND0_CYCLES / UNC_P_CLOCKTICKS) * 100.",
15 "MetricName": "freq_band0_cycles %",
15 "PerPkg": "1", 16 "PerPkg": "1",
16 "Unit": "PCU" 17 "Unit": "PCU"
17 }, 18 },
18 { 19 {
19 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band1=XXX with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency. Derived from unc_p_freq_band1_cycles", 20 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band1=XXX with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency",
20 "Counter": "0,1,2,3", 21 "Counter": "0,1,2,3",
21 "EventCode": "0xc", 22 "EventCode": "0xc",
22 "EventName": "UNC_P_FREQ_BAND1_CYCLES", 23 "EventName": "UNC_P_FREQ_BAND1_CYCLES",
23 "MetricExpr": "(UNC_P_FREQ_BAND1_CYCLES / UNC_P_CLOCKTICKS) * 100.", 24 "MetricExpr": "(UNC_P_FREQ_BAND1_CYCLES / UNC_P_CLOCKTICKS) * 100.",
25 "MetricName": "freq_band1_cycles %",
24 "PerPkg": "1", 26 "PerPkg": "1",
25 "Unit": "PCU" 27 "Unit": "PCU"
26 }, 28 },
27 { 29 {
28 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band2=XXX with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency. Derived from unc_p_freq_band2_cycles", 30 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band2=XXX with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency",
29 "Counter": "0,1,2,3", 31 "Counter": "0,1,2,3",
30 "EventCode": "0xd", 32 "EventCode": "0xd",
31 "EventName": "UNC_P_FREQ_BAND2_CYCLES", 33 "EventName": "UNC_P_FREQ_BAND2_CYCLES",
32 "MetricExpr": "(UNC_P_FREQ_BAND2_CYCLES / UNC_P_CLOCKTICKS) * 100.", 34 "MetricExpr": "(UNC_P_FREQ_BAND2_CYCLES / UNC_P_CLOCKTICKS) * 100.",
35 "MetricName": "freq_band2_cycles %",
33 "PerPkg": "1", 36 "PerPkg": "1",
34 "Unit": "PCU" 37 "Unit": "PCU"
35 }, 38 },
36 { 39 {
37 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band3=XXX, with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency. Derived from unc_p_freq_band3_cycles", 40 "BriefDescription": "Counts the number of cycles that the uncore was running at a frequency greater than or equal to the frequency that is configured in the filter. (filter_band3=XXX, with XXX in 100Mhz units). One can also use inversion (filter_inv=1) to track cycles when we were less than the configured frequency",
38 "Counter": "0,1,2,3", 41 "Counter": "0,1,2,3",
39 "EventCode": "0xe", 42 "EventCode": "0xe",
40 "EventName": "UNC_P_FREQ_BAND3_CYCLES", 43 "EventName": "UNC_P_FREQ_BAND3_CYCLES",
41 "MetricExpr": "(UNC_P_FREQ_BAND3_CYCLES / UNC_P_CLOCKTICKS) * 100.", 44 "MetricExpr": "(UNC_P_FREQ_BAND3_CYCLES / UNC_P_CLOCKTICKS) * 100.",
45 "MetricName": "freq_band3_cycles %",
42 "PerPkg": "1", 46 "PerPkg": "1",
43 "Unit": "PCU" 47 "Unit": "PCU"
44 }, 48 },
@@ -49,6 +53,7 @@
49 "EventName": "UNC_P_FREQ_BAND0_TRANSITIONS", 53 "EventName": "UNC_P_FREQ_BAND0_TRANSITIONS",
50 "Filter": "edge=1", 54 "Filter": "edge=1",
51 "MetricExpr": "(UNC_P_FREQ_BAND0_CYCLES / UNC_P_CLOCKTICKS) * 100.", 55 "MetricExpr": "(UNC_P_FREQ_BAND0_CYCLES / UNC_P_CLOCKTICKS) * 100.",
56 "MetricName": "freq_band0_cycles %",
52 "PerPkg": "1", 57 "PerPkg": "1",
53 "Unit": "PCU" 58 "Unit": "PCU"
54 }, 59 },
@@ -59,6 +64,7 @@
59 "EventName": "UNC_P_FREQ_BAND1_TRANSITIONS", 64 "EventName": "UNC_P_FREQ_BAND1_TRANSITIONS",
60 "Filter": "edge=1", 65 "Filter": "edge=1",
61 "MetricExpr": "(UNC_P_FREQ_BAND1_CYCLES / UNC_P_CLOCKTICKS) * 100.", 66 "MetricExpr": "(UNC_P_FREQ_BAND1_CYCLES / UNC_P_CLOCKTICKS) * 100.",
67 "MetricName": "freq_band1_cycles %",
62 "PerPkg": "1", 68 "PerPkg": "1",
63 "Unit": "PCU" 69 "Unit": "PCU"
64 }, 70 },
@@ -69,6 +75,7 @@
69 "EventName": "UNC_P_FREQ_BAND2_TRANSITIONS", 75 "EventName": "UNC_P_FREQ_BAND2_TRANSITIONS",
70 "Filter": "edge=1", 76 "Filter": "edge=1",
71 "MetricExpr": "(UNC_P_FREQ_BAND2_CYCLES / UNC_P_CLOCKTICKS) * 100.", 77 "MetricExpr": "(UNC_P_FREQ_BAND2_CYCLES / UNC_P_CLOCKTICKS) * 100.",
78 "MetricName": "freq_band2_cycles %",
72 "PerPkg": "1", 79 "PerPkg": "1",
73 "Unit": "PCU" 80 "Unit": "PCU"
74 }, 81 },
@@ -79,89 +86,99 @@
79 "EventName": "UNC_P_FREQ_BAND3_TRANSITIONS", 86 "EventName": "UNC_P_FREQ_BAND3_TRANSITIONS",
80 "Filter": "edge=1", 87 "Filter": "edge=1",
81 "MetricExpr": "(UNC_P_FREQ_BAND3_CYCLES / UNC_P_CLOCKTICKS) * 100.", 88 "MetricExpr": "(UNC_P_FREQ_BAND3_CYCLES / UNC_P_CLOCKTICKS) * 100.",
89 "MetricName": "freq_band3_cycles %",
82 "PerPkg": "1", 90 "PerPkg": "1",
83 "Unit": "PCU" 91 "Unit": "PCU"
84 }, 92 },
85 { 93 {
86 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C0. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details. Derived from unc_p_power_state_occupancy.cores_c0", 94 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C0. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details",
87 "Counter": "0,1,2,3", 95 "Counter": "0,1,2,3",
88 "EventCode": "0x80", 96 "EventCode": "0x80",
89 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C0", 97 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C0",
90 "Filter": "occ_sel=1", 98 "Filter": "occ_sel=1",
91 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C0 / UNC_P_CLOCKTICKS) * 100.", 99 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C0 / UNC_P_CLOCKTICKS) * 100.",
100 "MetricName": "power_state_occupancy.cores_c0 %",
92 "PerPkg": "1", 101 "PerPkg": "1",
93 "Unit": "PCU" 102 "Unit": "PCU"
94 }, 103 },
95 { 104 {
96 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C3. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details. Derived from unc_p_power_state_occupancy.cores_c3", 105 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C3. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events and occupancy triggering to capture other details",
97 "Counter": "0,1,2,3", 106 "Counter": "0,1,2,3",
98 "EventCode": "0x80", 107 "EventCode": "0x80",
99 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C3", 108 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C3",
100 "Filter": "occ_sel=2", 109 "Filter": "occ_sel=2",
101 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C3 / UNC_P_CLOCKTICKS) * 100.", 110 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C3 / UNC_P_CLOCKTICKS) * 100.",
111 "MetricName": "power_state_occupancy.cores_c3 %",
102 "PerPkg": "1", 112 "PerPkg": "1",
103 "Unit": "PCU" 113 "Unit": "PCU"
104 }, 114 },
105 { 115 {
106 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C6. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events . Derived from unc_p_power_state_occupancy.cores_c6", 116 "BriefDescription": "This is an occupancy event that tracks the number of cores that are in C6. It can be used by itself to get the average number of cores in C0, with threshholding to generate histograms, or with other PCU events ",
107 "Counter": "0,1,2,3", 117 "Counter": "0,1,2,3",
108 "EventCode": "0x80", 118 "EventCode": "0x80",
109 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C6", 119 "EventName": "UNC_P_POWER_STATE_OCCUPANCY.CORES_C6",
110 "Filter": "occ_sel=3", 120 "Filter": "occ_sel=3",
111 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C6 / UNC_P_CLOCKTICKS) * 100.", 121 "MetricExpr": "(UNC_P_POWER_STATE_OCCUPANCY.CORES_C6 / UNC_P_CLOCKTICKS) * 100.",
122 "MetricName": "power_state_occupancy.cores_c6 %",
112 "PerPkg": "1", 123 "PerPkg": "1",
113 "Unit": "PCU" 124 "Unit": "PCU"
114 }, 125 },
115 { 126 {
116 "BriefDescription": "Counts the number of cycles that we are in external PROCHOT mode. This mode is triggered when a sensor off the die determines that something off-die (like DRAM) is too hot and must throttle to avoid damaging the chip. Derived from unc_p_prochot_external_cycles", 127 "BriefDescription": "Counts the number of cycles that we are in external PROCHOT mode. This mode is triggered when a sensor off the die determines that something off-die (like DRAM) is too hot and must throttle to avoid damaging the chip",
117 "Counter": "0,1,2,3", 128 "Counter": "0,1,2,3",
118 "EventCode": "0xa", 129 "EventCode": "0xa",
119 "EventName": "UNC_P_PROCHOT_EXTERNAL_CYCLES", 130 "EventName": "UNC_P_PROCHOT_EXTERNAL_CYCLES",
120 "MetricExpr": "(UNC_P_PROCHOT_EXTERNAL_CYCLES / UNC_P_CLOCKTICKS) * 100.", 131 "MetricExpr": "(UNC_P_PROCHOT_EXTERNAL_CYCLES / UNC_P_CLOCKTICKS) * 100.",
132 "MetricName": "prochot_external_cycles %",
121 "PerPkg": "1", 133 "PerPkg": "1",
122 "Unit": "PCU" 134 "Unit": "PCU"
123 }, 135 },
124 { 136 {
125 "BriefDescription": "Counts the number of cycles when temperature is the upper limit on frequency. Derived from unc_p_freq_max_limit_thermal_cycles", 137 "BriefDescription": "Counts the number of cycles when temperature is the upper limit on frequency",
126 "Counter": "0,1,2,3", 138 "Counter": "0,1,2,3",
127 "EventCode": "0x4", 139 "EventCode": "0x4",
128 "EventName": "UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES", 140 "EventName": "UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES",
129 "MetricExpr": "(UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES / UNC_P_CLOCKTICKS) * 100.", 141 "MetricExpr": "(UNC_P_FREQ_MAX_LIMIT_THERMAL_CYCLES / UNC_P_CLOCKTICKS) * 100.",
142 "MetricName": "freq_max_limit_thermal_cycles %",
130 "PerPkg": "1", 143 "PerPkg": "1",
131 "Unit": "PCU" 144 "Unit": "PCU"
132 }, 145 },
133 { 146 {
134 "BriefDescription": "Counts the number of cycles when the OS is the upper limit on frequency. Derived from unc_p_freq_max_os_cycles", 147 "BriefDescription": "Counts the number of cycles when the OS is the upper limit on frequency",
135 "Counter": "0,1,2,3", 148 "Counter": "0,1,2,3",
136 "EventCode": "0x6", 149 "EventCode": "0x6",
137 "EventName": "UNC_P_FREQ_MAX_OS_CYCLES", 150 "EventName": "UNC_P_FREQ_MAX_OS_CYCLES",
138 "MetricExpr": "(UNC_P_FREQ_MAX_OS_CYCLES / UNC_P_CLOCKTICKS) * 100.", 151 "MetricExpr": "(UNC_P_FREQ_MAX_OS_CYCLES / UNC_P_CLOCKTICKS) * 100.",
152 "MetricName": "freq_max_os_cycles %",
139 "PerPkg": "1", 153 "PerPkg": "1",
140 "Unit": "PCU" 154 "Unit": "PCU"
141 }, 155 },
142 { 156 {
143 "BriefDescription": "Counts the number of cycles when power is the upper limit on frequency. Derived from unc_p_freq_max_power_cycles", 157 "BriefDescription": "Counts the number of cycles when power is the upper limit on frequency",
144 "Counter": "0,1,2,3", 158 "Counter": "0,1,2,3",
145 "EventCode": "0x5", 159 "EventCode": "0x5",
146 "EventName": "UNC_P_FREQ_MAX_POWER_CYCLES", 160 "EventName": "UNC_P_FREQ_MAX_POWER_CYCLES",
147 "MetricExpr": "(UNC_P_FREQ_MAX_POWER_CYCLES / UNC_P_CLOCKTICKS) * 100.", 161 "MetricExpr": "(UNC_P_FREQ_MAX_POWER_CYCLES / UNC_P_CLOCKTICKS) * 100.",
162 "MetricName": "freq_max_power_cycles %",
148 "PerPkg": "1", 163 "PerPkg": "1",
149 "Unit": "PCU" 164 "Unit": "PCU"
150 }, 165 },
151 { 166 {
152 "BriefDescription": "Counts the number of cycles when current is the upper limit on frequency. Derived from unc_p_freq_max_current_cycles", 167 "BriefDescription": "Counts the number of cycles when current is the upper limit on frequency",
153 "Counter": "0,1,2,3", 168 "Counter": "0,1,2,3",
154 "EventCode": "0x7", 169 "EventCode": "0x7",
155 "EventName": "UNC_P_FREQ_MAX_CURRENT_CYCLES", 170 "EventName": "UNC_P_FREQ_MAX_CURRENT_CYCLES",
156 "MetricExpr": "(UNC_P_FREQ_MAX_CURRENT_CYCLES / UNC_P_CLOCKTICKS) * 100.", 171 "MetricExpr": "(UNC_P_FREQ_MAX_CURRENT_CYCLES / UNC_P_CLOCKTICKS) * 100.",
172 "MetricName": "freq_max_current_cycles %",
157 "PerPkg": "1", 173 "PerPkg": "1",
158 "Unit": "PCU" 174 "Unit": "PCU"
159 }, 175 },
160 { 176 {
161 "BriefDescription": "Cycles spent changing Frequency. Derived from unc_p_freq_trans_cycles", 177 "BriefDescription": "Cycles spent changing Frequency",
162 "Counter": "0,1,2,3", 178 "Counter": "0,1,2,3",
163 "EventName": "UNC_P_FREQ_TRANS_CYCLES", 179 "EventName": "UNC_P_FREQ_TRANS_CYCLES",
164 "MetricExpr": "(UNC_P_FREQ_TRANS_CYCLES / UNC_P_CLOCKTICKS) * 100.", 180 "MetricExpr": "(UNC_P_FREQ_TRANS_CYCLES / UNC_P_CLOCKTICKS) * 100.",
181 "MetricName": "freq_trans_cycles %",
165 "PerPkg": "1", 182 "PerPkg": "1",
166 "Unit": "PCU" 183 "Unit": "PCU"
167 }, 184 },
@@ -172,6 +189,7 @@
172 "EventName": "UNC_P_FREQ_GE_1200MHZ_CYCLES", 189 "EventName": "UNC_P_FREQ_GE_1200MHZ_CYCLES",
173 "Filter": "filter_band0=1200", 190 "Filter": "filter_band0=1200",
174 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 191 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
192 "MetricName": "freq_ge_1200mhz_cycles %",
175 "PerPkg": "1", 193 "PerPkg": "1",
176 "Unit": "PCU" 194 "Unit": "PCU"
177 }, 195 },
@@ -182,6 +200,7 @@
182 "EventName": "UNC_P_FREQ_GE_2000MHZ_CYCLES", 200 "EventName": "UNC_P_FREQ_GE_2000MHZ_CYCLES",
183 "Filter": "filter_band1=2000", 201 "Filter": "filter_band1=2000",
184 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 202 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
203 "MetricName": "freq_ge_2000mhz_cycles %",
185 "PerPkg": "1", 204 "PerPkg": "1",
186 "Unit": "PCU" 205 "Unit": "PCU"
187 }, 206 },
@@ -192,6 +211,7 @@
192 "EventName": "UNC_P_FREQ_GE_3000MHZ_CYCLES", 211 "EventName": "UNC_P_FREQ_GE_3000MHZ_CYCLES",
193 "Filter": "filter_band2=3000", 212 "Filter": "filter_band2=3000",
194 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 213 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
214 "MetricName": "freq_ge_3000mhz_cycles %",
195 "PerPkg": "1", 215 "PerPkg": "1",
196 "Unit": "PCU" 216 "Unit": "PCU"
197 }, 217 },
@@ -202,6 +222,7 @@
202 "EventName": "UNC_P_FREQ_GE_4000MHZ_CYCLES", 222 "EventName": "UNC_P_FREQ_GE_4000MHZ_CYCLES",
203 "Filter": "filter_band3=4000", 223 "Filter": "filter_band3=4000",
204 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 224 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
225 "MetricName": "freq_ge_4000mhz_cycles %",
205 "PerPkg": "1", 226 "PerPkg": "1",
206 "Unit": "PCU" 227 "Unit": "PCU"
207 }, 228 },
@@ -212,6 +233,7 @@
212 "EventName": "UNC_P_FREQ_GE_1200MHZ_TRANSITIONS", 233 "EventName": "UNC_P_FREQ_GE_1200MHZ_TRANSITIONS",
213 "Filter": "edge=1,filter_band0=1200", 234 "Filter": "edge=1,filter_band0=1200",
214 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 235 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
236 "MetricName": "freq_ge_1200mhz_cycles %",
215 "PerPkg": "1", 237 "PerPkg": "1",
216 "Unit": "PCU" 238 "Unit": "PCU"
217 }, 239 },
@@ -222,6 +244,7 @@
222 "EventName": "UNC_P_FREQ_GE_2000MHZ_TRANSITIONS", 244 "EventName": "UNC_P_FREQ_GE_2000MHZ_TRANSITIONS",
223 "Filter": "edge=1,filter_band1=2000", 245 "Filter": "edge=1,filter_band1=2000",
224 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 246 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
247 "MetricName": "freq_ge_2000mhz_cycles %",
225 "PerPkg": "1", 248 "PerPkg": "1",
226 "Unit": "PCU" 249 "Unit": "PCU"
227 }, 250 },
@@ -232,6 +255,7 @@
232 "EventName": "UNC_P_FREQ_GE_3000MHZ_TRANSITIONS", 255 "EventName": "UNC_P_FREQ_GE_3000MHZ_TRANSITIONS",
233 "Filter": "edge=1,filter_band2=4000", 256 "Filter": "edge=1,filter_band2=4000",
234 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 257 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
258 "MetricName": "freq_ge_3000mhz_cycles %",
235 "PerPkg": "1", 259 "PerPkg": "1",
236 "Unit": "PCU" 260 "Unit": "PCU"
237 }, 261 },
@@ -242,6 +266,7 @@
242 "EventName": "UNC_P_FREQ_GE_4000MHZ_TRANSITIONS", 266 "EventName": "UNC_P_FREQ_GE_4000MHZ_TRANSITIONS",
243 "Filter": "edge=1,filter_band3=4000", 267 "Filter": "edge=1,filter_band3=4000",
244 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.", 268 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 100.",
269 "MetricName": "freq_ge_4000mhz_cycles %",
245 "PerPkg": "1", 270 "PerPkg": "1",
246 "Unit": "PCU" 271 "Unit": "PCU"
247 } 272 }
diff --git a/tools/perf/pmu-events/arch/x86/mapfile.csv b/tools/perf/pmu-events/arch/x86/mapfile.csv
index 12181bb1da2a..d1a12e584c1b 100644
--- a/tools/perf/pmu-events/arch/x86/mapfile.csv
+++ b/tools/perf/pmu-events/arch/x86/mapfile.csv
@@ -17,6 +17,7 @@ GenuineIntel-6-3A,v18,ivybridge,core
17GenuineIntel-6-3E,v19,ivytown,core 17GenuineIntel-6-3E,v19,ivytown,core
18GenuineIntel-6-2D,v20,jaketown,core 18GenuineIntel-6-2D,v20,jaketown,core
19GenuineIntel-6-57,v9,knightslanding,core 19GenuineIntel-6-57,v9,knightslanding,core
20GenuineIntel-6-85,v9,knightslanding,core
20GenuineIntel-6-1E,v2,nehalemep,core 21GenuineIntel-6-1E,v2,nehalemep,core
21GenuineIntel-6-1F,v2,nehalemep,core 22GenuineIntel-6-1F,v2,nehalemep,core
22GenuineIntel-6-1A,v2,nehalemep,core 23GenuineIntel-6-1A,v2,nehalemep,core
diff --git a/tools/perf/pmu-events/arch/x86/sandybridge/uncore.json b/tools/perf/pmu-events/arch/x86/sandybridge/uncore.json
new file mode 100644
index 000000000000..42c70eed05a2
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/sandybridge/uncore.json
@@ -0,0 +1,314 @@
1[
2 {
3 "Unit": "CBO",
4 "EventCode": "0x22",
5 "UMask": "0x01",
6 "EventName": "UNC_CBO_XSNP_RESPONSE.MISS",
7 "BriefDescription": "A snoop misses in some processor core.",
8 "PublicDescription": "A snoop misses in some processor core.",
9 "Counter": "0,1",
10 "CounterMask": "0",
11 "Invert": "0",
12 "EdgeDetect": "0"
13 },
14 {
15 "Unit": "CBO",
16 "EventCode": "0x22",
17 "UMask": "0x02",
18 "EventName": "UNC_CBO_XSNP_RESPONSE.INVAL",
19 "BriefDescription": "A snoop invalidates a non-modified line in some processor core.",
20 "PublicDescription": "A snoop invalidates a non-modified line in some processor core.",
21 "Counter": "0,1",
22 "CounterMask": "0",
23 "Invert": "0",
24 "EdgeDetect": "0"
25 },
26 {
27 "Unit": "CBO",
28 "EventCode": "0x22",
29 "UMask": "0x04",
30 "EventName": "UNC_CBO_XSNP_RESPONSE.HIT",
31 "BriefDescription": "A snoop hits a non-modified line in some processor core.",
32 "PublicDescription": "A snoop hits a non-modified line in some processor core.",
33 "Counter": "0,1",
34 "CounterMask": "0",
35 "Invert": "0",
36 "EdgeDetect": "0"
37 },
38 {
39 "Unit": "CBO",
40 "EventCode": "0x22",
41 "UMask": "0x08",
42 "EventName": "UNC_CBO_XSNP_RESPONSE.HITM",
43 "BriefDescription": "A snoop hits a modified line in some processor core.",
44 "PublicDescription": "A snoop hits a modified line in some processor core.",
45 "Counter": "0,1",
46 "CounterMask": "0",
47 "Invert": "0",
48 "EdgeDetect": "0"
49 },
50 {
51 "Unit": "CBO",
52 "EventCode": "0x22",
53 "UMask": "0x10",
54 "EventName": "UNC_CBO_XSNP_RESPONSE.INVAL_M",
55 "BriefDescription": "A snoop invalidates a modified line in some processor core.",
56 "PublicDescription": "A snoop invalidates a modified line in some processor core.",
57 "Counter": "0,1",
58 "CounterMask": "0",
59 "Invert": "0",
60 "EdgeDetect": "0"
61 },
62 {
63 "Unit": "CBO",
64 "EventCode": "0x22",
65 "UMask": "0x20",
66 "EventName": "UNC_CBO_XSNP_RESPONSE.EXTERNAL_FILTER",
67 "BriefDescription": "Filter on cross-core snoops initiated by this Cbox due to external snoop request.",
68 "PublicDescription": "Filter on cross-core snoops initiated by this Cbox due to external snoop request.",
69 "Counter": "0,1",
70 "CounterMask": "0",
71 "Invert": "0",
72 "EdgeDetect": "0"
73 },
74 {
75 "Unit": "CBO",
76 "EventCode": "0x22",
77 "UMask": "0x40",
78 "EventName": "UNC_CBO_XSNP_RESPONSE.XCORE_FILTER",
79 "BriefDescription": "Filter on cross-core snoops initiated by this Cbox due to processor core memory request.",
80 "PublicDescription": "Filter on cross-core snoops initiated by this Cbox due to processor core memory request.",
81 "Counter": "0,1",
82 "CounterMask": "0",
83 "Invert": "0",
84 "EdgeDetect": "0"
85 },
86 {
87 "Unit": "CBO",
88 "EventCode": "0x22",
89 "UMask": "0x80",
90 "EventName": "UNC_CBO_XSNP_RESPONSE.EVICTION_FILTER",
91 "BriefDescription": "Filter on cross-core snoops initiated by this Cbox due to LLC eviction.",
92 "PublicDescription": "Filter on cross-core snoops initiated by this Cbox due to LLC eviction.",
93 "Counter": "0,1",
94 "CounterMask": "0",
95 "Invert": "0",
96 "EdgeDetect": "0"
97 },
98 {
99 "Unit": "CBO",
100 "EventCode": "0x34",
101 "UMask": "0x01",
102 "EventName": "UNC_CBO_CACHE_LOOKUP.M",
103 "BriefDescription": "LLC lookup request that access cache and found line in M-state.",
104 "PublicDescription": "LLC lookup request that access cache and found line in M-state.",
105 "Counter": "0,1",
106 "CounterMask": "0",
107 "Invert": "0",
108 "EdgeDetect": "0"
109 },
110 {
111 "Unit": "CBO",
112 "EventCode": "0x34",
113 "UMask": "0x02",
114 "EventName": "UNC_CBO_CACHE_LOOKUP.E",
115 "BriefDescription": "LLC lookup request that access cache and found line in E-state.",
116 "PublicDescription": "LLC lookup request that access cache and found line in E-state.",
117 "Counter": "0,1",
118 "CounterMask": "0",
119 "Invert": "0",
120 "EdgeDetect": "0"
121 },
122 {
123 "Unit": "CBO",
124 "EventCode": "0x34",
125 "UMask": "0x04",
126 "EventName": "UNC_CBO_CACHE_LOOKUP.S",
127 "BriefDescription": "LLC lookup request that access cache and found line in S-state.",
128 "PublicDescription": "LLC lookup request that access cache and found line in S-state.",
129 "Counter": "0,1",
130 "CounterMask": "0",
131 "Invert": "0",
132 "EdgeDetect": "0"
133 },
134 {
135 "Unit": "CBO",
136 "EventCode": "0x34",
137 "UMask": "0x08",
138 "EventName": "UNC_CBO_CACHE_LOOKUP.I",
139 "BriefDescription": "LLC lookup request that access cache and found line in I-state.",
140 "PublicDescription": "LLC lookup request that access cache and found line in I-state.",
141 "Counter": "0,1",
142 "CounterMask": "0",
143 "Invert": "0",
144 "EdgeDetect": "0"
145 },
146 {
147 "Unit": "CBO",
148 "EventCode": "0x34",
149 "UMask": "0x10",
150 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_FILTER",
151 "BriefDescription": "Filter on processor core initiated cacheable read requests.",
152 "PublicDescription": "Filter on processor core initiated cacheable read requests.",
153 "Counter": "0,1",
154 "CounterMask": "0",
155 "Invert": "0",
156 "EdgeDetect": "0"
157 },
158 {
159 "Unit": "CBO",
160 "EventCode": "0x34",
161 "UMask": "0x20",
162 "EventName": "UNC_CBO_CACHE_LOOKUP.WRITE_FILTER",
163 "BriefDescription": "Filter on processor core initiated cacheable write requests.",
164 "PublicDescription": "Filter on processor core initiated cacheable write requests.",
165 "Counter": "0,1",
166 "CounterMask": "0",
167 "Invert": "0",
168 "EdgeDetect": "0"
169 },
170 {
171 "Unit": "CBO",
172 "EventCode": "0x34",
173 "UMask": "0x40",
174 "EventName": "UNC_CBO_CACHE_LOOKUP.EXTSNP_FILTER",
175 "BriefDescription": "Filter on external snoop requests.",
176 "PublicDescription": "Filter on external snoop requests.",
177 "Counter": "0,1",
178 "CounterMask": "0",
179 "Invert": "0",
180 "EdgeDetect": "0"
181 },
182 {
183 "Unit": "CBO",
184 "EventCode": "0x34",
185 "UMask": "0x80",
186 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_REQUEST_FILTER",
187 "BriefDescription": "Filter on any IRQ or IPQ initiated requests including uncacheable, non-coherent requests.",
188 "PublicDescription": "Filter on any IRQ or IPQ initiated requests including uncacheable, non-coherent requests.",
189 "Counter": "0,1",
190 "CounterMask": "0",
191 "Invert": "0",
192 "EdgeDetect": "0"
193 },
194 {
195 "Unit": "ARB",
196 "EventCode": "0x80",
197 "UMask": "0x01",
198 "EventName": "UNC_ARB_TRK_OCCUPANCY.ALL",
199 "BriefDescription": "Counts cycles weighted by the number of requests waiting for data returning from the memory controller. Accounts for coherent and non-coherent requests initiated by IA cores, processor graphic units, or LLC.",
200 "PublicDescription": "Counts cycles weighted by the number of requests waiting for data returning from the memory controller. Accounts for coherent and non-coherent requests initiated by IA cores, processor graphic units, or LLC.",
201 "Counter": "0",
202 "CounterMask": "0",
203 "Invert": "0",
204 "EdgeDetect": "0"
205 },
206 {
207 "Unit": "ARB",
208 "EventCode": "0x81",
209 "UMask": "0x01",
210 "EventName": "UNC_ARB_TRK_REQUESTS.ALL",
211 "BriefDescription": "Counts the number of coherent and in-coherent requests initiated by IA cores, processor graphic units, or LLC.",
212 "PublicDescription": "Counts the number of coherent and in-coherent requests initiated by IA cores, processor graphic units, or LLC.",
213 "Counter": "0,1",
214 "CounterMask": "0",
215 "Invert": "0",
216 "EdgeDetect": "0"
217 },
218 {
219 "Unit": "ARB",
220 "EventCode": "0x81",
221 "UMask": "0x20",
222 "EventName": "UNC_ARB_TRK_REQUESTS.WRITES",
223 "BriefDescription": "Counts the number of allocated write entries, include full, partial, and LLC evictions.",
224 "PublicDescription": "Counts the number of allocated write entries, include full, partial, and LLC evictions.",
225 "Counter": "0,1",
226 "CounterMask": "0",
227 "Invert": "0",
228 "EdgeDetect": "0"
229 },
230 {
231 "Unit": "ARB",
232 "EventCode": "0x81",
233 "UMask": "0x80",
234 "EventName": "UNC_ARB_TRK_REQUESTS.EVICTIONS",
235 "BriefDescription": "Counts the number of LLC evictions allocated.",
236 "PublicDescription": "Counts the number of LLC evictions allocated.",
237 "Counter": "0,1",
238 "CounterMask": "0",
239 "Invert": "0",
240 "EdgeDetect": "0"
241 },
242 {
243 "Unit": "ARB",
244 "EventCode": "0x83",
245 "UMask": "0x01",
246 "EventName": "UNC_ARB_COH_TRK_OCCUPANCY.ALL",
247 "BriefDescription": "Cycles weighted by number of requests pending in Coherency Tracker.",
248 "PublicDescription": "Cycles weighted by number of requests pending in Coherency Tracker.",
249 "Counter": "0",
250 "CounterMask": "0",
251 "Invert": "0",
252 "EdgeDetect": "0"
253 },
254 {
255 "Unit": "ARB",
256 "EventCode": "0x84",
257 "UMask": "0x01",
258 "EventName": "UNC_ARB_COH_TRK_REQUESTS.ALL",
259 "BriefDescription": "Number of requests allocated in Coherency Tracker.",
260 "PublicDescription": "Number of requests allocated in Coherency Tracker.",
261 "Counter": "0,1",
262 "CounterMask": "0",
263 "Invert": "0",
264 "EdgeDetect": "0"
265 },
266 {
267 "Unit": "ARB",
268 "EventCode": "0x80",
269 "UMask": "0x01",
270 "EventName": "UNC_ARB_TRK_OCCUPANCY.CYCLES_WITH_ANY_REQUEST",
271 "BriefDescription": "Cycles with at least one request outstanding is waiting for data return from memory controller. Account for coherent and non-coherent requests initiated by IA Cores, Processor Graphics Unit, or LLC.",
272 "PublicDescription": "Cycles with at least one request outstanding is waiting for data return from memory controller. Account for coherent and non-coherent requests initiated by IA Cores, Processor Graphics Unit, or LLC.",
273 "Counter": "0,1",
274 "CounterMask": "1",
275 "Invert": "0",
276 "EdgeDetect": "0"
277 },
278 {
279 "Unit": "ARB",
280 "EventCode": "0x80",
281 "UMask": "0x01",
282 "EventName": "UNC_ARB_TRK_OCCUPANCY.CYCLES_OVER_HALF_FULL",
283 "BriefDescription": "Cycles with at least half of the requests outstanding are waiting for data return from memory controller. Account for coherent and non-coherent requests initiated by IA Cores, Processor Graphics Unit, or LLC.",
284 "PublicDescription": "Cycles with at least half of the requests outstanding are waiting for data return from memory controller. Account for coherent and non-coherent requests initiated by IA Cores, Processor Graphics Unit, or LLC.",
285 "Counter": "0,1",
286 "CounterMask": "10",
287 "Invert": "0",
288 "EdgeDetect": "0"
289 },
290 {
291 "Unit": "ARB",
292 "EventCode": "0x0",
293 "UMask": "0x01",
294 "EventName": "UNC_CLOCK.SOCKET",
295 "BriefDescription": "This 48-bit fixed counter counts the UCLK cycles.",
296 "PublicDescription": "This 48-bit fixed counter counts the UCLK cycles.",
297 "Counter": "Fixed",
298 "CounterMask": "0",
299 "Invert": "0",
300 "EdgeDetect": "0"
301 },
302 {
303 "Unit": "CBO",
304 "EventCode": "0x34",
305 "UMask": "0x06",
306 "EventName": "UNC_CBO_CACHE_LOOKUP.ES",
307 "BriefDescription": "LLC lookup request that access cache and found line in E-state or S-state.",
308 "PublicDescription": "LLC lookup request that access cache and found line in E-state or S-state.",
309 "Counter": "0,1",
310 "CounterMask": "0",
311 "Invert": "0",
312 "EdgeDetect": "0"
313 }
314] \ No newline at end of file
diff --git a/tools/perf/pmu-events/arch/x86/skylake/uncore.json b/tools/perf/pmu-events/arch/x86/skylake/uncore.json
new file mode 100644
index 000000000000..dbc193252fb3
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/skylake/uncore.json
@@ -0,0 +1,254 @@
1[
2 {
3 "Unit": "CBO",
4 "EventCode": "0x22",
5 "UMask": "0x41",
6 "EventName": "UNC_CBO_XSNP_RESPONSE.MISS_XCORE",
7 "BriefDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which misses in some processor core.",
8 "PublicDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which misses in some processor core.",
9 "Counter": "0,1",
10 "CounterMask": "0",
11 "Invert": "0",
12 "EdgeDetect": "0"
13 },
14 {
15 "Unit": "CBO",
16 "EventCode": "0x22",
17 "UMask": "0x81",
18 "EventName": "UNC_CBO_XSNP_RESPONSE.MISS_EVICTION",
19 "BriefDescription": "A cross-core snoop resulted from L3 Eviction which misses in some processor core.",
20 "PublicDescription": "A cross-core snoop resulted from L3 Eviction which misses in some processor core.",
21 "Counter": "0,1",
22 "CounterMask": "0",
23 "Invert": "0",
24 "EdgeDetect": "0"
25 },
26 {
27 "Unit": "CBO",
28 "EventCode": "0x22",
29 "UMask": "0x44",
30 "EventName": "UNC_CBO_XSNP_RESPONSE.HIT_XCORE",
31 "BriefDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which hits a non-modified line in some processor core.",
32 "PublicDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which hits a non-modified line in some processor core.",
33 "Counter": "0,1",
34 "CounterMask": "0",
35 "Invert": "0",
36 "EdgeDetect": "0"
37 },
38 {
39 "Unit": "CBO",
40 "EventCode": "0x22",
41 "UMask": "0x48",
42 "EventName": "UNC_CBO_XSNP_RESPONSE.HITM_XCORE",
43 "BriefDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which hits a modified line in some processor core.",
44 "PublicDescription": "A cross-core snoop initiated by this Cbox due to processor core memory request which hits a modified line in some processor core.",
45 "Counter": "0,1",
46 "CounterMask": "0",
47 "Invert": "0",
48 "EdgeDetect": "0"
49 },
50 {
51 "Unit": "CBO",
52 "EventCode": "0x34",
53 "UMask": "0x21",
54 "EventName": "UNC_CBO_CACHE_LOOKUP.WRITE_M",
55 "BriefDescription": "L3 Lookup write request that access cache and found line in M-state",
56 "PublicDescription": "L3 Lookup write request that access cache and found line in M-state.",
57 "Counter": "0,1",
58 "CounterMask": "0",
59 "Invert": "0",
60 "EdgeDetect": "0"
61 },
62 {
63 "Unit": "CBO",
64 "EventCode": "0x34",
65 "UMask": "0x81",
66 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_M",
67 "BriefDescription": "L3 Lookup any request that access cache and found line in M-state",
68 "PublicDescription": "L3 Lookup any request that access cache and found line in M-state.",
69 "Counter": "0,1",
70 "CounterMask": "0",
71 "Invert": "0",
72 "EdgeDetect": "0"
73 },
74 {
75 "Unit": "CBO",
76 "EventCode": "0x34",
77 "UMask": "0x18",
78 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_I",
79 "BriefDescription": "L3 Lookup read request that access cache and found line in I-state",
80 "PublicDescription": "L3 Lookup read request that access cache and found line in I-state.",
81 "Counter": "0,1",
82 "CounterMask": "0",
83 "Invert": "0",
84 "EdgeDetect": "0"
85 },
86 {
87 "Unit": "CBO",
88 "EventCode": "0x34",
89 "UMask": "0x88",
90 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_I",
91 "BriefDescription": "L3 Lookup any request that access cache and found line in I-state",
92 "PublicDescription": "L3 Lookup any request that access cache and found line in I-state.",
93 "Counter": "0,1",
94 "CounterMask": "0",
95 "Invert": "0",
96 "EdgeDetect": "0"
97 },
98 {
99 "Unit": "CBO",
100 "EventCode": "0x34",
101 "UMask": "0x1f",
102 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_MESI",
103 "BriefDescription": "L3 Lookup read request that access cache and found line in any MESI-state",
104 "PublicDescription": "L3 Lookup read request that access cache and found line in any MESI-state.",
105 "Counter": "0,1",
106 "CounterMask": "0",
107 "Invert": "0",
108 "EdgeDetect": "0"
109 },
110 {
111 "Unit": "CBO",
112 "EventCode": "0x34",
113 "UMask": "0x2f",
114 "EventName": "UNC_CBO_CACHE_LOOKUP.WRITE_MESI",
115 "BriefDescription": "L3 Lookup write request that access cache and found line in MESI-state",
116 "PublicDescription": "L3 Lookup write request that access cache and found line in MESI-state.",
117 "Counter": "0,1",
118 "CounterMask": "0",
119 "Invert": "0",
120 "EdgeDetect": "0"
121 },
122 {
123 "Unit": "CBO",
124 "EventCode": "0x34",
125 "UMask": "0x8f",
126 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_MESI",
127 "BriefDescription": "L3 Lookup any request that access cache and found line in MESI-state",
128 "PublicDescription": "L3 Lookup any request that access cache and found line in MESI-state.",
129 "Counter": "0,1",
130 "CounterMask": "0",
131 "Invert": "0",
132 "EdgeDetect": "0"
133 },
134 {
135 "Unit": "CBO",
136 "EventCode": "0x34",
137 "UMask": "0x86",
138 "EventName": "UNC_CBO_CACHE_LOOKUP.ANY_ES",
139 "BriefDescription": "L3 Lookup any request that access cache and found line in E or S-state",
140 "PublicDescription": "L3 Lookup any request that access cache and found line in E or S-state.",
141 "Counter": "0,1",
142 "CounterMask": "0",
143 "Invert": "0",
144 "EdgeDetect": "0"
145 },
146 {
147 "Unit": "CBO",
148 "EventCode": "0x34",
149 "UMask": "0x16",
150 "EventName": "UNC_CBO_CACHE_LOOKUP.READ_ES",
151 "BriefDescription": "L3 Lookup read request that access cache and found line in E or S-state",
152 "PublicDescription": "L3 Lookup read request that access cache and found line in E or S-state.",
153 "Counter": "0,1",
154 "CounterMask": "0",
155 "Invert": "0",
156 "EdgeDetect": "0"
157 },
158 {
159 "Unit": "CBO",
160 "EventCode": "0x34",
161 "UMask": "0x26",
162 "EventName": "UNC_CBO_CACHE_LOOKUP.WRITE_ES",
163 "BriefDescription": "L3 Lookup write request that access cache and found line in E or S-state",
164 "PublicDescription": "L3 Lookup write request that access cache and found line in E or S-state.",
165 "Counter": "0,1",
166 "CounterMask": "0",
167 "Invert": "0",
168 "EdgeDetect": "0"
169 },
170 {
171 "Unit": "iMPH-U",
172 "EventCode": "0x80",
173 "UMask": "0x01",
174 "EventName": "UNC_ARB_TRK_OCCUPANCY.ALL",
175 "BriefDescription": "Each cycle count number of all Core outgoing valid entries. Such entry is defined as valid from its allocation till first of IDI0 or DRS0 messages is sent out. Accounts for Coherent and non-coherent traffic.",
176 "PublicDescription": "Each cycle count number of all Core outgoing valid entries. Such entry is defined as valid from its allocation till first of IDI0 or DRS0 messages is sent out. Accounts for Coherent and non-coherent traffic.",
177 "Counter": "0",
178 "CounterMask": "0",
179 "Invert": "0",
180 "EdgeDetect": "0"
181 },
182 {
183 "Unit": "iMPH-U",
184 "EventCode": "0x81",
185 "UMask": "0x01",
186 "EventName": "UNC_ARB_TRK_REQUESTS.ALL",
187 "BriefDescription": "Total number of Core outgoing entries allocated. Accounts for Coherent and non-coherent traffic.",
188 "PublicDescription": "Total number of Core outgoing entries allocated. Accounts for Coherent and non-coherent traffic.",
189 "Counter": "0,1",
190 "CounterMask": "0",
191 "Invert": "0",
192 "EdgeDetect": "0"
193 },
194 {
195 "Unit": "iMPH-U",
196 "EventCode": "0x81",
197 "UMask": "0x02",
198 "EventName": "UNC_ARB_TRK_REQUESTS.DRD_DIRECT",
199 "BriefDescription": "Number of Core coherent Data Read entries allocated in DirectData mode",
200 "PublicDescription": "Number of Core coherent Data Read entries allocated in DirectData mode.",
201 "Counter": "0,1",
202 "CounterMask": "0",
203 "Invert": "0",
204 "EdgeDetect": "0"
205 },
206 {
207 "Unit": "iMPH-U",
208 "EventCode": "0x81",
209 "UMask": "0x20",
210 "EventName": "UNC_ARB_TRK_REQUESTS.WRITES",
211 "BriefDescription": "Number of Writes allocated - any write transactions: full/partials writes and evictions.",
212 "PublicDescription": "Number of Writes allocated - any write transactions: full/partials writes and evictions.",
213 "Counter": "0,1",
214 "CounterMask": "0",
215 "Invert": "0",
216 "EdgeDetect": "0"
217 },
218 {
219 "Unit": "iMPH-U",
220 "EventCode": "0x84",
221 "UMask": "0x01",
222 "EventName": "UNC_ARB_COH_TRK_REQUESTS.ALL",
223 "BriefDescription": "Number of entries allocated. Account for Any type: e.g. Snoop, Core aperture, etc.",
224 "PublicDescription": "Number of entries allocated. Account for Any type: e.g. Snoop, Core aperture, etc.",
225 "Counter": "0,1",
226 "CounterMask": "0",
227 "Invert": "0",
228 "EdgeDetect": "0"
229 },
230 {
231 "Unit": "iMPH-U",
232 "EventCode": "0x80",
233 "UMask": "0x01",
234 "EventName": "UNC_ARB_TRK_OCCUPANCY.CYCLES_WITH_ANY_REQUEST",
235 "BriefDescription": "Cycles with at least one request outstanding is waiting for data return from memory controller. Account for coherent and non-coherent requests initiated by IA Cores, Processor Graphics Unit, or LLC.;",
236 "PublicDescription": "Cycles with at least one request outstanding is waiting for data return from memory controller. Account for coherent and non-coherent requests initiated by IA Cores, Processor Graphics Unit, or LLC.",
237 "Counter": "0",
238 "CounterMask": "1",
239 "Invert": "0",
240 "EdgeDetect": "0"
241 },
242 {
243 "Unit": "NCU",
244 "EventCode": "0x0",
245 "UMask": "0x01",
246 "EventName": "UNC_CLOCK.SOCKET",
247 "BriefDescription": "This 48-bit fixed counter counts the UCLK cycles",
248 "PublicDescription": "This 48-bit fixed counter counts the UCLK cycles.",
249 "Counter": "FIXED",
250 "CounterMask": "0",
251 "Invert": "0",
252 "EdgeDetect": "0"
253 }
254] \ No newline at end of file
diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c
index eed09346a72a..baa073f38334 100644
--- a/tools/perf/pmu-events/jevents.c
+++ b/tools/perf/pmu-events/jevents.c
@@ -195,6 +195,7 @@ static struct map {
195 { "CBO", "uncore_cbox" }, 195 { "CBO", "uncore_cbox" },
196 { "QPI LL", "uncore_qpi" }, 196 { "QPI LL", "uncore_qpi" },
197 { "SBO", "uncore_sbox" }, 197 { "SBO", "uncore_sbox" },
198 { "iMPH-U", "uncore_arb" },
198 {} 199 {}
199}; 200};
200 201
@@ -291,7 +292,9 @@ static void print_events_table_prefix(FILE *fp, const char *tblname)
291 292
292static int print_events_table_entry(void *data, char *name, char *event, 293static int print_events_table_entry(void *data, char *name, char *event,
293 char *desc, char *long_desc, 294 char *desc, char *long_desc,
294 char *pmu, char *unit, char *perpkg) 295 char *pmu, char *unit, char *perpkg,
296 char *metric_expr,
297 char *metric_name)
295{ 298{
296 struct perf_entry_data *pd = data; 299 struct perf_entry_data *pd = data;
297 FILE *outfp = pd->outfp; 300 FILE *outfp = pd->outfp;
@@ -315,6 +318,10 @@ static int print_events_table_entry(void *data, char *name, char *event,
315 fprintf(outfp, "\t.unit = \"%s\",\n", unit); 318 fprintf(outfp, "\t.unit = \"%s\",\n", unit);
316 if (perpkg) 319 if (perpkg)
317 fprintf(outfp, "\t.perpkg = \"%s\",\n", perpkg); 320 fprintf(outfp, "\t.perpkg = \"%s\",\n", perpkg);
321 if (metric_expr)
322 fprintf(outfp, "\t.metric_expr = \"%s\",\n", metric_expr);
323 if (metric_name)
324 fprintf(outfp, "\t.metric_name = \"%s\",\n", metric_name);
318 fprintf(outfp, "},\n"); 325 fprintf(outfp, "},\n");
319 326
320 return 0; 327 return 0;
@@ -362,7 +369,9 @@ static char *real_event(const char *name, char *event)
362int json_events(const char *fn, 369int json_events(const char *fn,
363 int (*func)(void *data, char *name, char *event, char *desc, 370 int (*func)(void *data, char *name, char *event, char *desc,
364 char *long_desc, 371 char *long_desc,
365 char *pmu, char *unit, char *perpkg), 372 char *pmu, char *unit, char *perpkg,
373 char *metric_expr,
374 char *metric_name),
366 void *data) 375 void *data)
367{ 376{
368 int err = -EIO; 377 int err = -EIO;
@@ -388,6 +397,8 @@ int json_events(const char *fn,
388 char *filter = NULL; 397 char *filter = NULL;
389 char *perpkg = NULL; 398 char *perpkg = NULL;
390 char *unit = NULL; 399 char *unit = NULL;
400 char *metric_expr = NULL;
401 char *metric_name = NULL;
391 unsigned long long eventcode = 0; 402 unsigned long long eventcode = 0;
392 struct msrmap *msr = NULL; 403 struct msrmap *msr = NULL;
393 jsmntok_t *msrval = NULL; 404 jsmntok_t *msrval = NULL;
@@ -398,6 +409,7 @@ int json_events(const char *fn,
398 for (j = 0; j < obj->size; j += 2) { 409 for (j = 0; j < obj->size; j += 2) {
399 jsmntok_t *field, *val; 410 jsmntok_t *field, *val;
400 int nz; 411 int nz;
412 char *s;
401 413
402 field = tok + j; 414 field = tok + j;
403 EXPECT(field->type == JSMN_STRING, tok + j, 415 EXPECT(field->type == JSMN_STRING, tok + j,
@@ -444,7 +456,6 @@ int json_events(const char *fn,
444 NULL); 456 NULL);
445 } else if (json_streq(map, field, "Unit")) { 457 } else if (json_streq(map, field, "Unit")) {
446 const char *ppmu; 458 const char *ppmu;
447 char *s;
448 459
449 ppmu = field_to_perf(unit_to_pmu, map, val); 460 ppmu = field_to_perf(unit_to_pmu, map, val);
450 if (ppmu) { 461 if (ppmu) {
@@ -458,12 +469,19 @@ int json_events(const char *fn,
458 } 469 }
459 addfield(map, &desc, ". ", "Unit: ", NULL); 470 addfield(map, &desc, ". ", "Unit: ", NULL);
460 addfield(map, &desc, "", pmu, NULL); 471 addfield(map, &desc, "", pmu, NULL);
472 addfield(map, &desc, "", " ", NULL);
461 } else if (json_streq(map, field, "Filter")) { 473 } else if (json_streq(map, field, "Filter")) {
462 addfield(map, &filter, "", "", val); 474 addfield(map, &filter, "", "", val);
463 } else if (json_streq(map, field, "ScaleUnit")) { 475 } else if (json_streq(map, field, "ScaleUnit")) {
464 addfield(map, &unit, "", "", val); 476 addfield(map, &unit, "", "", val);
465 } else if (json_streq(map, field, "PerPkg")) { 477 } else if (json_streq(map, field, "PerPkg")) {
466 addfield(map, &perpkg, "", "", val); 478 addfield(map, &perpkg, "", "", val);
479 } else if (json_streq(map, field, "MetricName")) {
480 addfield(map, &metric_name, "", "", val);
481 } else if (json_streq(map, field, "MetricExpr")) {
482 addfield(map, &metric_expr, "", "", val);
483 for (s = metric_expr; *s; s++)
484 *s = tolower(*s);
467 } 485 }
468 /* ignore unknown fields */ 486 /* ignore unknown fields */
469 } 487 }
@@ -488,7 +506,7 @@ int json_events(const char *fn,
488 fixname(name); 506 fixname(name);
489 507
490 err = func(data, name, real_event(name, event), desc, long_desc, 508 err = func(data, name, real_event(name, event), desc, long_desc,
491 pmu, unit, perpkg); 509 pmu, unit, perpkg, metric_expr, metric_name);
492 free(event); 510 free(event);
493 free(desc); 511 free(desc);
494 free(name); 512 free(name);
@@ -498,6 +516,8 @@ int json_events(const char *fn,
498 free(filter); 516 free(filter);
499 free(perpkg); 517 free(perpkg);
500 free(unit); 518 free(unit);
519 free(metric_expr);
520 free(metric_name);
501 if (err) 521 if (err)
502 break; 522 break;
503 tok += j; 523 tok += j;
diff --git a/tools/perf/pmu-events/jevents.h b/tools/perf/pmu-events/jevents.h
index 71e13de31092..611fac01913d 100644
--- a/tools/perf/pmu-events/jevents.h
+++ b/tools/perf/pmu-events/jevents.h
@@ -5,7 +5,8 @@ int json_events(const char *fn,
5 int (*func)(void *data, char *name, char *event, char *desc, 5 int (*func)(void *data, char *name, char *event, char *desc,
6 char *long_desc, 6 char *long_desc,
7 char *pmu, 7 char *pmu,
8 char *unit, char *perpkg), 8 char *unit, char *perpkg, char *metric_expr,
9 char *metric_name),
9 void *data); 10 void *data);
10char *get_cpu_str(void); 11char *get_cpu_str(void);
11 12
diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h
index c669a3cdb9f0..569eab3688dd 100644
--- a/tools/perf/pmu-events/pmu-events.h
+++ b/tools/perf/pmu-events/pmu-events.h
@@ -13,6 +13,8 @@ struct pmu_event {
13 const char *pmu; 13 const char *pmu;
14 const char *unit; 14 const char *unit;
15 const char *perpkg; 15 const char *perpkg;
16 const char *metric_expr;
17 const char *metric_name;
16}; 18};
17 19
18/* 20/*
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 1cb3d9b540e9..af58ebc243ef 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -38,6 +38,7 @@ perf-y += cpumap.o
38perf-y += stat.o 38perf-y += stat.o
39perf-y += event_update.o 39perf-y += event_update.o
40perf-y += event-times.o 40perf-y += event-times.o
41perf-y += expr.o
41perf-y += backward-ring-buffer.o 42perf-y += backward-ring-buffer.o
42perf-y += sdt.o 43perf-y += sdt.o
43perf-y += is_printable_array.o 44perf-y += is_printable_array.o
diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c
index 88dc51f4c27b..0dd77494bb58 100644
--- a/tools/perf/tests/attr.c
+++ b/tools/perf/tests/attr.c
@@ -18,10 +18,16 @@
18 * permissions. All the event text files are stored there. 18 * permissions. All the event text files are stored there.
19 */ 19 */
20 20
21#include <errno.h>
22#include <inttypes.h>
21#include <stdlib.h> 23#include <stdlib.h>
22#include <stdio.h> 24#include <stdio.h>
23#include <linux/types.h> 25#include <linux/types.h>
24#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <sys/param.h>
28#include <sys/types.h>
29#include <sys/stat.h>
30#include <unistd.h>
25#include "../perf.h" 31#include "../perf.h"
26#include "util.h" 32#include "util.h"
27#include <subcmd/exec-cmd.h> 33#include <subcmd/exec-cmd.h>
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index 42e892b1e979..50f6d7afee58 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -8,6 +8,7 @@
8#include <sys/prctl.h> 8#include <sys/prctl.h>
9#include "tests.h" 9#include "tests.h"
10#include "debug.h" 10#include "debug.h"
11#include <errno.h>
11 12
12#define NR_ITERS 111 13#define NR_ITERS 111
13 14
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 1a04fe77487d..5876da126b58 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -1,10 +1,14 @@
1#include <errno.h>
1#include <stdio.h> 2#include <stdio.h>
2#include <sys/epoll.h> 3#include <sys/epoll.h>
4#include <sys/types.h>
5#include <sys/stat.h>
3#include <util/util.h> 6#include <util/util.h>
4#include <util/bpf-loader.h> 7#include <util/bpf-loader.h>
5#include <util/evlist.h> 8#include <util/evlist.h>
6#include <linux/bpf.h> 9#include <linux/bpf.h>
7#include <linux/filter.h> 10#include <linux/filter.h>
11#include <linux/kernel.h>
8#include <api/fs/fs.h> 12#include <api/fs/fs.h>
9#include <bpf/bpf.h> 13#include <bpf/bpf.h>
10#include "tests.h" 14#include "tests.h"
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 83c4669cbc5b..9e08d297f1a9 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -3,8 +3,10 @@
3 * 3 *
4 * Builtin regression testing command: ever growing number of sanity tests 4 * Builtin regression testing command: ever growing number of sanity tests
5 */ 5 */
6#include <errno.h>
6#include <unistd.h> 7#include <unistd.h>
7#include <string.h> 8#include <string.h>
9#include <sys/wait.h>
8#include "builtin.h" 10#include "builtin.h"
9#include "hist.h" 11#include "hist.h"
10#include "intlist.h" 12#include "intlist.h"
@@ -13,6 +15,7 @@
13#include "color.h" 15#include "color.h"
14#include <subcmd/parse-options.h> 16#include <subcmd/parse-options.h>
15#include "symbol.h" 17#include "symbol.h"
18#include <linux/kernel.h>
16 19
17static bool dont_fork; 20static bool dont_fork;
18 21
@@ -44,6 +47,10 @@ static struct test generic_tests[] = {
44 .func = test__parse_events, 47 .func = test__parse_events,
45 }, 48 },
46 { 49 {
50 .desc = "Simple expression parser",
51 .func = test__expr,
52 },
53 {
47 .desc = "PERF_RECORD_* events & perf_sample fields", 54 .desc = "PERF_RECORD_* events & perf_sample fields",
48 .func = test__PERF_RECORD, 55 .func = test__PERF_RECORD,
49 }, 56 },
@@ -460,7 +467,7 @@ static int perf_test__list(int argc, const char **argv)
460 return 0; 467 return 0;
461} 468}
462 469
463int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused) 470int cmd_test(int argc, const char **argv)
464{ 471{
465 const char *test_usage[] = { 472 const char *test_usage[] = {
466 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]", 473 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
diff --git a/tools/perf/tests/clang.c b/tools/perf/tests/clang.c
index f853e242a86c..c5bb2203f5a9 100644
--- a/tools/perf/tests/clang.c
+++ b/tools/perf/tests/clang.c
@@ -2,6 +2,7 @@
2#include "debug.h" 2#include "debug.h"
3#include "util.h" 3#include "util.h"
4#include "c++/clang-c.h" 4#include "c++/clang-c.h"
5#include <linux/kernel.h>
5 6
6static struct { 7static struct {
7 int (*func)(void); 8 int (*func)(void);
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index d1f693041324..1f14e7612cbb 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -1,9 +1,12 @@
1#include <errno.h>
2#include <linux/kernel.h>
1#include <linux/types.h> 3#include <linux/types.h>
4#include <inttypes.h>
2#include <stdlib.h> 5#include <stdlib.h>
3#include <unistd.h> 6#include <unistd.h>
4#include <stdio.h> 7#include <stdio.h>
5#include <ctype.h>
6#include <string.h> 8#include <string.h>
9#include <sys/param.h>
7 10
8#include "parse-events.h" 11#include "parse-events.h"
9#include "evlist.h" 12#include "evlist.h"
@@ -16,6 +19,8 @@
16 19
17#include "tests.h" 20#include "tests.h"
18 21
22#include "sane_ctype.h"
23
19#define BUFSZ 1024 24#define BUFSZ 1024
20#define READLEN 128 25#define READLEN 128
21 26
diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c
index f168a85992d0..4478773cdb97 100644
--- a/tools/perf/tests/cpumap.c
+++ b/tools/perf/tests/cpumap.c
@@ -66,7 +66,7 @@ static int process_event_cpus(struct perf_tool *tool __maybe_unused,
66 TEST_ASSERT_VAL("wrong nr", map->nr == 2); 66 TEST_ASSERT_VAL("wrong nr", map->nr == 2);
67 TEST_ASSERT_VAL("wrong cpu", map->map[0] == 1); 67 TEST_ASSERT_VAL("wrong cpu", map->map[0] == 1);
68 TEST_ASSERT_VAL("wrong cpu", map->map[1] == 256); 68 TEST_ASSERT_VAL("wrong cpu", map->map[1] == 256);
69 TEST_ASSERT_VAL("wrong refcnt", atomic_read(&map->refcnt) == 1); 69 TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map->refcnt) == 1);
70 cpu_map__put(map); 70 cpu_map__put(map);
71 return 0; 71 return 0;
72} 72}
diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c
index 13725e09ba22..8f08df5861cb 100644
--- a/tools/perf/tests/dso-data.c
+++ b/tools/perf/tests/dso-data.c
@@ -1,4 +1,6 @@
1#include <dirent.h>
1#include <stdlib.h> 2#include <stdlib.h>
3#include <linux/kernel.h>
2#include <linux/types.h> 4#include <linux/types.h>
3#include <sys/stat.h> 5#include <sys/stat.h>
4#include <fcntl.h> 6#include <fcntl.h>
diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c
index 1046491de4b2..dfe5c89e2049 100644
--- a/tools/perf/tests/dwarf-unwind.c
+++ b/tools/perf/tests/dwarf-unwind.c
@@ -1,5 +1,6 @@
1#include <linux/compiler.h> 1#include <linux/compiler.h>
2#include <linux/types.h> 2#include <linux/types.h>
3#include <inttypes.h>
3#include <unistd.h> 4#include <unistd.h>
4#include "tests.h" 5#include "tests.h"
5#include "debug.h" 6#include "debug.h"
diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c
index 19ef77bd6eb4..634f20c631d8 100644
--- a/tools/perf/tests/event-times.c
+++ b/tools/perf/tests/event-times.c
@@ -1,5 +1,8 @@
1#include <linux/compiler.h> 1#include <linux/compiler.h>
2#include <errno.h>
3#include <inttypes.h>
2#include <string.h> 4#include <string.h>
5#include <sys/wait.h>
3#include "tests.h" 6#include "tests.h"
4#include "evlist.h" 7#include "evlist.h"
5#include "evsel.h" 8#include "evsel.h"
diff --git a/tools/perf/tests/evsel-roundtrip-name.c b/tools/perf/tests/evsel-roundtrip-name.c
index 60926a1f6fd7..d2bea6f780f8 100644
--- a/tools/perf/tests/evsel-roundtrip-name.c
+++ b/tools/perf/tests/evsel-roundtrip-name.c
@@ -3,6 +3,8 @@
3#include "parse-events.h" 3#include "parse-events.h"
4#include "tests.h" 4#include "tests.h"
5#include "debug.h" 5#include "debug.h"
6#include <errno.h>
7#include <linux/kernel.h>
6 8
7static int perf_evsel__roundtrip_cache_name_test(void) 9static int perf_evsel__roundtrip_cache_name_test(void)
8{ 10{
diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c
new file mode 100644
index 000000000000..6c6a3749aaf6
--- /dev/null
+++ b/tools/perf/tests/expr.c
@@ -0,0 +1,56 @@
1#include "util/debug.h"
2#include "util/expr.h"
3#include "tests.h"
4#include <stdlib.h>
5
6static int test(struct parse_ctx *ctx, const char *e, double val2)
7{
8 double val;
9
10 if (expr__parse(&val, ctx, &e))
11 TEST_ASSERT_VAL("parse test failed", 0);
12 TEST_ASSERT_VAL("unexpected value", val == val2);
13 return 0;
14}
15
16int test__expr(int subtest __maybe_unused)
17{
18 const char *p;
19 const char **other;
20 double val;
21 int ret;
22 struct parse_ctx ctx;
23 int num_other;
24
25 expr__ctx_init(&ctx);
26 expr__add_id(&ctx, "FOO", 1);
27 expr__add_id(&ctx, "BAR", 2);
28
29 ret = test(&ctx, "1+1", 2);
30 ret |= test(&ctx, "FOO+BAR", 3);
31 ret |= test(&ctx, "(BAR/2)%2", 1);
32 ret |= test(&ctx, "1 - -4", 5);
33 ret |= test(&ctx, "(FOO-1)*2 + (BAR/2)%2 - -4", 5);
34
35 if (ret)
36 return ret;
37
38 p = "FOO/0";
39 ret = expr__parse(&val, &ctx, &p);
40 TEST_ASSERT_VAL("division by zero", ret == 1);
41
42 p = "BAR/";
43 ret = expr__parse(&val, &ctx, &p);
44 TEST_ASSERT_VAL("missing operand", ret == 1);
45
46 TEST_ASSERT_VAL("find other",
47 expr__find_other("FOO + BAR + BAZ + BOZO", "FOO", &other, &num_other) == 0);
48 TEST_ASSERT_VAL("find other", num_other == 3);
49 TEST_ASSERT_VAL("find other", !strcmp(other[0], "BAR"));
50 TEST_ASSERT_VAL("find other", !strcmp(other[1], "BAZ"));
51 TEST_ASSERT_VAL("find other", !strcmp(other[2], "BOZO"));
52 TEST_ASSERT_VAL("find other", other[3] == NULL);
53 free((void *)other);
54
55 return 0;
56}
diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c
index 6b21746d6eec..00b8dc50f3db 100644
--- a/tools/perf/tests/hists_common.c
+++ b/tools/perf/tests/hists_common.c
@@ -1,3 +1,4 @@
1#include <inttypes.h>
1#include "perf.h" 2#include "perf.h"
2#include "util/debug.h" 3#include "util/debug.h"
3#include "util/symbol.h" 4#include "util/symbol.h"
@@ -7,6 +8,7 @@
7#include "util/machine.h" 8#include "util/machine.h"
8#include "util/thread.h" 9#include "util/thread.h"
9#include "tests/hists_common.h" 10#include "tests/hists_common.h"
11#include <linux/kernel.h>
10 12
11static struct { 13static struct {
12 u32 pid; 14 u32 pid;
diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c
index 9fd54b79a788..70918b986568 100644
--- a/tools/perf/tests/hists_cumulate.c
+++ b/tools/perf/tests/hists_cumulate.c
@@ -9,6 +9,7 @@
9#include "util/parse-events.h" 9#include "util/parse-events.h"
10#include "tests/tests.h" 10#include "tests/tests.h"
11#include "tests/hists_common.h" 11#include "tests/hists_common.h"
12#include <linux/kernel.h>
12 13
13struct sample { 14struct sample {
14 u32 pid; 15 u32 pid;
diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c
index 62efb14f3a5a..f171b2da4899 100644
--- a/tools/perf/tests/hists_filter.c
+++ b/tools/perf/tests/hists_filter.c
@@ -9,6 +9,7 @@
9#include "util/parse-events.h" 9#include "util/parse-events.h"
10#include "tests/tests.h" 10#include "tests/tests.h"
11#include "tests/hists_common.h" 11#include "tests/hists_common.h"
12#include <linux/kernel.h>
12 13
13struct sample { 14struct sample {
14 u32 pid; 15 u32 pid;
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index eddc7407ff8a..a26cbb79e988 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -9,6 +9,8 @@
9#include "thread.h" 9#include "thread.h"
10#include "parse-events.h" 10#include "parse-events.h"
11#include "hists_common.h" 11#include "hists_common.h"
12#include <errno.h>
13#include <linux/kernel.h>
12 14
13struct sample { 15struct sample {
14 u32 pid; 16 u32 pid;
diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c
index 63c5efaba1b5..cdf0dde5fe97 100644
--- a/tools/perf/tests/hists_output.c
+++ b/tools/perf/tests/hists_output.c
@@ -9,6 +9,7 @@
9#include "util/parse-events.h" 9#include "util/parse-events.h"
10#include "tests/tests.h" 10#include "tests/tests.h"
11#include "tests/hists_common.h" 11#include "tests/hists_common.h"
12#include <linux/kernel.h>
12 13
13struct sample { 14struct sample {
14 u32 cpu; 15 u32 cpu;
diff --git a/tools/perf/tests/is_printable_array.c b/tools/perf/tests/is_printable_array.c
index 42e13393e502..a5192f6a20d7 100644
--- a/tools/perf/tests/is_printable_array.c
+++ b/tools/perf/tests/is_printable_array.c
@@ -1,7 +1,8 @@
1#include <linux/compiler.h> 1#include <linux/compiler.h>
2#include <linux/kernel.h>
2#include "tests.h" 3#include "tests.h"
3#include "debug.h" 4#include "debug.h"
4#include "util.h" 5#include "print_binary.h"
5 6
6int test__is_printable_array(int subtest __maybe_unused) 7int test__is_printable_array(int subtest __maybe_unused)
7{ 8{
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index 634bce9caebd..15c770856aac 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -1,3 +1,5 @@
1#include <errno.h>
2#include <inttypes.h>
1/* For the CLR_() macros */ 3/* For the CLR_() macros */
2#include <pthread.h> 4#include <pthread.h>
3 5
@@ -7,6 +9,7 @@
7#include "cpumap.h" 9#include "cpumap.h"
8#include "tests.h" 10#include "tests.h"
9#include <linux/err.h> 11#include <linux/err.h>
12#include <linux/kernel.h>
10 13
11/* 14/*
12 * This test will generate random numbers of calls to some getpid syscalls, 15 * This test will generate random numbers of calls to some getpid syscalls,
diff --git a/tools/perf/tests/mmap-thread-lookup.c b/tools/perf/tests/mmap-thread-lookup.c
index 0c5ce44f723f..6ea4d8a5d26b 100644
--- a/tools/perf/tests/mmap-thread-lookup.c
+++ b/tools/perf/tests/mmap-thread-lookup.c
@@ -1,3 +1,4 @@
1#include <inttypes.h>
1#include <unistd.h> 2#include <unistd.h>
2#include <sys/syscall.h> 3#include <sys/syscall.h>
3#include <sys/types.h> 4#include <sys/types.h>
@@ -11,6 +12,7 @@
11#include "thread_map.h" 12#include "thread_map.h"
12#include "symbol.h" 13#include "symbol.h"
13#include "thread.h" 14#include "thread.h"
15#include "util.h"
14 16
15#define THREADS 4 17#define THREADS 4
16 18
diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/openat-syscall-all-cpus.c
index c8d9592eb142..1a74dd9fd067 100644
--- a/tools/perf/tests/openat-syscall-all-cpus.c
+++ b/tools/perf/tests/openat-syscall-all-cpus.c
@@ -1,8 +1,14 @@
1#include <errno.h>
2#include <inttypes.h>
1/* For the CPU_* macros */ 3/* For the CPU_* macros */
2#include <pthread.h> 4#include <pthread.h>
3 5
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <fcntl.h>
4#include <api/fs/fs.h> 9#include <api/fs/fs.h>
5#include <linux/err.h> 10#include <linux/err.h>
11#include <api/fs/tracing_path.h>
6#include "evsel.h" 12#include "evsel.h"
7#include "tests.h" 13#include "tests.h"
8#include "thread_map.h" 14#include "thread_map.h"
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index f52239fed361..9788fac91095 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -5,6 +5,7 @@
5#include "thread_map.h" 5#include "thread_map.h"
6#include "tests.h" 6#include "tests.h"
7#include "debug.h" 7#include "debug.h"
8#include <errno.h>
8 9
9#ifndef O_DIRECTORY 10#ifndef O_DIRECTORY
10#define O_DIRECTORY 00200000 11#define O_DIRECTORY 00200000
diff --git a/tools/perf/tests/openat-syscall.c b/tools/perf/tests/openat-syscall.c
index d7414128d7fe..e44506e21ee7 100644
--- a/tools/perf/tests/openat-syscall.c
+++ b/tools/perf/tests/openat-syscall.c
@@ -1,5 +1,10 @@
1#include <errno.h>
2#include <inttypes.h>
1#include <api/fs/tracing_path.h> 3#include <api/fs/tracing_path.h>
2#include <linux/err.h> 4#include <linux/err.h>
5#include <sys/types.h>
6#include <sys/stat.h>
7#include <fcntl.h>
3#include "thread_map.h" 8#include "thread_map.h"
4#include "evsel.h" 9#include "evsel.h"
5#include "debug.h" 10#include "debug.h"
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 1dc838014422..7fad885491c5 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1,4 +1,3 @@
1
2#include "parse-events.h" 1#include "parse-events.h"
3#include "evsel.h" 2#include "evsel.h"
4#include "evlist.h" 3#include "evlist.h"
@@ -6,8 +5,15 @@
6#include "tests.h" 5#include "tests.h"
7#include "debug.h" 6#include "debug.h"
8#include "util.h" 7#include "util.h"
8#include <dirent.h>
9#include <errno.h>
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <unistd.h>
13#include <linux/kernel.h>
9#include <linux/hw_breakpoint.h> 14#include <linux/hw_breakpoint.h>
10#include <api/fs/fs.h> 15#include <api/fs/fs.h>
16#include <api/fs/tracing_path.h>
11 17
12#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \ 18#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
13 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD) 19 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
diff --git a/tools/perf/tests/parse-no-sample-id-all.c b/tools/perf/tests/parse-no-sample-id-all.c
index 65dcf48a92fb..c6207db09f12 100644
--- a/tools/perf/tests/parse-no-sample-id-all.c
+++ b/tools/perf/tests/parse-no-sample-id-all.c
@@ -1,3 +1,4 @@
1#include <linux/kernel.h>
1#include <linux/types.h> 2#include <linux/types.h>
2#include <stddef.h> 3#include <stddef.h>
3 4
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index 87893f3ba5f1..d37cd9588cc0 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -1,3 +1,5 @@
1#include <errno.h>
2#include <inttypes.h>
1/* For the CLR_() macros */ 3/* For the CLR_() macros */
2#include <pthread.h> 4#include <pthread.h>
3 5
diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c
index 1e2ba2602930..a6d7aef30030 100644
--- a/tools/perf/tests/pmu.c
+++ b/tools/perf/tests/pmu.c
@@ -2,6 +2,8 @@
2#include "pmu.h" 2#include "pmu.h"
3#include "util.h" 3#include "util.h"
4#include "tests.h" 4#include "tests.h"
5#include <errno.h>
6#include <linux/kernel.h>
5 7
6/* Simulated format definitions. */ 8/* Simulated format definitions. */
7static struct test_format { 9static struct test_format {
diff --git a/tools/perf/tests/sample-parsing.c b/tools/perf/tests/sample-parsing.c
index 5f23710b9fee..bac5c3885b3b 100644
--- a/tools/perf/tests/sample-parsing.c
+++ b/tools/perf/tests/sample-parsing.c
@@ -1,4 +1,6 @@
1#include <stdbool.h> 1#include <stdbool.h>
2#include <inttypes.h>
3#include <linux/kernel.h>
2#include <linux/types.h> 4#include <linux/types.h>
3 5
4#include "util.h" 6#include "util.h"
diff --git a/tools/perf/tests/sdt.c b/tools/perf/tests/sdt.c
index f59d210e1baf..f73b3c5e125d 100644
--- a/tools/perf/tests/sdt.c
+++ b/tools/perf/tests/sdt.c
@@ -1,3 +1,4 @@
1#include <errno.h>
1#include <stdio.h> 2#include <stdio.h>
2#include <sys/epoll.h> 3#include <sys/epoll.h>
3#include <util/util.h> 4#include <util/util.h>
@@ -43,7 +44,7 @@ static char *get_self_path(void)
43{ 44{
44 char *buf = calloc(PATH_MAX, sizeof(char)); 45 char *buf = calloc(PATH_MAX, sizeof(char));
45 46
46 if (buf && readlink("/proc/self/exe", buf, PATH_MAX) < 0) { 47 if (buf && readlink("/proc/self/exe", buf, PATH_MAX - 1) < 0) {
47 pr_debug("Failed to get correct path of perf\n"); 48 pr_debug("Failed to get correct path of perf\n");
48 free(buf); 49 free(buf);
49 return NULL; 50 return NULL;
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index 4c9fd046d57b..828494db4a19 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -1,3 +1,5 @@
1#include <errno.h>
2#include <inttypes.h>
1#include <unistd.h> 3#include <unistd.h>
2#include <stdlib.h> 4#include <stdlib.h>
3#include <signal.h> 5#include <signal.h>
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 7ddbe267d0ac..65474fd80da7 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -1,5 +1,6 @@
1#include <sys/time.h> 1#include <sys/time.h>
2#include <sys/prctl.h> 2#include <sys/prctl.h>
3#include <errno.h>
3#include <time.h> 4#include <time.h>
4#include <stdlib.h> 5#include <stdlib.h>
5 6
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index 01a5ba2788c6..32873ec91a4e 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -4,6 +4,7 @@
4#include "cpumap.h" 4#include "cpumap.h"
5#include "tests.h" 5#include "tests.h"
6 6
7#include <errno.h>
7#include <signal.h> 8#include <signal.h>
8 9
9static int exited; 10static int exited;
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 1fa9b9d83aa5..631859629403 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -62,6 +62,7 @@ int test__sample_parsing(int subtest);
62int test__keep_tracking(int subtest); 62int test__keep_tracking(int subtest);
63int test__parse_no_sample_id_all(int subtest); 63int test__parse_no_sample_id_all(int subtest);
64int test__dwarf_unwind(int subtest); 64int test__dwarf_unwind(int subtest);
65int test__expr(int subtest);
65int test__hists_filter(int subtest); 66int test__hists_filter(int subtest);
66int test__mmap_thread_lookup(int subtest); 67int test__mmap_thread_lookup(int subtest);
67int test__thread_mg_share(int subtest); 68int test__thread_mg_share(int subtest);
diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c
index f2d2e542d0ee..a63d6945807b 100644
--- a/tools/perf/tests/thread-map.c
+++ b/tools/perf/tests/thread-map.c
@@ -29,7 +29,7 @@ int test__thread_map(int subtest __maybe_unused)
29 thread_map__comm(map, 0) && 29 thread_map__comm(map, 0) &&
30 !strcmp(thread_map__comm(map, 0), NAME)); 30 !strcmp(thread_map__comm(map, 0), NAME));
31 TEST_ASSERT_VAL("wrong refcnt", 31 TEST_ASSERT_VAL("wrong refcnt",
32 atomic_read(&map->refcnt) == 1); 32 refcount_read(&map->refcnt) == 1);
33 thread_map__put(map); 33 thread_map__put(map);
34 34
35 /* test dummy pid */ 35 /* test dummy pid */
@@ -44,7 +44,7 @@ int test__thread_map(int subtest __maybe_unused)
44 thread_map__comm(map, 0) && 44 thread_map__comm(map, 0) &&
45 !strcmp(thread_map__comm(map, 0), "dummy")); 45 !strcmp(thread_map__comm(map, 0), "dummy"));
46 TEST_ASSERT_VAL("wrong refcnt", 46 TEST_ASSERT_VAL("wrong refcnt",
47 atomic_read(&map->refcnt) == 1); 47 refcount_read(&map->refcnt) == 1);
48 thread_map__put(map); 48 thread_map__put(map);
49 return 0; 49 return 0;
50} 50}
@@ -71,7 +71,7 @@ static int process_event(struct perf_tool *tool __maybe_unused,
71 thread_map__comm(threads, 0) && 71 thread_map__comm(threads, 0) &&
72 !strcmp(thread_map__comm(threads, 0), NAME)); 72 !strcmp(thread_map__comm(threads, 0), NAME));
73 TEST_ASSERT_VAL("wrong refcnt", 73 TEST_ASSERT_VAL("wrong refcnt",
74 atomic_read(&threads->refcnt) == 1); 74 refcount_read(&threads->refcnt) == 1);
75 thread_map__put(threads); 75 thread_map__put(threads);
76 return 0; 76 return 0;
77} 77}
diff --git a/tools/perf/tests/thread-mg-share.c b/tools/perf/tests/thread-mg-share.c
index 188b63140fc8..76686dd6f5ec 100644
--- a/tools/perf/tests/thread-mg-share.c
+++ b/tools/perf/tests/thread-mg-share.c
@@ -43,7 +43,7 @@ int test__thread_mg_share(int subtest __maybe_unused)
43 leader && t1 && t2 && t3 && other); 43 leader && t1 && t2 && t3 && other);
44 44
45 mg = leader->mg; 45 mg = leader->mg;
46 TEST_ASSERT_EQUAL("wrong refcnt", atomic_read(&mg->refcnt), 4); 46 TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&mg->refcnt), 4);
47 47
48 /* test the map groups pointer is shared */ 48 /* test the map groups pointer is shared */
49 TEST_ASSERT_VAL("map groups don't match", mg == t1->mg); 49 TEST_ASSERT_VAL("map groups don't match", mg == t1->mg);
@@ -71,25 +71,25 @@ int test__thread_mg_share(int subtest __maybe_unused)
71 machine__remove_thread(machine, other_leader); 71 machine__remove_thread(machine, other_leader);
72 72
73 other_mg = other->mg; 73 other_mg = other->mg;
74 TEST_ASSERT_EQUAL("wrong refcnt", atomic_read(&other_mg->refcnt), 2); 74 TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&other_mg->refcnt), 2);
75 75
76 TEST_ASSERT_VAL("map groups don't match", other_mg == other_leader->mg); 76 TEST_ASSERT_VAL("map groups don't match", other_mg == other_leader->mg);
77 77
78 /* release thread group */ 78 /* release thread group */
79 thread__put(leader); 79 thread__put(leader);
80 TEST_ASSERT_EQUAL("wrong refcnt", atomic_read(&mg->refcnt), 3); 80 TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&mg->refcnt), 3);
81 81
82 thread__put(t1); 82 thread__put(t1);
83 TEST_ASSERT_EQUAL("wrong refcnt", atomic_read(&mg->refcnt), 2); 83 TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&mg->refcnt), 2);
84 84
85 thread__put(t2); 85 thread__put(t2);
86 TEST_ASSERT_EQUAL("wrong refcnt", atomic_read(&mg->refcnt), 1); 86 TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&mg->refcnt), 1);
87 87
88 thread__put(t3); 88 thread__put(t3);
89 89
90 /* release other group */ 90 /* release other group */
91 thread__put(other_leader); 91 thread__put(other_leader);
92 TEST_ASSERT_EQUAL("wrong refcnt", atomic_read(&other_mg->refcnt), 1); 92 TEST_ASSERT_EQUAL("wrong refcnt", refcount_read(&other_mg->refcnt), 1);
93 93
94 thread__put(other); 94 thread__put(other);
95 95
diff --git a/tools/perf/tests/unit_number__scnprintf.c b/tools/perf/tests/unit_number__scnprintf.c
index 623c2aa53c4a..44589de084b8 100644
--- a/tools/perf/tests/unit_number__scnprintf.c
+++ b/tools/perf/tests/unit_number__scnprintf.c
@@ -1,7 +1,8 @@
1#include <inttypes.h>
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include <linux/types.h> 3#include <linux/types.h>
3#include "tests.h" 4#include "tests.h"
4#include "util.h" 5#include "units.h"
5#include "debug.h" 6#include "debug.h"
6 7
7int test__unit_number__scnprint(int subtest __maybe_unused) 8int test__unit_number__scnprint(int subtest __maybe_unused)
diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c
index 862b043e5924..8456175fc234 100644
--- a/tools/perf/tests/vmlinux-kallsyms.c
+++ b/tools/perf/tests/vmlinux-kallsyms.c
@@ -1,5 +1,6 @@
1#include <linux/compiler.h> 1#include <linux/compiler.h>
2#include <linux/rbtree.h> 2#include <linux/rbtree.h>
3#include <inttypes.h>
3#include <string.h> 4#include <string.h>
4#include "map.h" 5#include "map.h"
5#include "symbol.h" 6#include "symbol.h"
diff --git a/tools/perf/trace/beauty/Build b/tools/perf/trace/beauty/Build
new file mode 100644
index 000000000000..be95ac6ce845
--- /dev/null
+++ b/tools/perf/trace/beauty/Build
@@ -0,0 +1 @@
libperf-y += statx.o
diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h
new file mode 100644
index 000000000000..cf50be3f17a4
--- /dev/null
+++ b/tools/perf/trace/beauty/beauty.h
@@ -0,0 +1,24 @@
1#ifndef _PERF_TRACE_BEAUTY_H
2#define _PERF_TRACE_BEAUTY_H
3
4#include <linux/types.h>
5
6struct trace;
7struct thread;
8
9struct syscall_arg {
10 unsigned long val;
11 struct thread *thread;
12 struct trace *trace;
13 void *parm;
14 u8 idx;
15 u8 mask;
16};
17
18size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_arg *arg);
19#define SCA_STATX_FLAGS syscall_arg__scnprintf_statx_flags
20
21size_t syscall_arg__scnprintf_statx_mask(char *bf, size_t size, struct syscall_arg *arg);
22#define SCA_STATX_MASK syscall_arg__scnprintf_statx_mask
23
24#endif /* _PERF_TRACE_BEAUTY_H */
diff --git a/tools/perf/trace/beauty/signum.c b/tools/perf/trace/beauty/signum.c
index d3b0b1fab077..fde8f2fc6558 100644
--- a/tools/perf/trace/beauty/signum.c
+++ b/tools/perf/trace/beauty/signum.c
@@ -1,3 +1,4 @@
1#include <signal.h>
1 2
2static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscall_arg *arg) 3static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscall_arg *arg)
3{ 4{
diff --git a/tools/perf/trace/beauty/statx.c b/tools/perf/trace/beauty/statx.c
new file mode 100644
index 000000000000..5643b692af4c
--- /dev/null
+++ b/tools/perf/trace/beauty/statx.c
@@ -0,0 +1,72 @@
1/*
2 * trace/beauty/statx.c
3 *
4 * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
5 *
6 * Released under the GPL v2. (and only v2, not any later version)
7 */
8
9#include "trace/beauty/beauty.h"
10#include <linux/kernel.h>
11#include <sys/types.h>
12#include <uapi/linux/fcntl.h>
13#include <uapi/linux/stat.h>
14
15size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_arg *arg)
16{
17 int printed = 0, flags = arg->val;
18
19 if (flags == 0)
20 return scnprintf(bf, size, "SYNC_AS_STAT");
21#define P_FLAG(n) \
22 if (flags & AT_##n) { \
23 printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
24 flags &= ~AT_##n; \
25 }
26
27 P_FLAG(SYMLINK_NOFOLLOW);
28 P_FLAG(REMOVEDIR);
29 P_FLAG(SYMLINK_FOLLOW);
30 P_FLAG(NO_AUTOMOUNT);
31 P_FLAG(EMPTY_PATH);
32 P_FLAG(STATX_FORCE_SYNC);
33 P_FLAG(STATX_DONT_SYNC);
34
35#undef P_FLAG
36
37 if (flags)
38 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
39
40 return printed;
41}
42
43size_t syscall_arg__scnprintf_statx_mask(char *bf, size_t size, struct syscall_arg *arg)
44{
45 int printed = 0, flags = arg->val;
46
47#define P_FLAG(n) \
48 if (flags & STATX_##n) { \
49 printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
50 flags &= ~STATX_##n; \
51 }
52
53 P_FLAG(TYPE);
54 P_FLAG(MODE);
55 P_FLAG(NLINK);
56 P_FLAG(UID);
57 P_FLAG(GID);
58 P_FLAG(ATIME);
59 P_FLAG(MTIME);
60 P_FLAG(CTIME);
61 P_FLAG(INO);
62 P_FLAG(SIZE);
63 P_FLAG(BLOCKS);
64 P_FLAG(BTIME);
65
66#undef P_FLAG
67
68 if (flags)
69 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
70
71 return printed;
72}
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 3eb3edb307a4..a4d3762cd825 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -1,4 +1,5 @@
1#include "../util.h" 1#include "../util.h"
2#include "../string2.h"
2#include "../config.h" 3#include "../config.h"
3#include "../../perf.h" 4#include "../../perf.h"
4#include "libslang.h" 5#include "libslang.h"
@@ -13,6 +14,7 @@
13#include "helpline.h" 14#include "helpline.h"
14#include "keysyms.h" 15#include "keysyms.h"
15#include "../color.h" 16#include "../color.h"
17#include "sane_ctype.h"
16 18
17static int ui_browser__percent_color(struct ui_browser *browser, 19static int ui_browser__percent_color(struct ui_browser *browser,
18 double percent, bool current) 20 double percent, bool current)
@@ -579,7 +581,7 @@ static int ui_browser__color_config(const char *var, const char *value,
579 break; 581 break;
580 582
581 *bg = '\0'; 583 *bg = '\0';
582 while (isspace(*++bg)); 584 bg = ltrim(++bg);
583 ui_browser__colorsets[i].bg = bg; 585 ui_browser__colorsets[i].bg = bg;
584 ui_browser__colorsets[i].fg = fg; 586 ui_browser__colorsets[i].fg = fg;
585 return 0; 587 return 0;
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index ba36aac340bc..d990ad08a3c6 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -9,7 +9,10 @@
9#include "../../util/symbol.h" 9#include "../../util/symbol.h"
10#include "../../util/evsel.h" 10#include "../../util/evsel.h"
11#include "../../util/config.h" 11#include "../../util/config.h"
12#include <inttypes.h>
12#include <pthread.h> 13#include <pthread.h>
14#include <linux/kernel.h>
15#include <sys/ttydefaults.h>
13 16
14struct disasm_line_samples { 17struct disasm_line_samples {
15 double percent; 18 double percent;
diff --git a/tools/perf/ui/browsers/header.c b/tools/perf/ui/browsers/header.c
index edbeaaf31ace..e2c9390ff4c5 100644
--- a/tools/perf/ui/browsers/header.c
+++ b/tools/perf/ui/browsers/header.c
@@ -8,6 +8,8 @@
8#include "util/header.h" 8#include "util/header.h"
9#include "util/session.h" 9#include "util/session.h"
10 10
11#include <sys/ttydefaults.h>
12
11static void ui_browser__argv_write(struct ui_browser *browser, 13static void ui_browser__argv_write(struct ui_browser *browser,
12 void *entry, int row) 14 void *entry, int row)
13{ 15{
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index fc4fb669ceee..69f4570bd4f9 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1,7 +1,11 @@
1#include <dirent.h>
2#include <errno.h>
3#include <inttypes.h>
1#include <stdio.h> 4#include <stdio.h>
2#include <stdlib.h> 5#include <stdlib.h>
3#include <string.h> 6#include <string.h>
4#include <linux/rbtree.h> 7#include <linux/rbtree.h>
8#include <sys/ttydefaults.h>
5 9
6#include "../../util/evsel.h" 10#include "../../util/evsel.h"
7#include "../../util/evlist.h" 11#include "../../util/evlist.h"
@@ -10,6 +14,7 @@
10#include "../../util/sort.h" 14#include "../../util/sort.h"
11#include "../../util/util.h" 15#include "../../util/util.h"
12#include "../../util/top.h" 16#include "../../util/top.h"
17#include "../../util/thread.h"
13#include "../../arch/common.h" 18#include "../../arch/common.h"
14 19
15#include "../browsers/hists.h" 20#include "../browsers/hists.h"
@@ -18,6 +23,11 @@
18#include "../ui.h" 23#include "../ui.h"
19#include "map.h" 24#include "map.h"
20#include "annotate.h" 25#include "annotate.h"
26#include "srcline.h"
27#include "string2.h"
28#include "units.h"
29
30#include "sane_ctype.h"
21 31
22extern void hist_browser__init_hpp(void); 32extern void hist_browser__init_hpp(void);
23 33
@@ -144,9 +154,60 @@ static void callchain_list__set_folding(struct callchain_list *cl, bool unfold)
144 cl->unfolded = unfold ? cl->has_children : false; 154 cl->unfolded = unfold ? cl->has_children : false;
145} 155}
146 156
157static struct inline_node *inline_node__create(struct map *map, u64 ip)
158{
159 struct dso *dso;
160 struct inline_node *node;
161
162 if (map == NULL)
163 return NULL;
164
165 dso = map->dso;
166 if (dso == NULL)
167 return NULL;
168
169 if (dso->kernel != DSO_TYPE_USER)
170 return NULL;
171
172 node = dso__parse_addr_inlines(dso,
173 map__rip_2objdump(map, ip));
174
175 return node;
176}
177
178static int inline__count_rows(struct inline_node *node)
179{
180 struct inline_list *ilist;
181 int i = 0;
182
183 if (node == NULL)
184 return 0;
185
186 list_for_each_entry(ilist, &node->val, list) {
187 if ((ilist->filename != NULL) || (ilist->funcname != NULL))
188 i++;
189 }
190
191 return i;
192}
193
194static int callchain_list__inline_rows(struct callchain_list *chain)
195{
196 struct inline_node *node;
197 int rows;
198
199 node = inline_node__create(chain->ms.map, chain->ip);
200 if (node == NULL)
201 return 0;
202
203 rows = inline__count_rows(node);
204 inline_node__delete(node);
205 return rows;
206}
207
147static int callchain_node__count_rows_rb_tree(struct callchain_node *node) 208static int callchain_node__count_rows_rb_tree(struct callchain_node *node)
148{ 209{
149 int n = 0; 210 int n = 0, inline_rows;
150 struct rb_node *nd; 211 struct rb_node *nd;
151 212
152 for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) { 213 for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) {
@@ -156,6 +217,13 @@ static int callchain_node__count_rows_rb_tree(struct callchain_node *node)
156 217
157 list_for_each_entry(chain, &child->val, list) { 218 list_for_each_entry(chain, &child->val, list) {
158 ++n; 219 ++n;
220
221 if (symbol_conf.inline_name) {
222 inline_rows =
223 callchain_list__inline_rows(chain);
224 n += inline_rows;
225 }
226
159 /* We need this because we may not have children */ 227 /* We need this because we may not have children */
160 folded_sign = callchain_list__folded(chain); 228 folded_sign = callchain_list__folded(chain);
161 if (folded_sign == '+') 229 if (folded_sign == '+')
@@ -207,7 +275,7 @@ static int callchain_node__count_rows(struct callchain_node *node)
207{ 275{
208 struct callchain_list *chain; 276 struct callchain_list *chain;
209 bool unfolded = false; 277 bool unfolded = false;
210 int n = 0; 278 int n = 0, inline_rows;
211 279
212 if (callchain_param.mode == CHAIN_FLAT) 280 if (callchain_param.mode == CHAIN_FLAT)
213 return callchain_node__count_flat_rows(node); 281 return callchain_node__count_flat_rows(node);
@@ -216,6 +284,11 @@ static int callchain_node__count_rows(struct callchain_node *node)
216 284
217 list_for_each_entry(chain, &node->val, list) { 285 list_for_each_entry(chain, &node->val, list) {
218 ++n; 286 ++n;
287 if (symbol_conf.inline_name) {
288 inline_rows = callchain_list__inline_rows(chain);
289 n += inline_rows;
290 }
291
219 unfolded = chain->unfolded; 292 unfolded = chain->unfolded;
220 } 293 }
221 294
@@ -362,6 +435,19 @@ static void hist_entry__init_have_children(struct hist_entry *he)
362 he->init_have_children = true; 435 he->init_have_children = true;
363} 436}
364 437
438static void hist_entry_init_inline_node(struct hist_entry *he)
439{
440 if (he->inline_node)
441 return;
442
443 he->inline_node = inline_node__create(he->ms.map, he->ip);
444
445 if (he->inline_node == NULL)
446 return;
447
448 he->has_children = true;
449}
450
365static bool hist_browser__toggle_fold(struct hist_browser *browser) 451static bool hist_browser__toggle_fold(struct hist_browser *browser)
366{ 452{
367 struct hist_entry *he = browser->he_selection; 453 struct hist_entry *he = browser->he_selection;
@@ -393,7 +479,12 @@ static bool hist_browser__toggle_fold(struct hist_browser *browser)
393 479
394 if (he->unfolded) { 480 if (he->unfolded) {
395 if (he->leaf) 481 if (he->leaf)
396 he->nr_rows = callchain__count_rows(&he->sorted_chain); 482 if (he->inline_node)
483 he->nr_rows = inline__count_rows(
484 he->inline_node);
485 else
486 he->nr_rows = callchain__count_rows(
487 &he->sorted_chain);
397 else 488 else
398 he->nr_rows = hierarchy_count_rows(browser, he, false); 489 he->nr_rows = hierarchy_count_rows(browser, he, false);
399 490
@@ -753,6 +844,71 @@ static bool hist_browser__check_dump_full(struct hist_browser *browser __maybe_u
753 844
754#define LEVEL_OFFSET_STEP 3 845#define LEVEL_OFFSET_STEP 3
755 846
847static int hist_browser__show_inline(struct hist_browser *browser,
848 struct inline_node *node,
849 unsigned short row,
850 int offset)
851{
852 struct inline_list *ilist;
853 char buf[1024];
854 int color, width, first_row;
855
856 first_row = row;
857 width = browser->b.width - (LEVEL_OFFSET_STEP + 2);
858 list_for_each_entry(ilist, &node->val, list) {
859 if ((ilist->filename != NULL) || (ilist->funcname != NULL)) {
860 color = HE_COLORSET_NORMAL;
861 if (ui_browser__is_current_entry(&browser->b, row))
862 color = HE_COLORSET_SELECTED;
863
864 if (callchain_param.key == CCKEY_ADDRESS ||
865 callchain_param.key == CCKEY_SRCLINE) {
866 if (ilist->filename != NULL)
867 scnprintf(buf, sizeof(buf),
868 "%s:%d (inline)",
869 ilist->filename,
870 ilist->line_nr);
871 else
872 scnprintf(buf, sizeof(buf), "??");
873 } else if (ilist->funcname != NULL)
874 scnprintf(buf, sizeof(buf), "%s (inline)",
875 ilist->funcname);
876 else if (ilist->filename != NULL)
877 scnprintf(buf, sizeof(buf),
878 "%s:%d (inline)",
879 ilist->filename,
880 ilist->line_nr);
881 else
882 scnprintf(buf, sizeof(buf), "??");
883
884 ui_browser__set_color(&browser->b, color);
885 hist_browser__gotorc(browser, row, 0);
886 ui_browser__write_nstring(&browser->b, " ",
887 LEVEL_OFFSET_STEP + offset);
888 ui_browser__write_nstring(&browser->b, buf, width);
889 row++;
890 }
891 }
892
893 return row - first_row;
894}
895
896static size_t show_inline_list(struct hist_browser *browser, struct map *map,
897 u64 ip, int row, int offset)
898{
899 struct inline_node *node;
900 int ret;
901
902 node = inline_node__create(map, ip);
903 if (node == NULL)
904 return 0;
905
906 ret = hist_browser__show_inline(browser, node, row, offset);
907
908 inline_node__delete(node);
909 return ret;
910}
911
756static int hist_browser__show_callchain_list(struct hist_browser *browser, 912static int hist_browser__show_callchain_list(struct hist_browser *browser,
757 struct callchain_node *node, 913 struct callchain_node *node,
758 struct callchain_list *chain, 914 struct callchain_list *chain,
@@ -764,6 +920,7 @@ static int hist_browser__show_callchain_list(struct hist_browser *browser,
764 char bf[1024], *alloc_str; 920 char bf[1024], *alloc_str;
765 char buf[64], *alloc_str2; 921 char buf[64], *alloc_str2;
766 const char *str; 922 const char *str;
923 int inline_rows = 0, ret = 1;
767 924
768 if (arg->row_offset != 0) { 925 if (arg->row_offset != 0) {
769 arg->row_offset--; 926 arg->row_offset--;
@@ -801,10 +958,15 @@ static int hist_browser__show_callchain_list(struct hist_browser *browser,
801 } 958 }
802 959
803 print(browser, chain, str, offset, row, arg); 960 print(browser, chain, str, offset, row, arg);
804
805 free(alloc_str); 961 free(alloc_str);
806 free(alloc_str2); 962 free(alloc_str2);
807 return 1; 963
964 if (symbol_conf.inline_name) {
965 inline_rows = show_inline_list(browser, chain->ms.map,
966 chain->ip, row + 1, offset);
967 }
968
969 return ret + inline_rows;
808} 970}
809 971
810static bool check_percent_display(struct rb_node *node, u64 parent_total) 972static bool check_percent_display(struct rb_node *node, u64 parent_total)
@@ -1228,6 +1390,12 @@ static int hist_browser__show_entry(struct hist_browser *browser,
1228 folded_sign = hist_entry__folded(entry); 1390 folded_sign = hist_entry__folded(entry);
1229 } 1391 }
1230 1392
1393 if (symbol_conf.inline_name &&
1394 (!entry->has_children)) {
1395 hist_entry_init_inline_node(entry);
1396 folded_sign = hist_entry__folded(entry);
1397 }
1398
1231 if (row_offset == 0) { 1399 if (row_offset == 0) {
1232 struct hpp_arg arg = { 1400 struct hpp_arg arg = {
1233 .b = &browser->b, 1401 .b = &browser->b,
@@ -1259,7 +1427,8 @@ static int hist_browser__show_entry(struct hist_browser *browser,
1259 } 1427 }
1260 1428
1261 if (first) { 1429 if (first) {
1262 if (symbol_conf.use_callchain) { 1430 if (symbol_conf.use_callchain ||
1431 symbol_conf.inline_name) {
1263 ui_browser__printf(&browser->b, "%c ", folded_sign); 1432 ui_browser__printf(&browser->b, "%c ", folded_sign);
1264 width -= 2; 1433 width -= 2;
1265 } 1434 }
@@ -1301,8 +1470,14 @@ static int hist_browser__show_entry(struct hist_browser *browser,
1301 .is_current_entry = current_entry, 1470 .is_current_entry = current_entry,
1302 }; 1471 };
1303 1472
1304 printed += hist_browser__show_callchain(browser, entry, 1, row, 1473 if (entry->inline_node)
1305 hist_browser__show_callchain_entry, &arg, 1474 printed += hist_browser__show_inline(browser,
1475 entry->inline_node, row, 0);
1476 else
1477 printed += hist_browser__show_callchain(browser,
1478 entry, 1, row,
1479 hist_browser__show_callchain_entry,
1480 &arg,
1306 hist_browser__check_output_full); 1481 hist_browser__check_output_full);
1307 } 1482 }
1308 1483
@@ -2308,7 +2483,7 @@ static int switch_data_file(void)
2308 return ret; 2483 return ret;
2309 2484
2310 memset(options, 0, sizeof(options)); 2485 memset(options, 0, sizeof(options));
2311 memset(options, 0, sizeof(abs_path)); 2486 memset(abs_path, 0, sizeof(abs_path));
2312 2487
2313 while ((dent = readdir(pwd_dir))) { 2488 while ((dent = readdir(pwd_dir))) {
2314 char path[PATH_MAX]; 2489 char path[PATH_MAX];
diff --git a/tools/perf/ui/browsers/map.c b/tools/perf/ui/browsers/map.c
index 9ce142de536d..ffa5addf631d 100644
--- a/tools/perf/ui/browsers/map.c
+++ b/tools/perf/ui/browsers/map.c
@@ -11,6 +11,8 @@
11#include "../keysyms.h" 11#include "../keysyms.h"
12#include "map.h" 12#include "map.h"
13 13
14#include "sane_ctype.h"
15
14struct map_browser { 16struct map_browser {
15 struct ui_browser b; 17 struct ui_browser b;
16 struct map *map; 18 struct map *map;
diff --git a/tools/perf/ui/gtk/annotate.c b/tools/perf/ui/gtk/annotate.c
index 8c9308ac30b7..e99ba86158d2 100644
--- a/tools/perf/ui/gtk/annotate.c
+++ b/tools/perf/ui/gtk/annotate.c
@@ -3,7 +3,8 @@
3#include "util/annotate.h" 3#include "util/annotate.h"
4#include "util/evsel.h" 4#include "util/evsel.h"
5#include "ui/helpline.h" 5#include "ui/helpline.h"
6 6#include <inttypes.h>
7#include <signal.h>
7 8
8enum { 9enum {
9 ANN_COL__PERCENT, 10 ANN_COL__PERCENT,
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index a4f02de7c1b5..e24f83957705 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -4,7 +4,9 @@
4#include "../sort.h" 4#include "../sort.h"
5#include "../hist.h" 5#include "../hist.h"
6#include "../helpline.h" 6#include "../helpline.h"
7#include "../string2.h"
7#include "gtk.h" 8#include "gtk.h"
9#include <signal.h>
8 10
9#define MAX_COLUMNS 32 11#define MAX_COLUMNS 32
10 12
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 5d632dca672a..59addd52d9cd 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -1,3 +1,4 @@
1#include <inttypes.h>
1#include <math.h> 2#include <math.h>
2#include <linux/compiler.h> 3#include <linux/compiler.h>
3 4
diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c
index 50d13e58210f..5ea0b40c4fc2 100644
--- a/tools/perf/ui/setup.c
+++ b/tools/perf/ui/setup.c
@@ -4,6 +4,7 @@
4#include "../util/cache.h" 4#include "../util/cache.h"
5#include "../util/debug.h" 5#include "../util/debug.h"
6#include "../util/hist.h" 6#include "../util/hist.h"
7#include "../util/util.h"
7 8
8pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER; 9pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;
9void *perf_gtk_handle; 10void *perf_gtk_handle;
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 668f4aecf2e6..42e432bd2eb4 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -4,7 +4,10 @@
4#include "../../util/hist.h" 4#include "../../util/hist.h"
5#include "../../util/sort.h" 5#include "../../util/sort.h"
6#include "../../util/evsel.h" 6#include "../../util/evsel.h"
7 7#include "../../util/srcline.h"
8#include "../../util/string2.h"
9#include "../../util/thread.h"
10#include "../../util/sane_ctype.h"
8 11
9static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) 12static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
10{ 13{
@@ -17,6 +20,67 @@ static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
17 return ret; 20 return ret;
18} 21}
19 22
23static size_t inline__fprintf(struct map *map, u64 ip, int left_margin,
24 int depth, int depth_mask, FILE *fp)
25{
26 struct dso *dso;
27 struct inline_node *node;
28 struct inline_list *ilist;
29 int ret = 0, i;
30
31 if (map == NULL)
32 return 0;
33
34 dso = map->dso;
35 if (dso == NULL)
36 return 0;
37
38 if (dso->kernel != DSO_TYPE_USER)
39 return 0;
40
41 node = dso__parse_addr_inlines(dso,
42 map__rip_2objdump(map, ip));
43 if (node == NULL)
44 return 0;
45
46 list_for_each_entry(ilist, &node->val, list) {
47 if ((ilist->filename != NULL) || (ilist->funcname != NULL)) {
48 ret += callchain__fprintf_left_margin(fp, left_margin);
49
50 for (i = 0; i < depth; i++) {
51 if (depth_mask & (1 << i))
52 ret += fprintf(fp, "|");
53 else
54 ret += fprintf(fp, " ");
55 ret += fprintf(fp, " ");
56 }
57
58 if (callchain_param.key == CCKEY_ADDRESS ||
59 callchain_param.key == CCKEY_SRCLINE) {
60 if (ilist->filename != NULL)
61 ret += fprintf(fp, "%s:%d (inline)",
62 ilist->filename,
63 ilist->line_nr);
64 else
65 ret += fprintf(fp, "??");
66 } else if (ilist->funcname != NULL)
67 ret += fprintf(fp, "%s (inline)",
68 ilist->funcname);
69 else if (ilist->filename != NULL)
70 ret += fprintf(fp, "%s:%d (inline)",
71 ilist->filename,
72 ilist->line_nr);
73 else
74 ret += fprintf(fp, "??");
75
76 ret += fprintf(fp, "\n");
77 }
78 }
79
80 inline_node__delete(node);
81 return ret;
82}
83
20static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask, 84static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
21 int left_margin) 85 int left_margin)
22{ 86{
@@ -78,6 +142,10 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_node *node,
78 fputs(str, fp); 142 fputs(str, fp);
79 fputc('\n', fp); 143 fputc('\n', fp);
80 free(alloc_str); 144 free(alloc_str);
145
146 if (symbol_conf.inline_name)
147 ret += inline__fprintf(chain->ms.map, chain->ip,
148 left_margin, depth, depth_mask, fp);
81 return ret; 149 return ret;
82} 150}
83 151
@@ -229,6 +297,7 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
229 if (!i++ && field_order == NULL && 297 if (!i++ && field_order == NULL &&
230 sort_order && !prefixcmp(sort_order, "sym")) 298 sort_order && !prefixcmp(sort_order, "sym"))
231 continue; 299 continue;
300
232 if (!printed) { 301 if (!printed) {
233 ret += callchain__fprintf_left_margin(fp, left_margin); 302 ret += callchain__fprintf_left_margin(fp, left_margin);
234 ret += fprintf(fp, "|\n"); 303 ret += fprintf(fp, "|\n");
@@ -251,6 +320,13 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
251 320
252 if (++entries_printed == callchain_param.print_limit) 321 if (++entries_printed == callchain_param.print_limit)
253 break; 322 break;
323
324 if (symbol_conf.inline_name)
325 ret += inline__fprintf(chain->ms.map,
326 chain->ip,
327 left_margin,
328 0, 0,
329 fp);
254 } 330 }
255 root = &cnode->rb_root; 331 root = &cnode->rb_root;
256 } 332 }
@@ -529,6 +605,8 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
529 bool use_callchain) 605 bool use_callchain)
530{ 606{
531 int ret; 607 int ret;
608 int callchain_ret = 0;
609 int inline_ret = 0;
532 struct perf_hpp hpp = { 610 struct perf_hpp hpp = {
533 .buf = bf, 611 .buf = bf,
534 .size = size, 612 .size = size,
@@ -547,7 +625,16 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
547 ret = fprintf(fp, "%s\n", bf); 625 ret = fprintf(fp, "%s\n", bf);
548 626
549 if (use_callchain) 627 if (use_callchain)
550 ret += hist_entry_callchain__fprintf(he, total_period, 0, fp); 628 callchain_ret = hist_entry_callchain__fprintf(he, total_period,
629 0, fp);
630
631 if (callchain_ret == 0 && symbol_conf.inline_name) {
632 inline_ret = inline__fprintf(he->ms.map, he->ip, 0, 0, 0, fp);
633 ret += inline_ret;
634 if (inline_ret > 0)
635 ret += fprintf(fp, "\n");
636 } else
637 ret += callchain_ret;
551 638
552 return ret; 639 return ret;
553} 640}
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c
index 4ea2ba861fc2..d9350a1da48b 100644
--- a/tools/perf/ui/tui/setup.c
+++ b/tools/perf/ui/tui/setup.c
@@ -1,6 +1,7 @@
1#include <errno.h> 1#include <errno.h>
2#include <signal.h> 2#include <signal.h>
3#include <stdbool.h> 3#include <stdbool.h>
4#include <linux/kernel.h>
4#ifdef HAVE_BACKTRACE_SUPPORT 5#ifdef HAVE_BACKTRACE_SUPPORT
5#include <execinfo.h> 6#include <execinfo.h>
6#endif 7#endif
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 5da376bc1afc..069583bdc670 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -1,4 +1,3 @@
1libperf-y += alias.o
2libperf-y += annotate.o 1libperf-y += annotate.o
3libperf-y += block-range.o 2libperf-y += block-range.o
4libperf-y += build-id.o 3libperf-y += build-id.o
@@ -17,6 +16,7 @@ libperf-y += llvm-utils.o
17libperf-y += parse-events.o 16libperf-y += parse-events.o
18libperf-y += perf_regs.o 17libperf-y += perf_regs.o
19libperf-y += path.o 18libperf-y += path.o
19libperf-y += print_binary.o
20libperf-y += rbtree.o 20libperf-y += rbtree.o
21libperf-y += libstring.o 21libperf-y += libstring.o
22libperf-y += bitmap.o 22libperf-y += bitmap.o
@@ -42,6 +42,7 @@ libperf-y += pstack.o
42libperf-y += session.o 42libperf-y += session.o
43libperf-$(CONFIG_AUDIT) += syscalltbl.o 43libperf-$(CONFIG_AUDIT) += syscalltbl.o
44libperf-y += ordered-events.o 44libperf-y += ordered-events.o
45libperf-y += namespaces.o
45libperf-y += comm.o 46libperf-y += comm.o
46libperf-y += thread.o 47libperf-y += thread.o
47libperf-y += thread_map.o 48libperf-y += thread_map.o
@@ -81,13 +82,16 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt-decoder/
81libperf-$(CONFIG_AUXTRACE) += intel-pt.o 82libperf-$(CONFIG_AUXTRACE) += intel-pt.o
82libperf-$(CONFIG_AUXTRACE) += intel-bts.o 83libperf-$(CONFIG_AUXTRACE) += intel-bts.o
83libperf-y += parse-branch-options.o 84libperf-y += parse-branch-options.o
85libperf-y += dump-insn.o
84libperf-y += parse-regs-options.o 86libperf-y += parse-regs-options.o
85libperf-y += term.o 87libperf-y += term.o
86libperf-y += help-unknown-cmd.o 88libperf-y += help-unknown-cmd.o
87libperf-y += mem-events.o 89libperf-y += mem-events.o
88libperf-y += vsprintf.o 90libperf-y += vsprintf.o
89libperf-y += drv_configs.o 91libperf-y += drv_configs.o
92libperf-y += units.o
90libperf-y += time-utils.o 93libperf-y += time-utils.o
94libperf-y += expr-bison.o
91 95
92libperf-$(CONFIG_LIBBPF) += bpf-loader.o 96libperf-$(CONFIG_LIBBPF) += bpf-loader.o
93libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o 97libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
@@ -140,6 +144,10 @@ $(OUTPUT)util/parse-events-bison.c: util/parse-events.y
140 $(call rule_mkdir) 144 $(call rule_mkdir)
141 $(Q)$(call echo-cmd,bison)$(BISON) -v util/parse-events.y -d $(PARSER_DEBUG_BISON) -o $@ -p parse_events_ 145 $(Q)$(call echo-cmd,bison)$(BISON) -v util/parse-events.y -d $(PARSER_DEBUG_BISON) -o $@ -p parse_events_
142 146
147$(OUTPUT)util/expr-bison.c: util/expr.y
148 $(call rule_mkdir)
149 $(Q)$(call echo-cmd,bison)$(BISON) -v util/expr.y -d $(PARSER_DEBUG_BISON) -o $@ -p expr__
150
143$(OUTPUT)util/pmu-flex.c: util/pmu.l $(OUTPUT)util/pmu-bison.c 151$(OUTPUT)util/pmu-flex.c: util/pmu.l $(OUTPUT)util/pmu-bison.c
144 $(call rule_mkdir) 152 $(call rule_mkdir)
145 $(Q)$(call echo-cmd,flex)$(FLEX) -o $@ --header-file=$(OUTPUT)util/pmu-flex.h util/pmu.l 153 $(Q)$(call echo-cmd,flex)$(FLEX) -o $@ --header-file=$(OUTPUT)util/pmu-flex.h util/pmu.l
@@ -152,6 +160,7 @@ CFLAGS_parse-events-flex.o += -w
152CFLAGS_pmu-flex.o += -w 160CFLAGS_pmu-flex.o += -w
153CFLAGS_parse-events-bison.o += -DYYENABLE_NLS=0 -w 161CFLAGS_parse-events-bison.o += -DYYENABLE_NLS=0 -w
154CFLAGS_pmu-bison.o += -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -w 162CFLAGS_pmu-bison.o += -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -w
163CFLAGS_expr-bison.o += -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -w
155 164
156$(OUTPUT)util/parse-events.o: $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-bison.c 165$(OUTPUT)util/parse-events.o: $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-bison.c
157$(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c 166$(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c
diff --git a/tools/perf/util/alias.c b/tools/perf/util/alias.c
deleted file mode 100644
index 6455471d9cd1..000000000000
--- a/tools/perf/util/alias.c
+++ /dev/null
@@ -1,78 +0,0 @@
1#include "cache.h"
2#include "util.h"
3#include "config.h"
4
5static const char *alias_key;
6static char *alias_val;
7
8static int alias_lookup_cb(const char *k, const char *v,
9 void *cb __maybe_unused)
10{
11 if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) {
12 if (!v)
13 return config_error_nonbool(k);
14 alias_val = strdup(v);
15 return 0;
16 }
17 return 0;
18}
19
20char *alias_lookup(const char *alias)
21{
22 alias_key = alias;
23 alias_val = NULL;
24 perf_config(alias_lookup_cb, NULL);
25 return alias_val;
26}
27
28int split_cmdline(char *cmdline, const char ***argv)
29{
30 int src, dst, count = 0, size = 16;
31 char quoted = 0;
32
33 *argv = malloc(sizeof(char*) * size);
34
35 /* split alias_string */
36 (*argv)[count++] = cmdline;
37 for (src = dst = 0; cmdline[src];) {
38 char c = cmdline[src];
39 if (!quoted && isspace(c)) {
40 cmdline[dst++] = 0;
41 while (cmdline[++src]
42 && isspace(cmdline[src]))
43 ; /* skip */
44 if (count >= size) {
45 size += 16;
46 *argv = realloc(*argv, sizeof(char*) * size);
47 }
48 (*argv)[count++] = cmdline + dst;
49 } else if (!quoted && (c == '\'' || c == '"')) {
50 quoted = c;
51 src++;
52 } else if (c == quoted) {
53 quoted = 0;
54 src++;
55 } else {
56 if (c == '\\' && quoted != '\'') {
57 src++;
58 c = cmdline[src];
59 if (!c) {
60 zfree(argv);
61 return error("cmdline ends with \\");
62 }
63 }
64 cmdline[dst++] = c;
65 src++;
66 }
67 }
68
69 cmdline[dst] = 0;
70
71 if (quoted) {
72 zfree(argv);
73 return error("unclosed quote");
74 }
75
76 return count;
77}
78
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 7aa57225cbf7..683f8340460c 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -7,6 +7,8 @@
7 * Released under the GPL v2. (and only v2, not any later version) 7 * Released under the GPL v2. (and only v2, not any later version)
8 */ 8 */
9 9
10#include <errno.h>
11#include <inttypes.h>
10#include "util.h" 12#include "util.h"
11#include "ui/ui.h" 13#include "ui/ui.h"
12#include "sort.h" 14#include "sort.h"
@@ -18,12 +20,16 @@
18#include "annotate.h" 20#include "annotate.h"
19#include "evsel.h" 21#include "evsel.h"
20#include "block-range.h" 22#include "block-range.h"
23#include "string2.h"
21#include "arch/common.h" 24#include "arch/common.h"
22#include <regex.h> 25#include <regex.h>
23#include <pthread.h> 26#include <pthread.h>
24#include <linux/bitops.h> 27#include <linux/bitops.h>
28#include <linux/kernel.h>
25#include <sys/utsname.h> 29#include <sys/utsname.h>
26 30
31#include "sane_ctype.h"
32
27const char *disassembler_style; 33const char *disassembler_style;
28const char *objdump_path; 34const char *objdump_path;
29static regex_t file_lineno; 35static regex_t file_lineno;
@@ -108,6 +114,7 @@ static int arch__associate_ins_ops(struct arch* arch, const char *name, struct i
108#include "arch/arm64/annotate/instructions.c" 114#include "arch/arm64/annotate/instructions.c"
109#include "arch/x86/annotate/instructions.c" 115#include "arch/x86/annotate/instructions.c"
110#include "arch/powerpc/annotate/instructions.c" 116#include "arch/powerpc/annotate/instructions.c"
117#include "arch/s390/annotate/instructions.c"
111 118
112static struct arch architectures[] = { 119static struct arch architectures[] = {
113 { 120 {
@@ -132,6 +139,7 @@ static struct arch architectures[] = {
132 }, 139 },
133 { 140 {
134 .name = "s390", 141 .name = "s390",
142 .init = s390__annotate_init,
135 .objdump = { 143 .objdump = {
136 .comment_char = '#', 144 .comment_char = '#',
137 }, 145 },
@@ -385,9 +393,7 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map *m
385 if (comment == NULL) 393 if (comment == NULL)
386 return 0; 394 return 0;
387 395
388 while (comment[0] != '\0' && isspace(comment[0])) 396 comment = ltrim(comment);
389 ++comment;
390
391 comment__symbol(ops->source.raw, comment, &ops->source.addr, &ops->source.name); 397 comment__symbol(ops->source.raw, comment, &ops->source.addr, &ops->source.name);
392 comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name); 398 comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name);
393 399
@@ -432,9 +438,7 @@ static int dec__parse(struct arch *arch __maybe_unused, struct ins_operands *ops
432 if (comment == NULL) 438 if (comment == NULL)
433 return 0; 439 return 0;
434 440
435 while (comment[0] != '\0' && isspace(comment[0])) 441 comment = ltrim(comment);
436 ++comment;
437
438 comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name); 442 comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name);
439 443
440 return 0; 444 return 0;
@@ -783,10 +787,7 @@ static void disasm_line__init_ins(struct disasm_line *dl, struct arch *arch, str
783 787
784static int disasm_line__parse(char *line, const char **namep, char **rawp) 788static int disasm_line__parse(char *line, const char **namep, char **rawp)
785{ 789{
786 char *name = line, tmp; 790 char tmp, *name = ltrim(line);
787
788 while (isspace(name[0]))
789 ++name;
790 791
791 if (name[0] == '\0') 792 if (name[0] == '\0')
792 return -1; 793 return -1;
@@ -804,12 +805,7 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp)
804 goto out_free_name; 805 goto out_free_name;
805 806
806 (*rawp)[0] = tmp; 807 (*rawp)[0] = tmp;
807 808 *rawp = ltrim(*rawp);
808 if ((*rawp)[0] != '\0') {
809 (*rawp)++;
810 while (isspace((*rawp)[0]))
811 ++(*rawp);
812 }
813 809
814 return 0; 810 return 0;
815 811
@@ -1154,7 +1150,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
1154{ 1150{
1155 struct annotation *notes = symbol__annotation(sym); 1151 struct annotation *notes = symbol__annotation(sym);
1156 struct disasm_line *dl; 1152 struct disasm_line *dl;
1157 char *line = NULL, *parsed_line, *tmp, *tmp2, *c; 1153 char *line = NULL, *parsed_line, *tmp, *tmp2;
1158 size_t line_len; 1154 size_t line_len;
1159 s64 line_ip, offset = -1; 1155 s64 line_ip, offset = -1;
1160 regmatch_t match[2]; 1156 regmatch_t match[2];
@@ -1165,32 +1161,16 @@ static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
1165 if (!line) 1161 if (!line)
1166 return -1; 1162 return -1;
1167 1163
1168 while (line_len != 0 && isspace(line[line_len - 1]))
1169 line[--line_len] = '\0';
1170
1171 c = strchr(line, '\n');
1172 if (c)
1173 *c = 0;
1174
1175 line_ip = -1; 1164 line_ip = -1;
1176 parsed_line = line; 1165 parsed_line = rtrim(line);
1177 1166
1178 /* /filename:linenr ? Save line number and ignore. */ 1167 /* /filename:linenr ? Save line number and ignore. */
1179 if (regexec(&file_lineno, line, 2, match, 0) == 0) { 1168 if (regexec(&file_lineno, parsed_line, 2, match, 0) == 0) {
1180 *line_nr = atoi(line + match[1].rm_so); 1169 *line_nr = atoi(parsed_line + match[1].rm_so);
1181 return 0; 1170 return 0;
1182 } 1171 }
1183 1172
1184 /* 1173 tmp = ltrim(parsed_line);
1185 * Strip leading spaces:
1186 */
1187 tmp = line;
1188 while (*tmp) {
1189 if (*tmp != ' ')
1190 break;
1191 tmp++;
1192 }
1193
1194 if (*tmp) { 1174 if (*tmp) {
1195 /* 1175 /*
1196 * Parse hexa addresses followed by ':' 1176 * Parse hexa addresses followed by ':'
@@ -1313,6 +1293,7 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil
1313{ 1293{
1314 char linkname[PATH_MAX]; 1294 char linkname[PATH_MAX];
1315 char *build_id_filename; 1295 char *build_id_filename;
1296 char *build_id_path = NULL;
1316 1297
1317 if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && 1298 if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
1318 !dso__is_kcore(dso)) 1299 !dso__is_kcore(dso))
@@ -1328,8 +1309,14 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil
1328 goto fallback; 1309 goto fallback;
1329 } 1310 }
1330 1311
1312 build_id_path = strdup(filename);
1313 if (!build_id_path)
1314 return -1;
1315
1316 dirname(build_id_path);
1317
1331 if (dso__is_kcore(dso) || 1318 if (dso__is_kcore(dso) ||
1332 readlink(filename, linkname, sizeof(linkname)) < 0 || 1319 readlink(build_id_path, linkname, sizeof(linkname)) < 0 ||
1333 strstr(linkname, DSO__NAME_KALLSYMS) || 1320 strstr(linkname, DSO__NAME_KALLSYMS) ||
1334 access(filename, R_OK)) { 1321 access(filename, R_OK)) {
1335fallback: 1322fallback:
@@ -1341,6 +1328,7 @@ fallback:
1341 __symbol__join_symfs(filename, filename_size, dso->long_name); 1328 __symbol__join_symfs(filename, filename_size, dso->long_name);
1342 } 1329 }
1343 1330
1331 free(build_id_path);
1344 return 0; 1332 return 0;
1345} 1333}
1346 1334
@@ -1441,7 +1429,7 @@ int symbol__disassemble(struct symbol *sym, struct map *map, const char *arch_na
1441 snprintf(command, sizeof(command), 1429 snprintf(command, sizeof(command),
1442 "%s %s%s --start-address=0x%016" PRIx64 1430 "%s %s%s --start-address=0x%016" PRIx64
1443 " --stop-address=0x%016" PRIx64 1431 " --stop-address=0x%016" PRIx64
1444 " -l -d %s %s -C %s 2>/dev/null|grep -v %s|expand", 1432 " -l -d %s %s -C %s 2>/dev/null|grep -v %s:|expand",
1445 objdump_path ? objdump_path : "objdump", 1433 objdump_path ? objdump_path : "objdump",
1446 disassembler_style ? "-M " : "", 1434 disassembler_style ? "-M " : "",
1447 disassembler_style ? disassembler_style : "", 1435 disassembler_style ? disassembler_style : "",
@@ -1488,6 +1476,12 @@ int symbol__disassemble(struct symbol *sym, struct map *map, const char *arch_na
1488 1476
1489 nline = 0; 1477 nline = 0;
1490 while (!feof(file)) { 1478 while (!feof(file)) {
1479 /*
1480 * The source code line number (lineno) needs to be kept in
1481 * accross calls to symbol__parse_objdump_line(), so that it
1482 * can associate it with the instructions till the next one.
1483 * See disasm_line__new() and struct disasm_line::line_nr.
1484 */
1491 if (symbol__parse_objdump_line(sym, map, arch, file, privsize, 1485 if (symbol__parse_objdump_line(sym, map, arch, file, privsize,
1492 &lineno) < 0) 1486 &lineno) < 0)
1493 break; 1487 break;
@@ -1657,24 +1651,31 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map,
1657 start = map__rip_2objdump(map, sym->start); 1651 start = map__rip_2objdump(map, sym->start);
1658 1652
1659 for (i = 0; i < len; i++) { 1653 for (i = 0; i < len; i++) {
1660 u64 offset; 1654 u64 offset, nr_samples;
1661 double percent_max = 0.0; 1655 double percent_max = 0.0;
1662 1656
1663 src_line->nr_pcnt = nr_pcnt; 1657 src_line->nr_pcnt = nr_pcnt;
1664 1658
1665 for (k = 0; k < nr_pcnt; k++) { 1659 for (k = 0; k < nr_pcnt; k++) {
1660 double percent = 0.0;
1661
1666 h = annotation__histogram(notes, evidx + k); 1662 h = annotation__histogram(notes, evidx + k);
1667 src_line->samples[k].percent = 100.0 * h->addr[i] / h->sum; 1663 nr_samples = h->addr[i];
1664 if (h->sum)
1665 percent = 100.0 * nr_samples / h->sum;
1668 1666
1669 if (src_line->samples[k].percent > percent_max) 1667 if (percent > percent_max)
1670 percent_max = src_line->samples[k].percent; 1668 percent_max = percent;
1669 src_line->samples[k].percent = percent;
1670 src_line->samples[k].nr = nr_samples;
1671 } 1671 }
1672 1672
1673 if (percent_max <= 0.5) 1673 if (percent_max <= 0.5)
1674 goto next; 1674 goto next;
1675 1675
1676 offset = start + i; 1676 offset = start + i;
1677 src_line->path = get_srcline(map->dso, offset, NULL, false); 1677 src_line->path = get_srcline(map->dso, offset, NULL,
1678 false, true);
1678 insert_source_line(&tmp_root, src_line); 1679 insert_source_line(&tmp_root, src_line);
1679 1680
1680 next: 1681 next:
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 09776b5af991..948aa8e6fd39 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -98,7 +98,7 @@ struct cyc_hist {
98struct source_line_samples { 98struct source_line_samples {
99 double percent; 99 double percent;
100 double percent_sum; 100 double percent_sum;
101 double nr; 101 u64 nr;
102}; 102};
103 103
104struct source_line { 104struct source_line {
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index c5a6e0b12452..0daf63b9ee3e 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -13,10 +13,10 @@
13 * 13 *
14 */ 14 */
15 15
16#include <inttypes.h>
16#include <sys/types.h> 17#include <sys/types.h>
17#include <sys/mman.h> 18#include <sys/mman.h>
18#include <stdbool.h> 19#include <stdbool.h>
19#include <ctype.h>
20#include <string.h> 20#include <string.h>
21#include <limits.h> 21#include <limits.h>
22#include <errno.h> 22#include <errno.h>
@@ -46,7 +46,6 @@
46#include "cpumap.h" 46#include "cpumap.h"
47#include "thread_map.h" 47#include "thread_map.h"
48#include "asm/bug.h" 48#include "asm/bug.h"
49#include "symbol/kallsyms.h"
50#include "auxtrace.h" 49#include "auxtrace.h"
51 50
52#include <linux/hash.h> 51#include <linux/hash.h>
@@ -59,6 +58,9 @@
59#include "intel-pt.h" 58#include "intel-pt.h"
60#include "intel-bts.h" 59#include "intel-bts.h"
61 60
61#include "sane_ctype.h"
62#include "symbol/kallsyms.h"
63
62int auxtrace_mmap__mmap(struct auxtrace_mmap *mm, 64int auxtrace_mmap__mmap(struct auxtrace_mmap *mm,
63 struct auxtrace_mmap_params *mp, 65 struct auxtrace_mmap_params *mp,
64 void *userpg, int fd) 66 void *userpg, int fd)
@@ -1826,7 +1828,7 @@ static int addr_filter__resolve_kernel_syms(struct addr_filter *filt)
1826 filt->addr = start; 1828 filt->addr = start;
1827 if (filt->range && !filt->size && !filt->sym_to) { 1829 if (filt->range && !filt->size && !filt->sym_to) {
1828 filt->size = size; 1830 filt->size = size;
1829 no_size = !!size; 1831 no_size = !size;
1830 } 1832 }
1831 } 1833 }
1832 1834
@@ -1840,7 +1842,7 @@ static int addr_filter__resolve_kernel_syms(struct addr_filter *filt)
1840 if (err) 1842 if (err)
1841 return err; 1843 return err;
1842 filt->size = start + size - filt->addr; 1844 filt->size = start + size - filt->addr;
1843 no_size = !!size; 1845 no_size = !size;
1844 } 1846 }
1845 1847
1846 /* The very last symbol in kallsyms does not imply a particular size */ 1848 /* The very last symbol in kallsyms does not imply a particular size */
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 26fb1ee5746a..9f0de72d58e2 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -17,6 +17,7 @@
17#define __PERF_AUXTRACE_H 17#define __PERF_AUXTRACE_H
18 18
19#include <sys/types.h> 19#include <sys/types.h>
20#include <errno.h>
20#include <stdbool.h> 21#include <stdbool.h>
21#include <stddef.h> 22#include <stddef.h>
22#include <linux/list.h> 23#include <linux/list.h>
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index bc6bc7062eb4..4bd2d1d882af 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -9,7 +9,9 @@
9#include <bpf/libbpf.h> 9#include <bpf/libbpf.h>
10#include <bpf/bpf.h> 10#include <bpf/bpf.h>
11#include <linux/err.h> 11#include <linux/err.h>
12#include <linux/kernel.h>
12#include <linux/string.h> 13#include <linux/string.h>
14#include <errno.h>
13#include "perf.h" 15#include "perf.h"
14#include "debug.h" 16#include "debug.h"
15#include "bpf-loader.h" 17#include "bpf-loader.h"
@@ -17,6 +19,7 @@
17#include "probe-event.h" 19#include "probe-event.h"
18#include "probe-finder.h" // for MAX_PROBES 20#include "probe-finder.h" // for MAX_PROBES
19#include "parse-events.h" 21#include "parse-events.h"
22#include "strfilter.h"
20#include "llvm-utils.h" 23#include "llvm-utils.h"
21#include "c++/clang-c.h" 24#include "c++/clang-c.h"
22 25
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index f2b737b225f2..48863867878b 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -85,6 +85,8 @@ int bpf__strerror_setup_stdout(struct perf_evlist *evlist, int err,
85 char *buf, size_t size); 85 char *buf, size_t size);
86 86
87#else 87#else
88#include <errno.h>
89
88static inline struct bpf_object * 90static inline struct bpf_object *
89bpf__prepare_load(const char *filename __maybe_unused, 91bpf__prepare_load(const char *filename __maybe_unused,
90 bool source __maybe_unused) 92 bool source __maybe_unused)
diff --git a/tools/perf/util/bpf-prologue.c b/tools/perf/util/bpf-prologue.c
index 6cdbee119ceb..1356220a9f1b 100644
--- a/tools/perf/util/bpf-prologue.c
+++ b/tools/perf/util/bpf-prologue.c
@@ -12,6 +12,7 @@
12#include "bpf-loader.h" 12#include "bpf-loader.h"
13#include "bpf-prologue.h" 13#include "bpf-prologue.h"
14#include "probe-finder.h" 14#include "probe-finder.h"
15#include <errno.h>
15#include <dwarf-regs.h> 16#include <dwarf-regs.h>
16#include <linux/filter.h> 17#include <linux/filter.h>
17 18
diff --git a/tools/perf/util/bpf-prologue.h b/tools/perf/util/bpf-prologue.h
index d94cbea12899..ba564838375f 100644
--- a/tools/perf/util/bpf-prologue.h
+++ b/tools/perf/util/bpf-prologue.h
@@ -18,6 +18,8 @@ int bpf__gen_prologue(struct probe_trace_arg *args, int nargs,
18 struct bpf_insn *new_prog, size_t *new_cnt, 18 struct bpf_insn *new_prog, size_t *new_cnt,
19 size_t cnt_space); 19 size_t cnt_space);
20#else 20#else
21#include <errno.h>
22
21static inline int 23static inline int
22bpf__gen_prologue(struct probe_trace_arg *args __maybe_unused, 24bpf__gen_prologue(struct probe_trace_arg *args __maybe_unused,
23 int nargs __maybe_unused, 25 int nargs __maybe_unused,
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index e528c40739cc..168cc49654e7 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -7,18 +7,26 @@
7 * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <acme@redhat.com> 7 * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <acme@redhat.com>
8 */ 8 */
9#include "util.h" 9#include "util.h"
10#include <dirent.h>
11#include <errno.h>
10#include <stdio.h> 12#include <stdio.h>
13#include <sys/stat.h>
14#include <sys/types.h>
11#include "build-id.h" 15#include "build-id.h"
12#include "event.h" 16#include "event.h"
13#include "symbol.h" 17#include "symbol.h"
18#include "thread.h"
14#include <linux/kernel.h> 19#include <linux/kernel.h>
15#include "debug.h" 20#include "debug.h"
16#include "session.h" 21#include "session.h"
17#include "tool.h" 22#include "tool.h"
18#include "header.h" 23#include "header.h"
19#include "vdso.h" 24#include "vdso.h"
25#include "path.h"
20#include "probe-file.h" 26#include "probe-file.h"
27#include "strlist.h"
21 28
29#include "sane_ctype.h"
22 30
23static bool no_buildid_cache; 31static bool no_buildid_cache;
24 32
@@ -182,13 +190,17 @@ char *build_id_cache__origname(const char *sbuild_id)
182 char buf[PATH_MAX]; 190 char buf[PATH_MAX];
183 char *ret = NULL, *p; 191 char *ret = NULL, *p;
184 size_t offs = 5; /* == strlen("../..") */ 192 size_t offs = 5; /* == strlen("../..") */
193 ssize_t len;
185 194
186 linkname = build_id_cache__linkname(sbuild_id, NULL, 0); 195 linkname = build_id_cache__linkname(sbuild_id, NULL, 0);
187 if (!linkname) 196 if (!linkname)
188 return NULL; 197 return NULL;
189 198
190 if (readlink(linkname, buf, PATH_MAX) < 0) 199 len = readlink(linkname, buf, sizeof(buf) - 1);
200 if (len <= 0)
191 goto out; 201 goto out;
202 buf[len] = '\0';
203
192 /* The link should be "../..<origpath>/<sbuild_id>" */ 204 /* The link should be "../..<origpath>/<sbuild_id>" */
193 p = strrchr(buf, '/'); /* Cut off the "/<sbuild_id>" */ 205 p = strrchr(buf, '/'); /* Cut off the "/<sbuild_id>" */
194 if (p && (p > buf + offs)) { 206 if (p && (p > buf + offs)) {
@@ -443,14 +455,14 @@ void disable_buildid_cache(void)
443} 455}
444 456
445static bool lsdir_bid_head_filter(const char *name __maybe_unused, 457static bool lsdir_bid_head_filter(const char *name __maybe_unused,
446 struct dirent *d __maybe_unused) 458 struct dirent *d)
447{ 459{
448 return (strlen(d->d_name) == 2) && 460 return (strlen(d->d_name) == 2) &&
449 isxdigit(d->d_name[0]) && isxdigit(d->d_name[1]); 461 isxdigit(d->d_name[0]) && isxdigit(d->d_name[1]);
450} 462}
451 463
452static bool lsdir_bid_tail_filter(const char *name __maybe_unused, 464static bool lsdir_bid_tail_filter(const char *name __maybe_unused,
453 struct dirent *d __maybe_unused) 465 struct dirent *d)
454{ 466{
455 int i = 0; 467 int i = 0;
456 while (isxdigit(d->d_name[i]) && i < SBUILD_ID_SIZE - 3) 468 while (isxdigit(d->d_name[i]) && i < SBUILD_ID_SIZE - 3)
@@ -690,7 +702,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *name,
690 err = 0; 702 err = 0;
691 703
692 /* Update SDT cache : error is just warned */ 704 /* Update SDT cache : error is just warned */
693 if (build_id_cache__add_sdt_cache(sbuild_id, realname) < 0) 705 if (realname && build_id_cache__add_sdt_cache(sbuild_id, realname) < 0)
694 pr_debug4("Failed to update/scan SDT cache for %s\n", realname); 706 pr_debug4("Failed to update/scan SDT cache for %s\n", realname);
695 707
696out_free: 708out_free:
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index d27990610f9f..a96081121179 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -5,7 +5,6 @@
5#define SBUILD_ID_SIZE (BUILD_ID_SIZE * 2 + 1) 5#define SBUILD_ID_SIZE (BUILD_ID_SIZE * 2 + 1)
6 6
7#include "tool.h" 7#include "tool.h"
8#include "strlist.h"
9#include <linux/types.h> 8#include <linux/types.h>
10 9
11extern struct perf_tool build_id__mark_dso_hit_ops; 10extern struct perf_tool build_id__mark_dso_hit_ops;
@@ -34,6 +33,9 @@ char *build_id_cache__origname(const char *sbuild_id);
34char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size); 33char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size);
35char *build_id_cache__cachedir(const char *sbuild_id, const char *name, 34char *build_id_cache__cachedir(const char *sbuild_id, const char *name,
36 bool is_kallsyms, bool is_vdso); 35 bool is_kallsyms, bool is_vdso);
36
37struct strlist;
38
37struct strlist *build_id_cache__list_all(bool validonly); 39struct strlist *build_id_cache__list_all(bool validonly);
38char *build_id_cache__complement(const char *incomplete_sbuild_id); 40char *build_id_cache__complement(const char *incomplete_sbuild_id);
39int build_id_cache__list_build_ids(const char *pathname, 41int build_id_cache__list_build_ids(const char *pathname,
diff --git a/tools/perf/util/c++/clang-c.h b/tools/perf/util/c++/clang-c.h
index 0eadd792ab1f..ccafcf72b37a 100644
--- a/tools/perf/util/c++/clang-c.h
+++ b/tools/perf/util/c++/clang-c.h
@@ -20,6 +20,7 @@ extern int perf_clang__compile_bpf(const char *filename,
20 size_t *p_obj_buf_sz); 20 size_t *p_obj_buf_sz);
21#else 21#else
22 22
23#include <errno.h>
23 24
24static inline void perf_clang__init(void) { } 25static inline void perf_clang__init(void) { }
25static inline void perf_clang__cleanup(void) { } 26static inline void perf_clang__cleanup(void) { }
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 512c0c83fbc6..0328f297a748 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -15,7 +15,6 @@
15#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" 15#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
16#define PERF_PAGER_ENVIRONMENT "PERF_PAGER" 16#define PERF_PAGER_ENVIRONMENT "PERF_PAGER"
17 17
18char *alias_lookup(const char *alias);
19int split_cmdline(char *cmdline, const char ***argv); 18int split_cmdline(char *cmdline, const char ***argv);
20 19
21#define alloc_nr(x) (((x)+16)*3/2) 20#define alloc_nr(x) (((x)+16)*3/2)
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index aba953421a03..81fc29ac798f 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -9,6 +9,7 @@
9 * 9 *
10 */ 10 */
11 11
12#include <inttypes.h>
12#include <stdlib.h> 13#include <stdlib.h>
13#include <stdio.h> 14#include <stdio.h>
14#include <stdbool.h> 15#include <stdbool.h>
@@ -23,6 +24,21 @@
23#include "machine.h" 24#include "machine.h"
24#include "callchain.h" 25#include "callchain.h"
25 26
27#define CALLCHAIN_PARAM_DEFAULT \
28 .mode = CHAIN_GRAPH_ABS, \
29 .min_percent = 0.5, \
30 .order = ORDER_CALLEE, \
31 .key = CCKEY_FUNCTION, \
32 .value = CCVAL_PERCENT, \
33
34struct callchain_param callchain_param = {
35 CALLCHAIN_PARAM_DEFAULT
36};
37
38struct callchain_param callchain_param_default = {
39 CALLCHAIN_PARAM_DEFAULT
40};
41
26__thread struct callchain_cursor callchain_cursor; 42__thread struct callchain_cursor callchain_cursor;
27 43
28int parse_callchain_record_opt(const char *arg, struct callchain_param *param) 44int parse_callchain_record_opt(const char *arg, struct callchain_param *param)
@@ -80,6 +96,10 @@ static int parse_callchain_sort_key(const char *value)
80 callchain_param.key = CCKEY_ADDRESS; 96 callchain_param.key = CCKEY_ADDRESS;
81 return 0; 97 return 0;
82 } 98 }
99 if (!strncmp(value, "srcline", strlen(value))) {
100 callchain_param.key = CCKEY_SRCLINE;
101 return 0;
102 }
83 if (!strncmp(value, "branch", strlen(value))) { 103 if (!strncmp(value, "branch", strlen(value))) {
84 callchain_param.branch_callstack = 1; 104 callchain_param.branch_callstack = 1;
85 return 0; 105 return 0;
@@ -108,11 +128,37 @@ static int parse_callchain_value(const char *value)
108 return -1; 128 return -1;
109} 129}
110 130
131static int get_stack_size(const char *str, unsigned long *_size)
132{
133 char *endptr;
134 unsigned long size;
135 unsigned long max_size = round_down(USHRT_MAX, sizeof(u64));
136
137 size = strtoul(str, &endptr, 0);
138
139 do {
140 if (*endptr)
141 break;
142
143 size = round_up(size, sizeof(u64));
144 if (!size || size > max_size)
145 break;
146
147 *_size = size;
148 return 0;
149
150 } while (0);
151
152 pr_err("callchain: Incorrect stack dump size (max %ld): %s\n",
153 max_size, str);
154 return -1;
155}
156
111static int 157static int
112__parse_callchain_report_opt(const char *arg, bool allow_record_opt) 158__parse_callchain_report_opt(const char *arg, bool allow_record_opt)
113{ 159{
114 char *tok; 160 char *tok;
115 char *endptr; 161 char *endptr, *saveptr = NULL;
116 bool minpcnt_set = false; 162 bool minpcnt_set = false;
117 bool record_opt_set = false; 163 bool record_opt_set = false;
118 bool try_stack_size = false; 164 bool try_stack_size = false;
@@ -123,7 +169,7 @@ __parse_callchain_report_opt(const char *arg, bool allow_record_opt)
123 if (!arg) 169 if (!arg)
124 return 0; 170 return 0;
125 171
126 while ((tok = strtok((char *)arg, ",")) != NULL) { 172 while ((tok = strtok_r((char *)arg, ",", &saveptr)) != NULL) {
127 if (!strncmp(tok, "none", strlen(tok))) { 173 if (!strncmp(tok, "none", strlen(tok))) {
128 callchain_param.mode = CHAIN_NONE; 174 callchain_param.mode = CHAIN_NONE;
129 callchain_param.enabled = false; 175 callchain_param.enabled = false;
@@ -191,6 +237,68 @@ int parse_callchain_top_opt(const char *arg)
191 return __parse_callchain_report_opt(arg, true); 237 return __parse_callchain_report_opt(arg, true);
192} 238}
193 239
240int parse_callchain_record(const char *arg, struct callchain_param *param)
241{
242 char *tok, *name, *saveptr = NULL;
243 char *buf;
244 int ret = -1;
245
246 /* We need buffer that we know we can write to. */
247 buf = malloc(strlen(arg) + 1);
248 if (!buf)
249 return -ENOMEM;
250
251 strcpy(buf, arg);
252
253 tok = strtok_r((char *)buf, ",", &saveptr);
254 name = tok ? : (char *)buf;
255
256 do {
257 /* Framepointer style */
258 if (!strncmp(name, "fp", sizeof("fp"))) {
259 if (!strtok_r(NULL, ",", &saveptr)) {
260 param->record_mode = CALLCHAIN_FP;
261 ret = 0;
262 } else
263 pr_err("callchain: No more arguments "
264 "needed for --call-graph fp\n");
265 break;
266
267 /* Dwarf style */
268 } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) {
269 const unsigned long default_stack_dump_size = 8192;
270
271 ret = 0;
272 param->record_mode = CALLCHAIN_DWARF;
273 param->dump_size = default_stack_dump_size;
274
275 tok = strtok_r(NULL, ",", &saveptr);
276 if (tok) {
277 unsigned long size = 0;
278
279 ret = get_stack_size(tok, &size);
280 param->dump_size = size;
281 }
282 } else if (!strncmp(name, "lbr", sizeof("lbr"))) {
283 if (!strtok_r(NULL, ",", &saveptr)) {
284 param->record_mode = CALLCHAIN_LBR;
285 ret = 0;
286 } else
287 pr_err("callchain: No more arguments "
288 "needed for --call-graph lbr\n");
289 break;
290 } else {
291 pr_err("callchain: Unknown --call-graph option "
292 "value: %s\n", arg);
293 break;
294 }
295
296 } while (0);
297
298 free(buf);
299 return ret;
300}
301
194int perf_callchain_config(const char *var, const char *value) 302int perf_callchain_config(const char *var, const char *value)
195{ 303{
196 char *endptr; 304 char *endptr;
@@ -510,14 +618,51 @@ enum match_result {
510 MATCH_GT, 618 MATCH_GT,
511}; 619};
512 620
621static enum match_result match_chain_srcline(struct callchain_cursor_node *node,
622 struct callchain_list *cnode)
623{
624 char *left = get_srcline(cnode->ms.map->dso,
625 map__rip_2objdump(cnode->ms.map, cnode->ip),
626 cnode->ms.sym, true, false);
627 char *right = get_srcline(node->map->dso,
628 map__rip_2objdump(node->map, node->ip),
629 node->sym, true, false);
630 enum match_result ret = MATCH_EQ;
631 int cmp;
632
633 if (left && right)
634 cmp = strcmp(left, right);
635 else if (!left && right)
636 cmp = 1;
637 else if (left && !right)
638 cmp = -1;
639 else if (cnode->ip == node->ip)
640 cmp = 0;
641 else
642 cmp = (cnode->ip < node->ip) ? -1 : 1;
643
644 if (cmp != 0)
645 ret = cmp < 0 ? MATCH_LT : MATCH_GT;
646
647 free_srcline(left);
648 free_srcline(right);
649 return ret;
650}
651
513static enum match_result match_chain(struct callchain_cursor_node *node, 652static enum match_result match_chain(struct callchain_cursor_node *node,
514 struct callchain_list *cnode) 653 struct callchain_list *cnode)
515{ 654{
516 struct symbol *sym = node->sym; 655 struct symbol *sym = node->sym;
517 u64 left, right; 656 u64 left, right;
518 657
519 if (cnode->ms.sym && sym && 658 if (callchain_param.key == CCKEY_SRCLINE) {
520 callchain_param.key == CCKEY_FUNCTION) { 659 enum match_result match = match_chain_srcline(node, cnode);
660
661 if (match != MATCH_ERROR)
662 return match;
663 }
664
665 if (cnode->ms.sym && sym && callchain_param.key == CCKEY_FUNCTION) {
521 left = cnode->ms.sym->start; 666 left = cnode->ms.sym->start;
522 right = sym->start; 667 right = sym->start;
523 } else { 668 } else {
@@ -911,15 +1056,16 @@ out:
911char *callchain_list__sym_name(struct callchain_list *cl, 1056char *callchain_list__sym_name(struct callchain_list *cl,
912 char *bf, size_t bfsize, bool show_dso) 1057 char *bf, size_t bfsize, bool show_dso)
913{ 1058{
1059 bool show_addr = callchain_param.key == CCKEY_ADDRESS;
1060 bool show_srcline = show_addr || callchain_param.key == CCKEY_SRCLINE;
914 int printed; 1061 int printed;
915 1062
916 if (cl->ms.sym) { 1063 if (cl->ms.sym) {
917 if (callchain_param.key == CCKEY_ADDRESS && 1064 if (show_srcline && cl->ms.map && !cl->srcline)
918 cl->ms.map && !cl->srcline)
919 cl->srcline = get_srcline(cl->ms.map->dso, 1065 cl->srcline = get_srcline(cl->ms.map->dso,
920 map__rip_2objdump(cl->ms.map, 1066 map__rip_2objdump(cl->ms.map,
921 cl->ip), 1067 cl->ip),
922 cl->ms.sym, false); 1068 cl->ms.sym, false, show_addr);
923 if (cl->srcline) 1069 if (cl->srcline)
924 printed = scnprintf(bf, bfsize, "%s %s", 1070 printed = scnprintf(bf, bfsize, "%s %s",
925 cl->ms.sym->name, cl->srcline); 1071 cl->ms.sym->name, cl->srcline);
@@ -1063,63 +1209,100 @@ int callchain_branch_counts(struct callchain_root *root,
1063 cycles_count); 1209 cycles_count);
1064} 1210}
1065 1211
1066static int callchain_counts_printf(FILE *fp, char *bf, int bfsize, 1212static int counts_str_build(char *bf, int bfsize,
1067 u64 branch_count, u64 predicted_count, 1213 u64 branch_count, u64 predicted_count,
1068 u64 abort_count, u64 cycles_count, 1214 u64 abort_count, u64 cycles_count,
1069 u64 iter_count, u64 samples_count) 1215 u64 iter_count, u64 samples_count)
1070{ 1216{
1071 double predicted_percent = 0.0; 1217 double predicted_percent = 0.0;
1072 const char *null_str = ""; 1218 const char *null_str = "";
1073 char iter_str[32]; 1219 char iter_str[32];
1074 char *str; 1220 char cycle_str[32];
1075 u64 cycles = 0; 1221 char *istr, *cstr;
1076 1222 u64 cycles;
1077 if (branch_count == 0) {
1078 if (fp)
1079 return fprintf(fp, " (calltrace)");
1080 1223
1224 if (branch_count == 0)
1081 return scnprintf(bf, bfsize, " (calltrace)"); 1225 return scnprintf(bf, bfsize, " (calltrace)");
1082 } 1226
1227 cycles = cycles_count / branch_count;
1083 1228
1084 if (iter_count && samples_count) { 1229 if (iter_count && samples_count) {
1085 scnprintf(iter_str, sizeof(iter_str), 1230 if (cycles > 0)
1086 ", iterations:%" PRId64 "", 1231 scnprintf(iter_str, sizeof(iter_str),
1087 iter_count / samples_count); 1232 " iterations:%" PRId64 "",
1088 str = iter_str; 1233 iter_count / samples_count);
1234 else
1235 scnprintf(iter_str, sizeof(iter_str),
1236 "iterations:%" PRId64 "",
1237 iter_count / samples_count);
1238 istr = iter_str;
1239 } else
1240 istr = (char *)null_str;
1241
1242 if (cycles > 0) {
1243 scnprintf(cycle_str, sizeof(cycle_str),
1244 "cycles:%" PRId64 "", cycles);
1245 cstr = cycle_str;
1089 } else 1246 } else
1090 str = (char *)null_str; 1247 cstr = (char *)null_str;
1091 1248
1092 predicted_percent = predicted_count * 100.0 / branch_count; 1249 predicted_percent = predicted_count * 100.0 / branch_count;
1093 cycles = cycles_count / branch_count;
1094 1250
1095 if ((predicted_percent >= 100.0) && (abort_count == 0)) { 1251 if ((predicted_count == branch_count) && (abort_count == 0)) {
1096 if (fp) 1252 if ((cycles > 0) || (istr != (char *)null_str))
1097 return fprintf(fp, " (cycles:%" PRId64 "%s)", 1253 return scnprintf(bf, bfsize, " (%s%s)", cstr, istr);
1098 cycles, str); 1254 else
1255 return scnprintf(bf, bfsize, "%s", (char *)null_str);
1256 }
1099 1257
1100 return scnprintf(bf, bfsize, " (cycles:%" PRId64 "%s)", 1258 if ((predicted_count < branch_count) && (abort_count == 0)) {
1101 cycles, str); 1259 if ((cycles > 0) || (istr != (char *)null_str))
1260 return scnprintf(bf, bfsize,
1261 " (predicted:%.1f%% %s%s)",
1262 predicted_percent, cstr, istr);
1263 else {
1264 return scnprintf(bf, bfsize,
1265 " (predicted:%.1f%%)",
1266 predicted_percent);
1267 }
1102 } 1268 }
1103 1269
1104 if ((predicted_percent < 100.0) && (abort_count == 0)) { 1270 if ((predicted_count == branch_count) && (abort_count > 0)) {
1105 if (fp) 1271 if ((cycles > 0) || (istr != (char *)null_str))
1106 return fprintf(fp, 1272 return scnprintf(bf, bfsize,
1107 " (predicted:%.1f%%, cycles:%" PRId64 "%s)", 1273 " (abort:%" PRId64 " %s%s)",
1108 predicted_percent, cycles, str); 1274 abort_count, cstr, istr);
1275 else
1276 return scnprintf(bf, bfsize,
1277 " (abort:%" PRId64 ")",
1278 abort_count);
1279 }
1109 1280
1281 if ((cycles > 0) || (istr != (char *)null_str))
1110 return scnprintf(bf, bfsize, 1282 return scnprintf(bf, bfsize,
1111 " (predicted:%.1f%%, cycles:%" PRId64 "%s)", 1283 " (predicted:%.1f%% abort:%" PRId64 " %s%s)",
1112 predicted_percent, cycles, str); 1284 predicted_percent, abort_count, cstr, istr);
1113 } 1285
1286 return scnprintf(bf, bfsize,
1287 " (predicted:%.1f%% abort:%" PRId64 ")",
1288 predicted_percent, abort_count);
1289}
1290
1291static int callchain_counts_printf(FILE *fp, char *bf, int bfsize,
1292 u64 branch_count, u64 predicted_count,
1293 u64 abort_count, u64 cycles_count,
1294 u64 iter_count, u64 samples_count)
1295{
1296 char str[128];
1297
1298 counts_str_build(str, sizeof(str), branch_count,
1299 predicted_count, abort_count, cycles_count,
1300 iter_count, samples_count);
1114 1301
1115 if (fp) 1302 if (fp)
1116 return fprintf(fp, 1303 return fprintf(fp, "%s", str);
1117 " (predicted:%.1f%%, abort:%" PRId64 ", cycles:%" PRId64 "%s)",
1118 predicted_percent, abort_count, cycles, str);
1119 1304
1120 return scnprintf(bf, bfsize, 1305 return scnprintf(bf, bfsize, "%s", str);
1121 " (predicted:%.1f%%, abort:%" PRId64 ", cycles:%" PRId64 "%s)",
1122 predicted_percent, abort_count, cycles, str);
1123} 1306}
1124 1307
1125int callchain_list_counts__printf_value(struct callchain_node *node, 1308int callchain_list_counts__printf_value(struct callchain_node *node,
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 4f4b60f1558a..c56c23dbbf72 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -77,7 +77,8 @@ typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_root *,
77 77
78enum chain_key { 78enum chain_key {
79 CCKEY_FUNCTION, 79 CCKEY_FUNCTION,
80 CCKEY_ADDRESS 80 CCKEY_ADDRESS,
81 CCKEY_SRCLINE
81}; 82};
82 83
83enum chain_value { 84enum chain_value {
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index eafbf11442b2..03347748f3fa 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -4,6 +4,7 @@
4#include "evsel.h" 4#include "evsel.h"
5#include "cgroup.h" 5#include "cgroup.h"
6#include "evlist.h" 6#include "evlist.h"
7#include <linux/stringify.h>
7 8
8int nr_cgroups; 9int nr_cgroups;
9 10
@@ -27,8 +28,8 @@ cgroupfs_find_mountpoint(char *buf, size_t maxlen)
27 path_v1[0] = '\0'; 28 path_v1[0] = '\0';
28 path_v2[0] = '\0'; 29 path_v2[0] = '\0';
29 30
30 while (fscanf(fp, "%*s %"STR(PATH_MAX)"s %"STR(PATH_MAX)"s %" 31 while (fscanf(fp, "%*s %"__stringify(PATH_MAX)"s %"__stringify(PATH_MAX)"s %"
31 STR(PATH_MAX)"s %*d %*d\n", 32 __stringify(PATH_MAX)"s %*d %*d\n",
32 mountpoint, type, tokens) == 3) { 33 mountpoint, type, tokens) == 3) {
33 34
34 if (!path_v1[0] && !strcmp(type, "cgroup")) { 35 if (!path_v1[0] && !strcmp(type, "cgroup")) {
@@ -127,19 +128,19 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
127 goto found; 128 goto found;
128 n++; 129 n++;
129 } 130 }
130 if (atomic_read(&cgrp->refcnt) == 0) 131 if (refcount_read(&cgrp->refcnt) == 0)
131 free(cgrp); 132 free(cgrp);
132 133
133 return -1; 134 return -1;
134found: 135found:
135 atomic_inc(&cgrp->refcnt); 136 refcount_inc(&cgrp->refcnt);
136 counter->cgrp = cgrp; 137 counter->cgrp = cgrp;
137 return 0; 138 return 0;
138} 139}
139 140
140void close_cgroup(struct cgroup_sel *cgrp) 141void close_cgroup(struct cgroup_sel *cgrp)
141{ 142{
142 if (cgrp && atomic_dec_and_test(&cgrp->refcnt)) { 143 if (cgrp && refcount_dec_and_test(&cgrp->refcnt)) {
143 close(cgrp->fd); 144 close(cgrp->fd);
144 zfree(&cgrp->name); 145 zfree(&cgrp->name);
145 free(cgrp); 146 free(cgrp);
diff --git a/tools/perf/util/cgroup.h b/tools/perf/util/cgroup.h
index 31f8dcdbd7ef..d91966b97cbd 100644
--- a/tools/perf/util/cgroup.h
+++ b/tools/perf/util/cgroup.h
@@ -1,14 +1,14 @@
1#ifndef __CGROUP_H__ 1#ifndef __CGROUP_H__
2#define __CGROUP_H__ 2#define __CGROUP_H__
3 3
4#include <linux/atomic.h> 4#include <linux/refcount.h>
5 5
6struct option; 6struct option;
7 7
8struct cgroup_sel { 8struct cgroup_sel {
9 char *name; 9 char *name;
10 int fd; 10 int fd;
11 atomic_t refcnt; 11 refcount_t refcnt;
12}; 12};
13 13
14 14
diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index f0dcd0ee0afa..4b4f00df58a8 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -1,3 +1,4 @@
1#include <errno.h>
1#include <sched.h> 2#include <sched.h>
2#include "util.h" 3#include "util.h"
3#include "../perf.h" 4#include "../perf.h"
diff --git a/tools/perf/util/cloexec.h b/tools/perf/util/cloexec.h
index d0d465953d36..94a5a7d829d5 100644
--- a/tools/perf/util/cloexec.h
+++ b/tools/perf/util/cloexec.h
@@ -3,10 +3,4 @@
3 3
4unsigned long perf_event_open_cloexec_flag(void); 4unsigned long perf_event_open_cloexec_flag(void);
5 5
6#ifdef __GLIBC_PREREQ
7#if !__GLIBC_PREREQ(2, 6) && !defined(__UCLIBC__)
8int sched_getcpu(void) __THROW;
9#endif
10#endif
11
12#endif /* __PERF_CLOEXEC_H */ 6#endif /* __PERF_CLOEXEC_H */
diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h
index a93997f16dec..52122bcc3170 100644
--- a/tools/perf/util/color.h
+++ b/tools/perf/util/color.h
@@ -1,6 +1,8 @@
1#ifndef __PERF_COLOR_H 1#ifndef __PERF_COLOR_H
2#define __PERF_COLOR_H 2#define __PERF_COLOR_H
3 3
4#include <stdio.h>
5
4/* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */ 6/* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */
5#define COLOR_MAXLEN 24 7#define COLOR_MAXLEN 24
6 8
diff --git a/tools/perf/util/comm.c b/tools/perf/util/comm.c
index 21b7ff382c3f..7bc981b6bf29 100644
--- a/tools/perf/util/comm.c
+++ b/tools/perf/util/comm.c
@@ -1,13 +1,15 @@
1#include "comm.h" 1#include "comm.h"
2#include "util.h" 2#include "util.h"
3#include <errno.h>
3#include <stdlib.h> 4#include <stdlib.h>
4#include <stdio.h> 5#include <stdio.h>
5#include <linux/atomic.h> 6#include <string.h>
7#include <linux/refcount.h>
6 8
7struct comm_str { 9struct comm_str {
8 char *str; 10 char *str;
9 struct rb_node rb_node; 11 struct rb_node rb_node;
10 atomic_t refcnt; 12 refcount_t refcnt;
11}; 13};
12 14
13/* Should perhaps be moved to struct machine */ 15/* Should perhaps be moved to struct machine */
@@ -16,13 +18,13 @@ static struct rb_root comm_str_root;
16static struct comm_str *comm_str__get(struct comm_str *cs) 18static struct comm_str *comm_str__get(struct comm_str *cs)
17{ 19{
18 if (cs) 20 if (cs)
19 atomic_inc(&cs->refcnt); 21 refcount_inc(&cs->refcnt);
20 return cs; 22 return cs;
21} 23}
22 24
23static void comm_str__put(struct comm_str *cs) 25static void comm_str__put(struct comm_str *cs)
24{ 26{
25 if (cs && atomic_dec_and_test(&cs->refcnt)) { 27 if (cs && refcount_dec_and_test(&cs->refcnt)) {
26 rb_erase(&cs->rb_node, &comm_str_root); 28 rb_erase(&cs->rb_node, &comm_str_root);
27 zfree(&cs->str); 29 zfree(&cs->str);
28 free(cs); 30 free(cs);
@@ -43,7 +45,7 @@ static struct comm_str *comm_str__alloc(const char *str)
43 return NULL; 45 return NULL;
44 } 46 }
45 47
46 atomic_set(&cs->refcnt, 0); 48 refcount_set(&cs->refcnt, 1);
47 49
48 return cs; 50 return cs;
49} 51}
@@ -61,7 +63,7 @@ static struct comm_str *comm_str__findnew(const char *str, struct rb_root *root)
61 63
62 cmp = strcmp(str, iter->str); 64 cmp = strcmp(str, iter->str);
63 if (!cmp) 65 if (!cmp)
64 return iter; 66 return comm_str__get(iter);
65 67
66 if (cmp < 0) 68 if (cmp < 0)
67 p = &(*p)->rb_left; 69 p = &(*p)->rb_left;
@@ -95,8 +97,6 @@ struct comm *comm__new(const char *str, u64 timestamp, bool exec)
95 return NULL; 97 return NULL;
96 } 98 }
97 99
98 comm_str__get(comm->comm_str);
99
100 return comm; 100 return comm;
101} 101}
102 102
@@ -108,7 +108,6 @@ int comm__override(struct comm *comm, const char *str, u64 timestamp, bool exec)
108 if (!new) 108 if (!new)
109 return -ENOMEM; 109 return -ENOMEM;
110 110
111 comm_str__get(new);
112 comm_str__put(old); 111 comm_str__put(old);
113 comm->comm_str = new; 112 comm->comm_str = new;
114 comm->start = timestamp; 113 comm->start = timestamp;
diff --git a/tools/perf/util/compress.h b/tools/perf/util/compress.h
new file mode 100644
index 000000000000..67fd1bb7c2b7
--- /dev/null
+++ b/tools/perf/util/compress.h
@@ -0,0 +1,12 @@
1#ifndef PERF_COMPRESS_H
2#define PERF_COMPRESS_H
3
4#ifdef HAVE_ZLIB_SUPPORT
5int gzip_decompress_to_file(const char *input, int output_fd);
6#endif
7
8#ifdef HAVE_LZMA_SUPPORT
9int lzma_decompress_to_file(const char *input, int output_fd);
10#endif
11
12#endif /* PERF_COMPRESS_H */
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 0c7d5a4975cd..8d724f0fa5a8 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -8,12 +8,19 @@
8 * Copyright (C) Johannes Schindelin, 2005 8 * Copyright (C) Johannes Schindelin, 2005
9 * 9 *
10 */ 10 */
11#include <errno.h>
12#include <sys/param.h>
11#include "util.h" 13#include "util.h"
12#include "cache.h" 14#include "cache.h"
13#include <subcmd/exec-cmd.h> 15#include <subcmd/exec-cmd.h>
14#include "util/hist.h" /* perf_hist_config */ 16#include "util/hist.h" /* perf_hist_config */
15#include "util/llvm-utils.h" /* perf_llvm_config */ 17#include "util/llvm-utils.h" /* perf_llvm_config */
16#include "config.h" 18#include "config.h"
19#include <sys/types.h>
20#include <sys/stat.h>
21#include <unistd.h>
22
23#include "sane_ctype.h"
17 24
18#define MAXNAME (256) 25#define MAXNAME (256)
19 26
@@ -627,6 +634,8 @@ static int perf_config_set__init(struct perf_config_set *set)
627{ 634{
628 int ret = -1; 635 int ret = -1;
629 const char *home = NULL; 636 const char *home = NULL;
637 char *user_config;
638 struct stat st;
630 639
631 /* Setting $PERF_CONFIG makes perf read _only_ the given config file. */ 640 /* Setting $PERF_CONFIG makes perf read _only_ the given config file. */
632 if (config_exclusive_filename) 641 if (config_exclusive_filename)
@@ -637,35 +646,41 @@ static int perf_config_set__init(struct perf_config_set *set)
637 } 646 }
638 647
639 home = getenv("HOME"); 648 home = getenv("HOME");
640 if (perf_config_global() && home) {
641 char *user_config = strdup(mkpath("%s/.perfconfig", home));
642 struct stat st;
643 649
644 if (user_config == NULL) { 650 /*
645 warning("Not enough memory to process %s/.perfconfig, " 651 * Skip reading user config if:
646 "ignoring it.", home); 652 * - there is no place to read it from (HOME)
647 goto out; 653 * - we are asked not to (PERF_CONFIG_NOGLOBAL=1)
648 } 654 */
655 if (!home || !*home || !perf_config_global())
656 return 0;
649 657
650 if (stat(user_config, &st) < 0) { 658 user_config = strdup(mkpath("%s/.perfconfig", home));
651 if (errno == ENOENT) 659 if (user_config == NULL) {
652 ret = 0; 660 warning("Not enough memory to process %s/.perfconfig, "
653 goto out_free; 661 "ignoring it.", home);
654 } 662 goto out;
663 }
655 664
656 ret = 0; 665 if (stat(user_config, &st) < 0) {
666 if (errno == ENOENT)
667 ret = 0;
668 goto out_free;
669 }
657 670
658 if (st.st_uid && (st.st_uid != geteuid())) { 671 ret = 0;
659 warning("File %s not owned by current user or root, "
660 "ignoring it.", user_config);
661 goto out_free;
662 }
663 672
664 if (st.st_size) 673 if (st.st_uid && (st.st_uid != geteuid())) {
665 ret = perf_config_from_file(collect_config, user_config, set); 674 warning("File %s not owned by current user or root, "
666out_free: 675 "ignoring it.", user_config);
667 free(user_config); 676 goto out_free;
668 } 677 }
678
679 if (st.st_size)
680 ret = perf_config_from_file(collect_config, user_config, set);
681
682out_free:
683 free(user_config);
669out: 684out:
670 return ret; 685 return ret;
671} 686}
diff --git a/tools/perf/util/counts.c b/tools/perf/util/counts.c
index e3fde313deb2..c4af82ab7808 100644
--- a/tools/perf/util/counts.c
+++ b/tools/perf/util/counts.c
@@ -1,6 +1,8 @@
1#include <errno.h>
1#include <stdlib.h> 2#include <stdlib.h>
2#include "evsel.h" 3#include "evsel.h"
3#include "counts.h" 4#include "counts.h"
5#include "util.h"
4 6
5struct perf_counts *perf_counts__new(int ncpus, int nthreads) 7struct perf_counts *perf_counts__new(int ncpus, int nthreads)
6{ 8{
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 8c7504939113..37b3bb79ee08 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -3,11 +3,14 @@
3#include "../perf.h" 3#include "../perf.h"
4#include "cpumap.h" 4#include "cpumap.h"
5#include <assert.h> 5#include <assert.h>
6#include <dirent.h>
6#include <stdio.h> 7#include <stdio.h>
7#include <stdlib.h> 8#include <stdlib.h>
8#include <linux/bitmap.h> 9#include <linux/bitmap.h>
9#include "asm/bug.h" 10#include "asm/bug.h"
10 11
12#include "sane_ctype.h"
13
11static int max_cpu_num; 14static int max_cpu_num;
12static int max_present_cpu_num; 15static int max_present_cpu_num;
13static int max_node_num; 16static int max_node_num;
@@ -29,7 +32,7 @@ static struct cpu_map *cpu_map__default_new(void)
29 cpus->map[i] = i; 32 cpus->map[i] = i;
30 33
31 cpus->nr = nr_cpus; 34 cpus->nr = nr_cpus;
32 atomic_set(&cpus->refcnt, 1); 35 refcount_set(&cpus->refcnt, 1);
33 } 36 }
34 37
35 return cpus; 38 return cpus;
@@ -43,7 +46,7 @@ static struct cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus)
43 if (cpus != NULL) { 46 if (cpus != NULL) {
44 cpus->nr = nr_cpus; 47 cpus->nr = nr_cpus;
45 memcpy(cpus->map, tmp_cpus, payload_size); 48 memcpy(cpus->map, tmp_cpus, payload_size);
46 atomic_set(&cpus->refcnt, 1); 49 refcount_set(&cpus->refcnt, 1);
47 } 50 }
48 51
49 return cpus; 52 return cpus;
@@ -252,7 +255,7 @@ struct cpu_map *cpu_map__dummy_new(void)
252 if (cpus != NULL) { 255 if (cpus != NULL) {
253 cpus->nr = 1; 256 cpus->nr = 1;
254 cpus->map[0] = -1; 257 cpus->map[0] = -1;
255 atomic_set(&cpus->refcnt, 1); 258 refcount_set(&cpus->refcnt, 1);
256 } 259 }
257 260
258 return cpus; 261 return cpus;
@@ -269,7 +272,7 @@ struct cpu_map *cpu_map__empty_new(int nr)
269 for (i = 0; i < nr; i++) 272 for (i = 0; i < nr; i++)
270 cpus->map[i] = -1; 273 cpus->map[i] = -1;
271 274
272 atomic_set(&cpus->refcnt, 1); 275 refcount_set(&cpus->refcnt, 1);
273 } 276 }
274 277
275 return cpus; 278 return cpus;
@@ -278,7 +281,7 @@ struct cpu_map *cpu_map__empty_new(int nr)
278static void cpu_map__delete(struct cpu_map *map) 281static void cpu_map__delete(struct cpu_map *map)
279{ 282{
280 if (map) { 283 if (map) {
281 WARN_ONCE(atomic_read(&map->refcnt) != 0, 284 WARN_ONCE(refcount_read(&map->refcnt) != 0,
282 "cpu_map refcnt unbalanced\n"); 285 "cpu_map refcnt unbalanced\n");
283 free(map); 286 free(map);
284 } 287 }
@@ -287,13 +290,13 @@ static void cpu_map__delete(struct cpu_map *map)
287struct cpu_map *cpu_map__get(struct cpu_map *map) 290struct cpu_map *cpu_map__get(struct cpu_map *map)
288{ 291{
289 if (map) 292 if (map)
290 atomic_inc(&map->refcnt); 293 refcount_inc(&map->refcnt);
291 return map; 294 return map;
292} 295}
293 296
294void cpu_map__put(struct cpu_map *map) 297void cpu_map__put(struct cpu_map *map)
295{ 298{
296 if (map && atomic_dec_and_test(&map->refcnt)) 299 if (map && refcount_dec_and_test(&map->refcnt))
297 cpu_map__delete(map); 300 cpu_map__delete(map);
298} 301}
299 302
@@ -357,7 +360,7 @@ int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
357 /* ensure we process id in increasing order */ 360 /* ensure we process id in increasing order */
358 qsort(c->map, c->nr, sizeof(int), cmp_ids); 361 qsort(c->map, c->nr, sizeof(int), cmp_ids);
359 362
360 atomic_set(&c->refcnt, 1); 363 refcount_set(&c->refcnt, 1);
361 *res = c; 364 *res = c;
362 return 0; 365 return 0;
363} 366}
@@ -673,3 +676,49 @@ size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size)
673 pr_debug("cpumask list: %s\n", buf); 676 pr_debug("cpumask list: %s\n", buf);
674 return ret; 677 return ret;
675} 678}
679
680static char hex_char(unsigned char val)
681{
682 if (val < 10)
683 return val + '0';
684 if (val < 16)
685 return val - 10 + 'a';
686 return '?';
687}
688
689size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size)
690{
691 int i, cpu;
692 char *ptr = buf;
693 unsigned char *bitmap;
694 int last_cpu = cpu_map__cpu(map, map->nr - 1);
695
696 bitmap = zalloc((last_cpu + 7) / 8);
697 if (bitmap == NULL) {
698 buf[0] = '\0';
699 return 0;
700 }
701
702 for (i = 0; i < map->nr; i++) {
703 cpu = cpu_map__cpu(map, i);
704 bitmap[cpu / 8] |= 1 << (cpu % 8);
705 }
706
707 for (cpu = last_cpu / 4 * 4; cpu >= 0; cpu -= 4) {
708 unsigned char bits = bitmap[cpu / 8];
709
710 if (cpu % 8)
711 bits >>= 4;
712 else
713 bits &= 0xf;
714
715 *ptr++ = hex_char(bits);
716 if ((cpu % 32) == 0 && cpu > 0)
717 *ptr++ = ',';
718 }
719 *ptr = '\0';
720 free(bitmap);
721
722 buf[size - 1] = '\0';
723 return ptr - buf;
724}
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 1a0549af8f5c..6b8bff87481d 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -3,13 +3,13 @@
3 3
4#include <stdio.h> 4#include <stdio.h>
5#include <stdbool.h> 5#include <stdbool.h>
6#include <linux/atomic.h> 6#include <linux/refcount.h>
7 7
8#include "perf.h" 8#include "perf.h"
9#include "util/debug.h" 9#include "util/debug.h"
10 10
11struct cpu_map { 11struct cpu_map {
12 atomic_t refcnt; 12 refcount_t refcnt;
13 int nr; 13 int nr;
14 int map[]; 14 int map[];
15}; 15};
@@ -20,6 +20,7 @@ struct cpu_map *cpu_map__dummy_new(void);
20struct cpu_map *cpu_map__new_data(struct cpu_map_data *data); 20struct cpu_map *cpu_map__new_data(struct cpu_map_data *data);
21struct cpu_map *cpu_map__read(FILE *file); 21struct cpu_map *cpu_map__read(FILE *file);
22size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size); 22size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size);
23size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size);
23size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); 24size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
24int cpu_map__get_socket_id(int cpu); 25int cpu_map__get_socket_id(int cpu);
25int cpu_map__get_socket(struct cpu_map *map, int idx, void *data); 26int cpu_map__get_socket(struct cpu_map *map, int idx, void *data);
diff --git a/tools/perf/util/ctype.c b/tools/perf/util/ctype.c
index d4a5a21c2a7e..4b261c2ec0f1 100644
--- a/tools/perf/util/ctype.c
+++ b/tools/perf/util/ctype.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * No surprises, and works with signed and unsigned chars. 4 * No surprises, and works with signed and unsigned chars.
5 */ 5 */
6#include "util.h" 6#include "sane_ctype.h"
7 7
8enum { 8enum {
9 S = GIT_SPACE, 9 S = GIT_SPACE,
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index 4e6cbc99f08e..89d50318833d 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -7,7 +7,10 @@
7 * Released under the GPL v2. (and only v2, not any later version) 7 * Released under the GPL v2. (and only v2, not any later version)
8 */ 8 */
9 9
10#include <errno.h>
11#include <inttypes.h>
10#include <linux/compiler.h> 12#include <linux/compiler.h>
13#include <linux/kernel.h>
11#include <babeltrace/ctf-writer/writer.h> 14#include <babeltrace/ctf-writer/writer.h>
12#include <babeltrace/ctf-writer/clock.h> 15#include <babeltrace/ctf-writer/clock.h>
13#include <babeltrace/ctf-writer/stream.h> 16#include <babeltrace/ctf-writer/stream.h>
@@ -27,6 +30,7 @@
27#include "evsel.h" 30#include "evsel.h"
28#include "machine.h" 31#include "machine.h"
29#include "config.h" 32#include "config.h"
33#include "sane_ctype.h"
30 34
31#define pr_N(n, fmt, ...) \ 35#define pr_N(n, fmt, ...) \
32 eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__) 36 eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)
@@ -1468,6 +1472,7 @@ int bt_convert__perf2ctf(const char *input, const char *path,
1468 .lost = perf_event__process_lost, 1472 .lost = perf_event__process_lost,
1469 .tracing_data = perf_event__process_tracing_data, 1473 .tracing_data = perf_event__process_tracing_data,
1470 .build_id = perf_event__process_build_id, 1474 .build_id = perf_event__process_build_id,
1475 .namespaces = perf_event__process_namespaces,
1471 .ordered_events = true, 1476 .ordered_events = true,
1472 .ordering_requires_timestamps = true, 1477 .ordering_requires_timestamps = true,
1473 }, 1478 },
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 60bfc9ca1e22..e84bbc8ec058 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -2,6 +2,7 @@
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <sys/stat.h> 4#include <sys/stat.h>
5#include <errno.h>
5#include <unistd.h> 6#include <unistd.h>
6#include <string.h> 7#include <string.h>
7 8
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 03eb81f30d0d..a5b3777ffee6 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -2,19 +2,26 @@
2 2
3#include "../perf.h" 3#include "../perf.h"
4 4
5#include <inttypes.h>
5#include <string.h> 6#include <string.h>
6#include <stdarg.h> 7#include <stdarg.h>
7#include <stdio.h> 8#include <stdio.h>
9#include <sys/wait.h>
8#include <api/debug.h> 10#include <api/debug.h>
9#include <linux/time64.h> 11#include <linux/time64.h>
10 12#ifdef HAVE_BACKTRACE_SUPPORT
13#include <execinfo.h>
14#endif
11#include "cache.h" 15#include "cache.h"
12#include "color.h" 16#include "color.h"
13#include "event.h" 17#include "event.h"
14#include "debug.h" 18#include "debug.h"
19#include "print_binary.h"
15#include "util.h" 20#include "util.h"
16#include "target.h" 21#include "target.h"
17 22
23#include "sane_ctype.h"
24
18int verbose; 25int verbose;
19bool dump_trace = false, quiet = false; 26bool dump_trace = false, quiet = false;
20int debug_ordered_events; 27int debug_ordered_events;
@@ -244,3 +251,31 @@ void perf_debug_setup(void)
244{ 251{
245 libapi_set_print(pr_warning_wrapper, pr_warning_wrapper, pr_debug_wrapper); 252 libapi_set_print(pr_warning_wrapper, pr_warning_wrapper, pr_debug_wrapper);
246} 253}
254
255/* Obtain a backtrace and print it to stdout. */
256#ifdef HAVE_BACKTRACE_SUPPORT
257void dump_stack(void)
258{
259 void *array[16];
260 size_t size = backtrace(array, ARRAY_SIZE(array));
261 char **strings = backtrace_symbols(array, size);
262 size_t i;
263
264 printf("Obtained %zd stack frames.\n", size);
265
266 for (i = 0; i < size; i++)
267 printf("%s\n", strings[i]);
268
269 free(strings);
270}
271#else
272void dump_stack(void) {}
273#endif
274
275void sighandler_dump_stack(int sig)
276{
277 psignal(sig, "perf");
278 dump_stack();
279 signal(sig, SIG_DFL);
280 raise(sig);
281}
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index 98832f5531d3..8a23ea1a71c7 100644
--- a/tools/perf/util/debug.h
+++ b/tools/perf/util/debug.h
@@ -56,4 +56,7 @@ int perf_debug_option(const char *str);
56void perf_debug_setup(void); 56void perf_debug_setup(void);
57int perf_quiet_option(void); 57int perf_quiet_option(void);
58 58
59void dump_stack(void);
60void sighandler_dump_stack(int sig);
61
59#endif /* __PERF_DEBUG_H */ 62#endif /* __PERF_DEBUG_H */
diff --git a/tools/perf/util/demangle-java.c b/tools/perf/util/demangle-java.c
index 3e6062ab2cdd..cb66d334f532 100644
--- a/tools/perf/util/demangle-java.c
+++ b/tools/perf/util/demangle-java.c
@@ -7,6 +7,8 @@
7 7
8#include "demangle-java.h" 8#include "demangle-java.h"
9 9
10#include "sane_ctype.h"
11
10enum { 12enum {
11 MODE_PREFIX = 0, 13 MODE_PREFIX = 0,
12 MODE_CLASS = 1, 14 MODE_CLASS = 1,
diff --git a/tools/perf/util/drv_configs.c b/tools/perf/util/drv_configs.c
index 1647f285c629..eec754243f4d 100644
--- a/tools/perf/util/drv_configs.c
+++ b/tools/perf/util/drv_configs.c
@@ -17,6 +17,7 @@
17#include "evlist.h" 17#include "evlist.h"
18#include "evsel.h" 18#include "evsel.h"
19#include "pmu.h" 19#include "pmu.h"
20#include <errno.h>
20 21
21static int 22static int
22perf_evsel__apply_drv_configs(struct perf_evsel *evsel, 23perf_evsel__apply_drv_configs(struct perf_evsel *evsel,
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index d38b62a700ca..a96a99d2369f 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -1,12 +1,20 @@
1#include <asm/bug.h> 1#include <asm/bug.h>
2#include <linux/kernel.h>
2#include <sys/time.h> 3#include <sys/time.h>
3#include <sys/resource.h> 4#include <sys/resource.h>
5#include <sys/types.h>
6#include <sys/stat.h>
7#include <unistd.h>
8#include <errno.h>
9#include "compress.h"
10#include "path.h"
4#include "symbol.h" 11#include "symbol.h"
5#include "dso.h" 12#include "dso.h"
6#include "machine.h" 13#include "machine.h"
7#include "auxtrace.h" 14#include "auxtrace.h"
8#include "util.h" 15#include "util.h"
9#include "debug.h" 16#include "debug.h"
17#include "string2.h"
10#include "vdso.h" 18#include "vdso.h"
11 19
12static const char * const debuglink_paths[] = { 20static const char * const debuglink_paths[] = {
@@ -1109,7 +1117,7 @@ struct dso *dso__new(const char *name)
1109 INIT_LIST_HEAD(&dso->node); 1117 INIT_LIST_HEAD(&dso->node);
1110 INIT_LIST_HEAD(&dso->data.open_entry); 1118 INIT_LIST_HEAD(&dso->data.open_entry);
1111 pthread_mutex_init(&dso->lock, NULL); 1119 pthread_mutex_init(&dso->lock, NULL);
1112 atomic_set(&dso->refcnt, 1); 1120 refcount_set(&dso->refcnt, 1);
1113 } 1121 }
1114 1122
1115 return dso; 1123 return dso;
@@ -1147,13 +1155,13 @@ void dso__delete(struct dso *dso)
1147struct dso *dso__get(struct dso *dso) 1155struct dso *dso__get(struct dso *dso)
1148{ 1156{
1149 if (dso) 1157 if (dso)
1150 atomic_inc(&dso->refcnt); 1158 refcount_inc(&dso->refcnt);
1151 return dso; 1159 return dso;
1152} 1160}
1153 1161
1154void dso__put(struct dso *dso) 1162void dso__put(struct dso *dso)
1155{ 1163{
1156 if (dso && atomic_dec_and_test(&dso->refcnt)) 1164 if (dso && refcount_dec_and_test(&dso->refcnt))
1157 dso__delete(dso); 1165 dso__delete(dso);
1158} 1166}
1159 1167
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index ecc4bbd3f82e..12350b171727 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -1,7 +1,7 @@
1#ifndef __PERF_DSO 1#ifndef __PERF_DSO
2#define __PERF_DSO 2#define __PERF_DSO
3 3
4#include <linux/atomic.h> 4#include <linux/refcount.h>
5#include <linux/types.h> 5#include <linux/types.h>
6#include <linux/rbtree.h> 6#include <linux/rbtree.h>
7#include <sys/types.h> 7#include <sys/types.h>
@@ -187,7 +187,7 @@ struct dso {
187 void *priv; 187 void *priv;
188 u64 db_id; 188 u64 db_id;
189 }; 189 };
190 atomic_t refcnt; 190 refcount_t refcnt;
191 char name[0]; 191 char name[0];
192}; 192};
193 193
diff --git a/tools/perf/util/dump-insn.c b/tools/perf/util/dump-insn.c
new file mode 100644
index 000000000000..ffbdb19f05d0
--- /dev/null
+++ b/tools/perf/util/dump-insn.c
@@ -0,0 +1,14 @@
1#include <linux/compiler.h>
2#include "dump-insn.h"
3
4/* Fallback code */
5
6__weak
7const char *dump_insn(struct perf_insn *x __maybe_unused,
8 u64 ip __maybe_unused, u8 *inbuf __maybe_unused,
9 int inlen __maybe_unused, int *lenp)
10{
11 if (lenp)
12 *lenp = 0;
13 return "?";
14}
diff --git a/tools/perf/util/dump-insn.h b/tools/perf/util/dump-insn.h
new file mode 100644
index 000000000000..90fb115981cf
--- /dev/null
+++ b/tools/perf/util/dump-insn.h
@@ -0,0 +1,22 @@
1#ifndef __PERF_DUMP_INSN_H
2#define __PERF_DUMP_INSN_H 1
3
4#define MAXINSN 15
5
6#include <linux/types.h>
7
8struct thread;
9
10struct perf_insn {
11 /* Initialized by callers: */
12 struct thread *thread;
13 u8 cpumode;
14 bool is64bit;
15 int cpu;
16 /* Temporary */
17 char out[256];
18};
19
20const char *dump_insn(struct perf_insn *x, u64 ip,
21 u8 *inbuf, int inlen, int *lenp);
22#endif
diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index 41e068e94349..f5acda13dcfa 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -17,10 +17,13 @@
17 * 17 *
18 */ 18 */
19 19
20#include <errno.h>
21#include <inttypes.h>
20#include <stdbool.h> 22#include <stdbool.h>
21#include "util.h" 23#include "util.h"
22#include "debug.h" 24#include "debug.h"
23#include "dwarf-aux.h" 25#include "dwarf-aux.h"
26#include "string2.h"
24 27
25/** 28/**
26 * cu_find_realpath - Find the realpath of the target file 29 * cu_find_realpath - Find the realpath of the target file
diff --git a/tools/perf/util/dwarf-regs.c b/tools/perf/util/dwarf-regs.c
index 62bc4a86a970..c708395b3cb6 100644
--- a/tools/perf/util/dwarf-regs.c
+++ b/tools/perf/util/dwarf-regs.c
@@ -8,6 +8,7 @@
8#include <debug.h> 8#include <debug.h>
9#include <dwarf-regs.h> 9#include <dwarf-regs.h>
10#include <elf.h> 10#include <elf.h>
11#include <linux/kernel.h>
11 12
12#ifndef EM_AARCH64 13#ifndef EM_AARCH64
13#define EM_AARCH64 183 /* ARM 64 bit */ 14#define EM_AARCH64 183 /* ARM 64 bit */
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 075fc77286bf..9e21538c42ae 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -1,6 +1,7 @@
1#include "cpumap.h" 1#include "cpumap.h"
2#include "env.h" 2#include "env.h"
3#include "util.h" 3#include "util.h"
4#include <errno.h>
4 5
5struct perf_env perf_env; 6struct perf_env perf_env;
6 7
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 4ea7ce72ed9c..142835c0ca0a 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1,15 +1,23 @@
1#include <dirent.h>
2#include <errno.h>
3#include <inttypes.h>
4#include <linux/kernel.h>
1#include <linux/types.h> 5#include <linux/types.h>
2#include <linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */ 6#include <sys/types.h>
7#include <sys/stat.h>
8#include <unistd.h>
9#include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */
3#include <api/fs/fs.h> 10#include <api/fs/fs.h>
4#include "event.h" 11#include "event.h"
5#include "debug.h" 12#include "debug.h"
6#include "hist.h" 13#include "hist.h"
7#include "machine.h" 14#include "machine.h"
8#include "sort.h" 15#include "sort.h"
9#include "string.h" 16#include "string2.h"
10#include "strlist.h" 17#include "strlist.h"
11#include "thread.h" 18#include "thread.h"
12#include "thread_map.h" 19#include "thread_map.h"
20#include "sane_ctype.h"
13#include "symbol/kallsyms.h" 21#include "symbol/kallsyms.h"
14#include "asm/bug.h" 22#include "asm/bug.h"
15#include "stat.h" 23#include "stat.h"
@@ -31,6 +39,7 @@ static const char *perf_event__names[] = {
31 [PERF_RECORD_LOST_SAMPLES] = "LOST_SAMPLES", 39 [PERF_RECORD_LOST_SAMPLES] = "LOST_SAMPLES",
32 [PERF_RECORD_SWITCH] = "SWITCH", 40 [PERF_RECORD_SWITCH] = "SWITCH",
33 [PERF_RECORD_SWITCH_CPU_WIDE] = "SWITCH_CPU_WIDE", 41 [PERF_RECORD_SWITCH_CPU_WIDE] = "SWITCH_CPU_WIDE",
42 [PERF_RECORD_NAMESPACES] = "NAMESPACES",
34 [PERF_RECORD_HEADER_ATTR] = "ATTR", 43 [PERF_RECORD_HEADER_ATTR] = "ATTR",
35 [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE", 44 [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE",
36 [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA", 45 [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA",
@@ -49,6 +58,16 @@ static const char *perf_event__names[] = {
49 [PERF_RECORD_TIME_CONV] = "TIME_CONV", 58 [PERF_RECORD_TIME_CONV] = "TIME_CONV",
50}; 59};
51 60
61static const char *perf_ns__names[] = {
62 [NET_NS_INDEX] = "net",
63 [UTS_NS_INDEX] = "uts",
64 [IPC_NS_INDEX] = "ipc",
65 [PID_NS_INDEX] = "pid",
66 [USER_NS_INDEX] = "user",
67 [MNT_NS_INDEX] = "mnt",
68 [CGROUP_NS_INDEX] = "cgroup",
69};
70
52const char *perf_event__name(unsigned int id) 71const char *perf_event__name(unsigned int id)
53{ 72{
54 if (id >= ARRAY_SIZE(perf_event__names)) 73 if (id >= ARRAY_SIZE(perf_event__names))
@@ -58,6 +77,13 @@ const char *perf_event__name(unsigned int id)
58 return perf_event__names[id]; 77 return perf_event__names[id];
59} 78}
60 79
80static const char *perf_ns__name(unsigned int id)
81{
82 if (id >= ARRAY_SIZE(perf_ns__names))
83 return "UNKNOWN";
84 return perf_ns__names[id];
85}
86
61static int perf_tool__process_synth_event(struct perf_tool *tool, 87static int perf_tool__process_synth_event(struct perf_tool *tool,
62 union perf_event *event, 88 union perf_event *event,
63 struct machine *machine, 89 struct machine *machine,
@@ -88,7 +114,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
88 int fd; 114 int fd;
89 size_t size = 0; 115 size_t size = 0;
90 ssize_t n; 116 ssize_t n;
91 char *nl, *name, *tgids, *ppids; 117 char *name, *tgids, *ppids;
92 118
93 *tgid = -1; 119 *tgid = -1;
94 *ppid = -1; 120 *ppid = -1;
@@ -115,10 +141,10 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
115 ppids = strstr(bf, "PPid:"); 141 ppids = strstr(bf, "PPid:");
116 142
117 if (name) { 143 if (name) {
118 name += 5; /* strlen("Name:") */ 144 char *nl;
119 145
120 while (*name && isspace(*name)) 146 name += 5; /* strlen("Name:") */
121 ++name; 147 name = ltrim(name);
122 148
123 nl = strchr(name, '\n'); 149 nl = strchr(name, '\n');
124 if (nl) 150 if (nl)
@@ -203,6 +229,58 @@ pid_t perf_event__synthesize_comm(struct perf_tool *tool,
203 return tgid; 229 return tgid;
204} 230}
205 231
232static void perf_event__get_ns_link_info(pid_t pid, const char *ns,
233 struct perf_ns_link_info *ns_link_info)
234{
235 struct stat64 st;
236 char proc_ns[128];
237
238 sprintf(proc_ns, "/proc/%u/ns/%s", pid, ns);
239 if (stat64(proc_ns, &st) == 0) {
240 ns_link_info->dev = st.st_dev;
241 ns_link_info->ino = st.st_ino;
242 }
243}
244
245int perf_event__synthesize_namespaces(struct perf_tool *tool,
246 union perf_event *event,
247 pid_t pid, pid_t tgid,
248 perf_event__handler_t process,
249 struct machine *machine)
250{
251 u32 idx;
252 struct perf_ns_link_info *ns_link_info;
253
254 if (!tool || !tool->namespace_events)
255 return 0;
256
257 memset(&event->namespaces, 0, (sizeof(event->namespaces) +
258 (NR_NAMESPACES * sizeof(struct perf_ns_link_info)) +
259 machine->id_hdr_size));
260
261 event->namespaces.pid = tgid;
262 event->namespaces.tid = pid;
263
264 event->namespaces.nr_namespaces = NR_NAMESPACES;
265
266 ns_link_info = event->namespaces.link_info;
267
268 for (idx = 0; idx < event->namespaces.nr_namespaces; idx++)
269 perf_event__get_ns_link_info(pid, perf_ns__name(idx),
270 &ns_link_info[idx]);
271
272 event->namespaces.header.type = PERF_RECORD_NAMESPACES;
273
274 event->namespaces.header.size = (sizeof(event->namespaces) +
275 (NR_NAMESPACES * sizeof(struct perf_ns_link_info)) +
276 machine->id_hdr_size);
277
278 if (perf_tool__process_synth_event(tool, event, machine, process) != 0)
279 return -1;
280
281 return 0;
282}
283
206static int perf_event__synthesize_fork(struct perf_tool *tool, 284static int perf_event__synthesize_fork(struct perf_tool *tool,
207 union perf_event *event, 285 union perf_event *event,
208 pid_t pid, pid_t tgid, pid_t ppid, 286 pid_t pid, pid_t tgid, pid_t ppid,
@@ -255,8 +333,8 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
255 if (machine__is_default_guest(machine)) 333 if (machine__is_default_guest(machine))
256 return 0; 334 return 0;
257 335
258 snprintf(filename, sizeof(filename), "%s/proc/%d/maps", 336 snprintf(filename, sizeof(filename), "%s/proc/%d/task/%d/maps",
259 machine->root_dir, pid); 337 machine->root_dir, pid, pid);
260 338
261 fp = fopen(filename, "r"); 339 fp = fopen(filename, "r");
262 if (fp == NULL) { 340 if (fp == NULL) {
@@ -434,8 +512,9 @@ int perf_event__synthesize_modules(struct perf_tool *tool,
434static int __event__synthesize_thread(union perf_event *comm_event, 512static int __event__synthesize_thread(union perf_event *comm_event,
435 union perf_event *mmap_event, 513 union perf_event *mmap_event,
436 union perf_event *fork_event, 514 union perf_event *fork_event,
515 union perf_event *namespaces_event,
437 pid_t pid, int full, 516 pid_t pid, int full,
438 perf_event__handler_t process, 517 perf_event__handler_t process,
439 struct perf_tool *tool, 518 struct perf_tool *tool,
440 struct machine *machine, 519 struct machine *machine,
441 bool mmap_data, 520 bool mmap_data,
@@ -455,6 +534,11 @@ static int __event__synthesize_thread(union perf_event *comm_event,
455 if (tgid == -1) 534 if (tgid == -1)
456 return -1; 535 return -1;
457 536
537 if (perf_event__synthesize_namespaces(tool, namespaces_event, pid,
538 tgid, process, machine) < 0)
539 return -1;
540
541
458 return perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid, 542 return perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
459 process, machine, mmap_data, 543 process, machine, mmap_data,
460 proc_map_timeout); 544 proc_map_timeout);
@@ -488,6 +572,11 @@ static int __event__synthesize_thread(union perf_event *comm_event,
488 if (perf_event__synthesize_fork(tool, fork_event, _pid, tgid, 572 if (perf_event__synthesize_fork(tool, fork_event, _pid, tgid,
489 ppid, process, machine) < 0) 573 ppid, process, machine) < 0)
490 break; 574 break;
575
576 if (perf_event__synthesize_namespaces(tool, namespaces_event, _pid,
577 tgid, process, machine) < 0)
578 break;
579
491 /* 580 /*
492 * Send the prepared comm event 581 * Send the prepared comm event
493 */ 582 */
@@ -516,6 +605,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
516 unsigned int proc_map_timeout) 605 unsigned int proc_map_timeout)
517{ 606{
518 union perf_event *comm_event, *mmap_event, *fork_event; 607 union perf_event *comm_event, *mmap_event, *fork_event;
608 union perf_event *namespaces_event;
519 int err = -1, thread, j; 609 int err = -1, thread, j;
520 610
521 comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size); 611 comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
@@ -530,10 +620,16 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
530 if (fork_event == NULL) 620 if (fork_event == NULL)
531 goto out_free_mmap; 621 goto out_free_mmap;
532 622
623 namespaces_event = malloc(sizeof(namespaces_event->namespaces) +
624 (NR_NAMESPACES * sizeof(struct perf_ns_link_info)) +
625 machine->id_hdr_size);
626 if (namespaces_event == NULL)
627 goto out_free_fork;
628
533 err = 0; 629 err = 0;
534 for (thread = 0; thread < threads->nr; ++thread) { 630 for (thread = 0; thread < threads->nr; ++thread) {
535 if (__event__synthesize_thread(comm_event, mmap_event, 631 if (__event__synthesize_thread(comm_event, mmap_event,
536 fork_event, 632 fork_event, namespaces_event,
537 thread_map__pid(threads, thread), 0, 633 thread_map__pid(threads, thread), 0,
538 process, tool, machine, 634 process, tool, machine,
539 mmap_data, proc_map_timeout)) { 635 mmap_data, proc_map_timeout)) {
@@ -559,7 +655,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
559 /* if not, generate events for it */ 655 /* if not, generate events for it */
560 if (need_leader && 656 if (need_leader &&
561 __event__synthesize_thread(comm_event, mmap_event, 657 __event__synthesize_thread(comm_event, mmap_event,
562 fork_event, 658 fork_event, namespaces_event,
563 comm_event->comm.pid, 0, 659 comm_event->comm.pid, 0,
564 process, tool, machine, 660 process, tool, machine,
565 mmap_data, proc_map_timeout)) { 661 mmap_data, proc_map_timeout)) {
@@ -568,6 +664,8 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
568 } 664 }
569 } 665 }
570 } 666 }
667 free(namespaces_event);
668out_free_fork:
571 free(fork_event); 669 free(fork_event);
572out_free_mmap: 670out_free_mmap:
573 free(mmap_event); 671 free(mmap_event);
@@ -587,6 +685,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
587 char proc_path[PATH_MAX]; 685 char proc_path[PATH_MAX];
588 struct dirent *dirent; 686 struct dirent *dirent;
589 union perf_event *comm_event, *mmap_event, *fork_event; 687 union perf_event *comm_event, *mmap_event, *fork_event;
688 union perf_event *namespaces_event;
590 int err = -1; 689 int err = -1;
591 690
592 if (machine__is_default_guest(machine)) 691 if (machine__is_default_guest(machine))
@@ -604,11 +703,17 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
604 if (fork_event == NULL) 703 if (fork_event == NULL)
605 goto out_free_mmap; 704 goto out_free_mmap;
606 705
706 namespaces_event = malloc(sizeof(namespaces_event->namespaces) +
707 (NR_NAMESPACES * sizeof(struct perf_ns_link_info)) +
708 machine->id_hdr_size);
709 if (namespaces_event == NULL)
710 goto out_free_fork;
711
607 snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir); 712 snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir);
608 proc = opendir(proc_path); 713 proc = opendir(proc_path);
609 714
610 if (proc == NULL) 715 if (proc == NULL)
611 goto out_free_fork; 716 goto out_free_namespaces;
612 717
613 while ((dirent = readdir(proc)) != NULL) { 718 while ((dirent = readdir(proc)) != NULL) {
614 char *end; 719 char *end;
@@ -620,13 +725,16 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
620 * We may race with exiting thread, so don't stop just because 725 * We may race with exiting thread, so don't stop just because
621 * one thread couldn't be synthesized. 726 * one thread couldn't be synthesized.
622 */ 727 */
623 __event__synthesize_thread(comm_event, mmap_event, fork_event, pid, 728 __event__synthesize_thread(comm_event, mmap_event, fork_event,
624 1, process, tool, machine, mmap_data, 729 namespaces_event, pid, 1, process,
730 tool, machine, mmap_data,
625 proc_map_timeout); 731 proc_map_timeout);
626 } 732 }
627 733
628 err = 0; 734 err = 0;
629 closedir(proc); 735 closedir(proc);
736out_free_namespaces:
737 free(namespaces_event);
630out_free_fork: 738out_free_fork:
631 free(fork_event); 739 free(fork_event);
632out_free_mmap: 740out_free_mmap:
@@ -1008,6 +1116,33 @@ size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp)
1008 return fprintf(fp, "%s: %s:%d/%d\n", s, event->comm.comm, event->comm.pid, event->comm.tid); 1116 return fprintf(fp, "%s: %s:%d/%d\n", s, event->comm.comm, event->comm.pid, event->comm.tid);
1009} 1117}
1010 1118
1119size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp)
1120{
1121 size_t ret = 0;
1122 struct perf_ns_link_info *ns_link_info;
1123 u32 nr_namespaces, idx;
1124
1125 ns_link_info = event->namespaces.link_info;
1126 nr_namespaces = event->namespaces.nr_namespaces;
1127
1128 ret += fprintf(fp, " %d/%d - nr_namespaces: %u\n\t\t[",
1129 event->namespaces.pid,
1130 event->namespaces.tid,
1131 nr_namespaces);
1132
1133 for (idx = 0; idx < nr_namespaces; idx++) {
1134 if (idx && (idx % 4 == 0))
1135 ret += fprintf(fp, "\n\t\t ");
1136
1137 ret += fprintf(fp, "%u/%s: %" PRIu64 "/%#" PRIx64 "%s", idx,
1138 perf_ns__name(idx), (u64)ns_link_info[idx].dev,
1139 (u64)ns_link_info[idx].ino,
1140 ((idx + 1) != nr_namespaces) ? ", " : "]\n");
1141 }
1142
1143 return ret;
1144}
1145
1011int perf_event__process_comm(struct perf_tool *tool __maybe_unused, 1146int perf_event__process_comm(struct perf_tool *tool __maybe_unused,
1012 union perf_event *event, 1147 union perf_event *event,
1013 struct perf_sample *sample, 1148 struct perf_sample *sample,
@@ -1016,6 +1151,14 @@ int perf_event__process_comm(struct perf_tool *tool __maybe_unused,
1016 return machine__process_comm_event(machine, event, sample); 1151 return machine__process_comm_event(machine, event, sample);
1017} 1152}
1018 1153
1154int perf_event__process_namespaces(struct perf_tool *tool __maybe_unused,
1155 union perf_event *event,
1156 struct perf_sample *sample,
1157 struct machine *machine)
1158{
1159 return machine__process_namespaces_event(machine, event, sample);
1160}
1161
1019int perf_event__process_lost(struct perf_tool *tool __maybe_unused, 1162int perf_event__process_lost(struct perf_tool *tool __maybe_unused,
1020 union perf_event *event, 1163 union perf_event *event,
1021 struct perf_sample *sample, 1164 struct perf_sample *sample,
@@ -1153,11 +1296,12 @@ int perf_event__process_exit(struct perf_tool *tool __maybe_unused,
1153 1296
1154size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp) 1297size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp)
1155{ 1298{
1156 return fprintf(fp, " offset: %#"PRIx64" size: %#"PRIx64" flags: %#"PRIx64" [%s%s]\n", 1299 return fprintf(fp, " offset: %#"PRIx64" size: %#"PRIx64" flags: %#"PRIx64" [%s%s%s]\n",
1157 event->aux.aux_offset, event->aux.aux_size, 1300 event->aux.aux_offset, event->aux.aux_size,
1158 event->aux.flags, 1301 event->aux.flags,
1159 event->aux.flags & PERF_AUX_FLAG_TRUNCATED ? "T" : "", 1302 event->aux.flags & PERF_AUX_FLAG_TRUNCATED ? "T" : "",
1160 event->aux.flags & PERF_AUX_FLAG_OVERWRITE ? "O" : ""); 1303 event->aux.flags & PERF_AUX_FLAG_OVERWRITE ? "O" : "",
1304 event->aux.flags & PERF_AUX_FLAG_PARTIAL ? "P" : "");
1161} 1305}
1162 1306
1163size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp) 1307size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp)
@@ -1196,6 +1340,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)
1196 case PERF_RECORD_MMAP: 1340 case PERF_RECORD_MMAP:
1197 ret += perf_event__fprintf_mmap(event, fp); 1341 ret += perf_event__fprintf_mmap(event, fp);
1198 break; 1342 break;
1343 case PERF_RECORD_NAMESPACES:
1344 ret += perf_event__fprintf_namespaces(event, fp);
1345 break;
1199 case PERF_RECORD_MMAP2: 1346 case PERF_RECORD_MMAP2:
1200 ret += perf_event__fprintf_mmap2(event, fp); 1347 ret += perf_event__fprintf_mmap2(event, fp);
1201 break; 1348 break;
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index c735c53a26f8..db2de6413518 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -3,9 +3,9 @@
3 3
4#include <limits.h> 4#include <limits.h>
5#include <stdio.h> 5#include <stdio.h>
6#include <linux/kernel.h>
6 7
7#include "../perf.h" 8#include "../perf.h"
8#include "map.h"
9#include "build-id.h" 9#include "build-id.h"
10#include "perf_regs.h" 10#include "perf_regs.h"
11 11
@@ -39,6 +39,13 @@ struct comm_event {
39 char comm[16]; 39 char comm[16];
40}; 40};
41 41
42struct namespaces_event {
43 struct perf_event_header header;
44 u32 pid, tid;
45 u64 nr_namespaces;
46 struct perf_ns_link_info link_info[];
47};
48
42struct fork_event { 49struct fork_event {
43 struct perf_event_header header; 50 struct perf_event_header header;
44 u32 pid, ppid; 51 u32 pid, ppid;
@@ -269,6 +276,7 @@ struct events_stats {
269 u64 total_lost; 276 u64 total_lost;
270 u64 total_lost_samples; 277 u64 total_lost_samples;
271 u64 total_aux_lost; 278 u64 total_aux_lost;
279 u64 total_aux_partial;
272 u64 total_invalid_chains; 280 u64 total_invalid_chains;
273 u32 nr_events[PERF_RECORD_HEADER_MAX]; 281 u32 nr_events[PERF_RECORD_HEADER_MAX];
274 u32 nr_non_filtered_samples; 282 u32 nr_non_filtered_samples;
@@ -485,6 +493,7 @@ union perf_event {
485 struct mmap_event mmap; 493 struct mmap_event mmap;
486 struct mmap2_event mmap2; 494 struct mmap2_event mmap2;
487 struct comm_event comm; 495 struct comm_event comm;
496 struct namespaces_event namespaces;
488 struct fork_event fork; 497 struct fork_event fork;
489 struct lost_event lost; 498 struct lost_event lost;
490 struct lost_samples_event lost_samples; 499 struct lost_samples_event lost_samples;
@@ -587,6 +596,10 @@ int perf_event__process_switch(struct perf_tool *tool,
587 union perf_event *event, 596 union perf_event *event,
588 struct perf_sample *sample, 597 struct perf_sample *sample,
589 struct machine *machine); 598 struct machine *machine);
599int perf_event__process_namespaces(struct perf_tool *tool,
600 union perf_event *event,
601 struct perf_sample *sample,
602 struct machine *machine);
590int perf_event__process_mmap(struct perf_tool *tool, 603int perf_event__process_mmap(struct perf_tool *tool,
591 union perf_event *event, 604 union perf_event *event,
592 struct perf_sample *sample, 605 struct perf_sample *sample,
@@ -636,6 +649,12 @@ pid_t perf_event__synthesize_comm(struct perf_tool *tool,
636 perf_event__handler_t process, 649 perf_event__handler_t process,
637 struct machine *machine); 650 struct machine *machine);
638 651
652int perf_event__synthesize_namespaces(struct perf_tool *tool,
653 union perf_event *event,
654 pid_t pid, pid_t tgid,
655 perf_event__handler_t process,
656 struct machine *machine);
657
639int perf_event__synthesize_mmap_events(struct perf_tool *tool, 658int perf_event__synthesize_mmap_events(struct perf_tool *tool,
640 union perf_event *event, 659 union perf_event *event,
641 pid_t pid, pid_t tgid, 660 pid_t pid, pid_t tgid,
@@ -653,6 +672,7 @@ size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp);
653size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp); 672size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp);
654size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp); 673size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp);
655size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp); 674size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp);
675size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp);
656size_t perf_event__fprintf(union perf_event *event, FILE *fp); 676size_t perf_event__fprintf(union perf_event *event, FILE *fp);
657 677
658u64 kallsyms__get_function_start(const char *kallsyms_filename, 678u64 kallsyms__get_function_start(const char *kallsyms_filename,
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index b601f2814a30..46c0faf6c502 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -8,6 +8,8 @@
8 */ 8 */
9#include "util.h" 9#include "util.h"
10#include <api/fs/fs.h> 10#include <api/fs/fs.h>
11#include <errno.h>
12#include <inttypes.h>
11#include <poll.h> 13#include <poll.h>
12#include "cpumap.h" 14#include "cpumap.h"
13#include "thread_map.h" 15#include "thread_map.h"
@@ -15,12 +17,15 @@
15#include "evlist.h" 17#include "evlist.h"
16#include "evsel.h" 18#include "evsel.h"
17#include "debug.h" 19#include "debug.h"
20#include "units.h"
18#include "asm/bug.h" 21#include "asm/bug.h"
22#include <signal.h>
19#include <unistd.h> 23#include <unistd.h>
20 24
21#include "parse-events.h" 25#include "parse-events.h"
22#include <subcmd/parse-options.h> 26#include <subcmd/parse-options.h>
23 27
28#include <sys/ioctl.h>
24#include <sys/mman.h> 29#include <sys/mman.h>
25 30
26#include <linux/bitops.h> 31#include <linux/bitops.h>
@@ -777,7 +782,7 @@ union perf_event *perf_mmap__read_forward(struct perf_mmap *md, bool check_messu
777 /* 782 /*
778 * Check if event was unmapped due to a POLLHUP/POLLERR. 783 * Check if event was unmapped due to a POLLHUP/POLLERR.
779 */ 784 */
780 if (!atomic_read(&md->refcnt)) 785 if (!refcount_read(&md->refcnt))
781 return NULL; 786 return NULL;
782 787
783 head = perf_mmap__read_head(md); 788 head = perf_mmap__read_head(md);
@@ -794,7 +799,7 @@ perf_mmap__read_backward(struct perf_mmap *md)
794 /* 799 /*
795 * Check if event was unmapped due to a POLLHUP/POLLERR. 800 * Check if event was unmapped due to a POLLHUP/POLLERR.
796 */ 801 */
797 if (!atomic_read(&md->refcnt)) 802 if (!refcount_read(&md->refcnt))
798 return NULL; 803 return NULL;
799 804
800 head = perf_mmap__read_head(md); 805 head = perf_mmap__read_head(md);
@@ -856,7 +861,7 @@ void perf_mmap__read_catchup(struct perf_mmap *md)
856{ 861{
857 u64 head; 862 u64 head;
858 863
859 if (!atomic_read(&md->refcnt)) 864 if (!refcount_read(&md->refcnt))
860 return; 865 return;
861 866
862 head = perf_mmap__read_head(md); 867 head = perf_mmap__read_head(md);
@@ -875,14 +880,14 @@ static bool perf_mmap__empty(struct perf_mmap *md)
875 880
876static void perf_mmap__get(struct perf_mmap *map) 881static void perf_mmap__get(struct perf_mmap *map)
877{ 882{
878 atomic_inc(&map->refcnt); 883 refcount_inc(&map->refcnt);
879} 884}
880 885
881static void perf_mmap__put(struct perf_mmap *md) 886static void perf_mmap__put(struct perf_mmap *md)
882{ 887{
883 BUG_ON(md->base && atomic_read(&md->refcnt) == 0); 888 BUG_ON(md->base && refcount_read(&md->refcnt) == 0);
884 889
885 if (atomic_dec_and_test(&md->refcnt)) 890 if (refcount_dec_and_test(&md->refcnt))
886 perf_mmap__munmap(md); 891 perf_mmap__munmap(md);
887} 892}
888 893
@@ -894,7 +899,7 @@ void perf_mmap__consume(struct perf_mmap *md, bool overwrite)
894 perf_mmap__write_tail(md, old); 899 perf_mmap__write_tail(md, old);
895 } 900 }
896 901
897 if (atomic_read(&md->refcnt) == 1 && perf_mmap__empty(md)) 902 if (refcount_read(&md->refcnt) == 1 && perf_mmap__empty(md))
898 perf_mmap__put(md); 903 perf_mmap__put(md);
899} 904}
900 905
@@ -937,7 +942,7 @@ static void perf_mmap__munmap(struct perf_mmap *map)
937 munmap(map->base, perf_mmap__mmap_len(map)); 942 munmap(map->base, perf_mmap__mmap_len(map));
938 map->base = NULL; 943 map->base = NULL;
939 map->fd = -1; 944 map->fd = -1;
940 atomic_set(&map->refcnt, 0); 945 refcount_set(&map->refcnt, 0);
941 } 946 }
942 auxtrace_mmap__munmap(&map->auxtrace_mmap); 947 auxtrace_mmap__munmap(&map->auxtrace_mmap);
943} 948}
@@ -974,8 +979,19 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct perf_evlist *evlist)
974 if (!map) 979 if (!map)
975 return NULL; 980 return NULL;
976 981
977 for (i = 0; i < evlist->nr_mmaps; i++) 982 for (i = 0; i < evlist->nr_mmaps; i++) {
978 map[i].fd = -1; 983 map[i].fd = -1;
984 /*
985 * When the perf_mmap() call is made we grab one refcount, plus
986 * one extra to let perf_evlist__mmap_consume() get the last
987 * events after all real references (perf_mmap__get()) are
988 * dropped.
989 *
990 * Each PERF_EVENT_IOC_SET_OUTPUT points to this mmap and
991 * thus does perf_mmap__get() on it.
992 */
993 refcount_set(&map[i].refcnt, 0);
994 }
979 return map; 995 return map;
980} 996}
981 997
@@ -1001,7 +1017,7 @@ static int perf_mmap__mmap(struct perf_mmap *map,
1001 * evlist layer can't just drop it when filtering events in 1017 * evlist layer can't just drop it when filtering events in
1002 * perf_evlist__filter_pollfd(). 1018 * perf_evlist__filter_pollfd().
1003 */ 1019 */
1004 atomic_set(&map->refcnt, 2); 1020 refcount_set(&map->refcnt, 2);
1005 map->prev = 0; 1021 map->prev = 0;
1006 map->mask = mp->mask; 1022 map->mask = mp->mask;
1007 map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot, 1023 map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 389b9ccdf8c7..94cea4398a13 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -1,7 +1,8 @@
1#ifndef __PERF_EVLIST_H 1#ifndef __PERF_EVLIST_H
2#define __PERF_EVLIST_H 1 2#define __PERF_EVLIST_H 1
3 3
4#include <linux/atomic.h> 4#include <linux/kernel.h>
5#include <linux/refcount.h>
5#include <linux/list.h> 6#include <linux/list.h>
6#include <api/fd/array.h> 7#include <api/fd/array.h>
7#include <stdio.h> 8#include <stdio.h>
@@ -10,6 +11,7 @@
10#include "evsel.h" 11#include "evsel.h"
11#include "util.h" 12#include "util.h"
12#include "auxtrace.h" 13#include "auxtrace.h"
14#include <signal.h>
13#include <unistd.h> 15#include <unistd.h>
14 16
15struct pollfd; 17struct pollfd;
@@ -29,7 +31,7 @@ struct perf_mmap {
29 void *base; 31 void *base;
30 int mask; 32 int mask;
31 int fd; 33 int fd;
32 atomic_t refcnt; 34 refcount_t refcnt;
33 u64 prev; 35 u64 prev;
34 struct auxtrace_mmap auxtrace_mmap; 36 struct auxtrace_mmap auxtrace_mmap;
35 char event_copy[PERF_SAMPLE_MAX_SIZE] __attribute__((aligned(8))); 37 char event_copy[PERF_SAMPLE_MAX_SIZE] __attribute__((aligned(8)));
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index ac59710b79e0..0e879097adfb 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -8,12 +8,15 @@
8 */ 8 */
9 9
10#include <byteswap.h> 10#include <byteswap.h>
11#include <errno.h>
12#include <inttypes.h>
11#include <linux/bitops.h> 13#include <linux/bitops.h>
12#include <api/fs/tracing_path.h> 14#include <api/fs/tracing_path.h>
13#include <traceevent/event-parse.h> 15#include <traceevent/event-parse.h>
14#include <linux/hw_breakpoint.h> 16#include <linux/hw_breakpoint.h>
15#include <linux/perf_event.h> 17#include <linux/perf_event.h>
16#include <linux/err.h> 18#include <linux/err.h>
19#include <sys/ioctl.h>
17#include <sys/resource.h> 20#include <sys/resource.h>
18#include "asm/bug.h" 21#include "asm/bug.h"
19#include "callchain.h" 22#include "callchain.h"
@@ -30,6 +33,8 @@
30#include "stat.h" 33#include "stat.h"
31#include "util/parse-branch-options.h" 34#include "util/parse-branch-options.h"
32 35
36#include "sane_ctype.h"
37
33static struct { 38static struct {
34 bool sample_id_all; 39 bool sample_id_all;
35 bool exclude_guest; 40 bool exclude_guest;
@@ -236,6 +241,10 @@ void perf_evsel__init(struct perf_evsel *evsel,
236 evsel->sample_size = __perf_evsel__sample_size(attr->sample_type); 241 evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
237 perf_evsel__calc_id_pos(evsel); 242 perf_evsel__calc_id_pos(evsel);
238 evsel->cmdline_group_boundary = false; 243 evsel->cmdline_group_boundary = false;
244 evsel->metric_expr = NULL;
245 evsel->metric_name = NULL;
246 evsel->metric_events = NULL;
247 evsel->collect_stat = false;
239} 248}
240 249
241struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx) 250struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
@@ -932,6 +941,9 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
932 attr->mmap2 = track && !perf_missing_features.mmap2; 941 attr->mmap2 = track && !perf_missing_features.mmap2;
933 attr->comm = track; 942 attr->comm = track;
934 943
944 if (opts->record_namespaces)
945 attr->namespaces = track;
946
935 if (opts->record_switch_events) 947 if (opts->record_switch_events)
936 attr->context_switch = track; 948 attr->context_switch = track;
937 949
@@ -1232,7 +1244,7 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
1232 if (FD(evsel, cpu, thread) < 0) 1244 if (FD(evsel, cpu, thread) < 0)
1233 return -EINVAL; 1245 return -EINVAL;
1234 1246
1235 if (readn(FD(evsel, cpu, thread), count, sizeof(*count)) < 0) 1247 if (readn(FD(evsel, cpu, thread), count, sizeof(*count)) <= 0)
1236 return -errno; 1248 return -errno;
1237 1249
1238 return 0; 1250 return 0;
@@ -1250,7 +1262,7 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
1250 if (evsel->counts == NULL && perf_evsel__alloc_counts(evsel, cpu + 1, thread + 1) < 0) 1262 if (evsel->counts == NULL && perf_evsel__alloc_counts(evsel, cpu + 1, thread + 1) < 0)
1251 return -ENOMEM; 1263 return -ENOMEM;
1252 1264
1253 if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0) 1265 if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) <= 0)
1254 return -errno; 1266 return -errno;
1255 1267
1256 perf_evsel__compute_deltas(evsel, cpu, thread, &count); 1268 perf_evsel__compute_deltas(evsel, cpu, thread, &count);
@@ -2450,11 +2462,17 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
2450 int err, char *msg, size_t size) 2462 int err, char *msg, size_t size)
2451{ 2463{
2452 char sbuf[STRERR_BUFSIZE]; 2464 char sbuf[STRERR_BUFSIZE];
2465 int printed = 0;
2453 2466
2454 switch (err) { 2467 switch (err) {
2455 case EPERM: 2468 case EPERM:
2456 case EACCES: 2469 case EACCES:
2457 return scnprintf(msg, size, 2470 if (err == EPERM)
2471 printed = scnprintf(msg, size,
2472 "No permission to enable %s event.\n\n",
2473 perf_evsel__name(evsel));
2474
2475 return scnprintf(msg + printed, size - printed,
2458 "You may not have permission to collect %sstats.\n\n" 2476 "You may not have permission to collect %sstats.\n\n"
2459 "Consider tweaking /proc/sys/kernel/perf_event_paranoid,\n" 2477 "Consider tweaking /proc/sys/kernel/perf_event_paranoid,\n"
2460 "which controls use of the performance events system by\n" 2478 "which controls use of the performance events system by\n"
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 06ef6f29efa1..d101695c482c 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -131,6 +131,11 @@ struct perf_evsel {
131 bool cmdline_group_boundary; 131 bool cmdline_group_boundary;
132 struct list_head config_terms; 132 struct list_head config_terms;
133 int bpf_fd; 133 int bpf_fd;
134 bool merged_stat;
135 const char * metric_expr;
136 const char * metric_name;
137 struct perf_evsel **metric_events;
138 bool collect_stat;
134}; 139};
135 140
136union u64_swap { 141union u64_swap {
diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprintf.c
index 4ef5184819a0..e415aee6a245 100644
--- a/tools/perf/util/evsel_fprintf.c
+++ b/tools/perf/util/evsel_fprintf.c
@@ -1,9 +1,11 @@
1#include <inttypes.h>
1#include <stdio.h> 2#include <stdio.h>
2#include <stdbool.h> 3#include <stdbool.h>
3#include <traceevent/event-parse.h> 4#include <traceevent/event-parse.h>
4#include "evsel.h" 5#include "evsel.h"
5#include "callchain.h" 6#include "callchain.h"
6#include "map.h" 7#include "map.h"
8#include "strlist.h"
7#include "symbol.h" 9#include "symbol.h"
8 10
9static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...) 11static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...)
diff --git a/tools/perf/util/expr.h b/tools/perf/util/expr.h
new file mode 100644
index 000000000000..9c2760a1a96e
--- /dev/null
+++ b/tools/perf/util/expr.h
@@ -0,0 +1,25 @@
1#ifndef PARSE_CTX_H
2#define PARSE_CTX_H 1
3
4#define EXPR_MAX_OTHER 8
5#define MAX_PARSE_ID EXPR_MAX_OTHER
6
7struct parse_id {
8 const char *name;
9 double val;
10};
11
12struct parse_ctx {
13 int num_ids;
14 struct parse_id ids[MAX_PARSE_ID];
15};
16
17void expr__ctx_init(struct parse_ctx *ctx);
18void expr__add_id(struct parse_ctx *ctx, const char *id, double val);
19#ifndef IN_EXPR_Y
20int expr__parse(double *final_val, struct parse_ctx *ctx, const char **pp);
21#endif
22int expr__find_other(const char *p, const char *one, const char ***other,
23 int *num_other);
24
25#endif
diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y
new file mode 100644
index 000000000000..954556bea36e
--- /dev/null
+++ b/tools/perf/util/expr.y
@@ -0,0 +1,173 @@
1/* Simple expression parser */
2%{
3#include "util.h"
4#include "util/debug.h"
5#define IN_EXPR_Y 1
6#include "expr.h"
7#include <string.h>
8
9#define MAXIDLEN 256
10%}
11
12%pure-parser
13%parse-param { double *final_val }
14%parse-param { struct parse_ctx *ctx }
15%parse-param { const char **pp }
16%lex-param { const char **pp }
17
18%union {
19 double num;
20 char id[MAXIDLEN+1];
21}
22
23%token <num> NUMBER
24%token <id> ID
25%left '|'
26%left '^'
27%left '&'
28%left '-' '+'
29%left '*' '/' '%'
30%left NEG NOT
31%type <num> expr
32
33%{
34static int expr__lex(YYSTYPE *res, const char **pp);
35
36static void expr__error(double *final_val __maybe_unused,
37 struct parse_ctx *ctx __maybe_unused,
38 const char **pp __maybe_unused,
39 const char *s)
40{
41 pr_debug("%s\n", s);
42}
43
44static int lookup_id(struct parse_ctx *ctx, char *id, double *val)
45{
46 int i;
47
48 for (i = 0; i < ctx->num_ids; i++) {
49 if (!strcasecmp(ctx->ids[i].name, id)) {
50 *val = ctx->ids[i].val;
51 return 0;
52 }
53 }
54 return -1;
55}
56
57%}
58%%
59
60all_expr: expr { *final_val = $1; }
61 ;
62
63expr: NUMBER
64 | ID { if (lookup_id(ctx, $1, &$$) < 0) {
65 pr_debug("%s not found", $1);
66 YYABORT;
67 }
68 }
69 | expr '+' expr { $$ = $1 + $3; }
70 | expr '-' expr { $$ = $1 - $3; }
71 | expr '*' expr { $$ = $1 * $3; }
72 | expr '/' expr { if ($3 == 0) YYABORT; $$ = $1 / $3; }
73 | expr '%' expr { if ((long)$3 == 0) YYABORT; $$ = (long)$1 % (long)$3; }
74 | '-' expr %prec NEG { $$ = -$2; }
75 | '(' expr ')' { $$ = $2; }
76 ;
77
78%%
79
80static int expr__symbol(YYSTYPE *res, const char *p, const char **pp)
81{
82 char *dst = res->id;
83 const char *s = p;
84
85 while (isalnum(*p) || *p == '_' || *p == '.') {
86 if (p - s >= MAXIDLEN)
87 return -1;
88 *dst++ = *p++;
89 }
90 *dst = 0;
91 *pp = p;
92 return ID;
93}
94
95static int expr__lex(YYSTYPE *res, const char **pp)
96{
97 int tok;
98 const char *s;
99 const char *p = *pp;
100
101 while (isspace(*p))
102 p++;
103 s = p;
104 switch (*p++) {
105 case 'a' ... 'z':
106 case 'A' ... 'Z':
107 return expr__symbol(res, p - 1, pp);
108 case '0' ... '9': case '.':
109 res->num = strtod(s, (char **)&p);
110 tok = NUMBER;
111 break;
112 default:
113 tok = *s;
114 break;
115 }
116 *pp = p;
117 return tok;
118}
119
120/* Caller must make sure id is allocated */
121void expr__add_id(struct parse_ctx *ctx, const char *name, double val)
122{
123 int idx;
124 assert(ctx->num_ids < MAX_PARSE_ID);
125 idx = ctx->num_ids++;
126 ctx->ids[idx].name = name;
127 ctx->ids[idx].val = val;
128}
129
130void expr__ctx_init(struct parse_ctx *ctx)
131{
132 ctx->num_ids = 0;
133}
134
135int expr__find_other(const char *p, const char *one, const char ***other,
136 int *num_otherp)
137{
138 const char *orig = p;
139 int err = -1;
140 int num_other;
141
142 *other = malloc((EXPR_MAX_OTHER + 1) * sizeof(char *));
143 if (!*other)
144 return -1;
145
146 num_other = 0;
147 for (;;) {
148 YYSTYPE val;
149 int tok = expr__lex(&val, &p);
150 if (tok == 0) {
151 err = 0;
152 break;
153 }
154 if (tok == ID && strcasecmp(one, val.id)) {
155 if (num_other >= EXPR_MAX_OTHER - 1) {
156 pr_debug("Too many extra events in %s\n", orig);
157 break;
158 }
159 (*other)[num_other] = strdup(val.id);
160 if (!(*other)[num_other])
161 return -1;
162 num_other++;
163 }
164 }
165 (*other)[num_other] = NULL;
166 *num_otherp = num_other;
167 if (err) {
168 *num_otherp = 0;
169 free(*other);
170 *other = NULL;
171 }
172 return err;
173}
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 05714d548584..948b2c5efb65 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1,4 +1,8 @@
1#include <errno.h>
2#include <inttypes.h>
1#include "util.h" 3#include "util.h"
4#include "string2.h"
5#include <sys/param.h>
2#include <sys/types.h> 6#include <sys/types.h>
3#include <byteswap.h> 7#include <byteswap.h>
4#include <unistd.h> 8#include <unistd.h>
@@ -7,7 +11,10 @@
7#include <linux/list.h> 11#include <linux/list.h>
8#include <linux/kernel.h> 12#include <linux/kernel.h>
9#include <linux/bitops.h> 13#include <linux/bitops.h>
14#include <sys/stat.h>
15#include <sys/types.h>
10#include <sys/utsname.h> 16#include <sys/utsname.h>
17#include <unistd.h>
11 18
12#include "evlist.h" 19#include "evlist.h"
13#include "evsel.h" 20#include "evsel.h"
@@ -26,6 +33,8 @@
26#include <api/fs/fs.h> 33#include <api/fs/fs.h>
27#include "asm/bug.h" 34#include "asm/bug.h"
28 35
36#include "sane_ctype.h"
37
29/* 38/*
30 * magic2 = "PERFILE2" 39 * magic2 = "PERFILE2"
31 * must be a numerical value to let the endianness 40 * must be a numerical value to let the endianness
@@ -370,15 +379,11 @@ static int write_cmdline(int fd, struct perf_header *h __maybe_unused,
370 struct perf_evlist *evlist __maybe_unused) 379 struct perf_evlist *evlist __maybe_unused)
371{ 380{
372 char buf[MAXPATHLEN]; 381 char buf[MAXPATHLEN];
373 char proc[32];
374 u32 n; 382 u32 n;
375 int i, ret; 383 int i, ret;
376 384
377 /* 385 /* actual path to perf binary */
378 * actual atual path to perf binary 386 ret = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
379 */
380 sprintf(proc, "/proc/%d/exe", getpid());
381 ret = readlink(proc, buf, sizeof(buf));
382 if (ret <= 0) 387 if (ret <= 0)
383 return -1; 388 return -1;
384 389
@@ -2274,6 +2279,9 @@ int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full)
2274 perf_header__process_sections(header, fd, &hd, 2279 perf_header__process_sections(header, fd, &hd,
2275 perf_file_section__fprintf_info); 2280 perf_file_section__fprintf_info);
2276 2281
2282 if (session->file->is_pipe)
2283 return 0;
2284
2277 fprintf(fp, "# missing features: "); 2285 fprintf(fp, "# missing features: ");
2278 for_each_clear_bit(bit, header->adds_features, HEADER_LAST_FEATURE) { 2286 for_each_clear_bit(bit, header->adds_features, HEADER_LAST_FEATURE) {
2279 if (bit) 2287 if (bit)
diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c
index 2821f8d77e52..1c88ad6425b8 100644
--- a/tools/perf/util/help-unknown-cmd.c
+++ b/tools/perf/util/help-unknown-cmd.c
@@ -1,21 +1,18 @@
1#include "cache.h" 1#include "cache.h"
2#include "config.h" 2#include "config.h"
3#include <poll.h>
3#include <stdio.h> 4#include <stdio.h>
4#include <subcmd/help.h> 5#include <subcmd/help.h>
5#include "../builtin.h" 6#include "../builtin.h"
6#include "levenshtein.h" 7#include "levenshtein.h"
7 8
8static int autocorrect; 9static int autocorrect;
9static struct cmdnames aliases;
10 10
11static int perf_unknown_cmd_config(const char *var, const char *value, 11static int perf_unknown_cmd_config(const char *var, const char *value,
12 void *cb __maybe_unused) 12 void *cb __maybe_unused)
13{ 13{
14 if (!strcmp(var, "help.autocorrect")) 14 if (!strcmp(var, "help.autocorrect"))
15 autocorrect = perf_config_int(var,value); 15 autocorrect = perf_config_int(var,value);
16 /* Also use aliases for command lookup */
17 if (!prefixcmp(var, "alias."))
18 add_cmdname(&aliases, var + 6, strlen(var + 6));
19 16
20 return 0; 17 return 0;
21} 18}
@@ -59,14 +56,12 @@ const char *help_unknown_cmd(const char *cmd)
59 56
60 memset(&main_cmds, 0, sizeof(main_cmds)); 57 memset(&main_cmds, 0, sizeof(main_cmds));
61 memset(&other_cmds, 0, sizeof(main_cmds)); 58 memset(&other_cmds, 0, sizeof(main_cmds));
62 memset(&aliases, 0, sizeof(aliases));
63 59
64 perf_config(perf_unknown_cmd_config, NULL); 60 perf_config(perf_unknown_cmd_config, NULL);
65 61
66 load_command_list("perf-", &main_cmds, &other_cmds); 62 load_command_list("perf-", &main_cmds, &other_cmds);
67 63
68 if (add_cmd_list(&main_cmds, &aliases) < 0 || 64 if (add_cmd_list(&main_cmds, &other_cmds) < 0) {
69 add_cmd_list(&main_cmds, &other_cmds) < 0) {
70 fprintf(stderr, "ERROR: Failed to allocate command list for unknown command.\n"); 65 fprintf(stderr, "ERROR: Failed to allocate command list for unknown command.\n");
71 goto end; 66 goto end;
72 } 67 }
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index eaf72a938fb4..cf0186a088c1 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -3,12 +3,17 @@
3#include "hist.h" 3#include "hist.h"
4#include "map.h" 4#include "map.h"
5#include "session.h" 5#include "session.h"
6#include "namespaces.h"
6#include "sort.h" 7#include "sort.h"
7#include "evlist.h" 8#include "evlist.h"
8#include "evsel.h" 9#include "evsel.h"
9#include "annotate.h" 10#include "annotate.h"
11#include "srcline.h"
12#include "thread.h"
10#include "ui/progress.h" 13#include "ui/progress.h"
14#include <errno.h>
11#include <math.h> 15#include <math.h>
16#include <sys/param.h>
12 17
13static bool hists__filter_entry_by_dso(struct hists *hists, 18static bool hists__filter_entry_by_dso(struct hists *hists,
14 struct hist_entry *he); 19 struct hist_entry *he);
@@ -169,6 +174,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
169 hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO); 174 hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO);
170 } 175 }
171 176
177 hists__new_col_len(hists, HISTC_CGROUP_ID, 20);
172 hists__new_col_len(hists, HISTC_CPU, 3); 178 hists__new_col_len(hists, HISTC_CPU, 3);
173 hists__new_col_len(hists, HISTC_SOCKET, 6); 179 hists__new_col_len(hists, HISTC_SOCKET, 6);
174 hists__new_col_len(hists, HISTC_MEM_LOCKED, 6); 180 hists__new_col_len(hists, HISTC_MEM_LOCKED, 6);
@@ -574,9 +580,14 @@ __hists__add_entry(struct hists *hists,
574 bool sample_self, 580 bool sample_self,
575 struct hist_entry_ops *ops) 581 struct hist_entry_ops *ops)
576{ 582{
583 struct namespaces *ns = thread__namespaces(al->thread);
577 struct hist_entry entry = { 584 struct hist_entry entry = {
578 .thread = al->thread, 585 .thread = al->thread,
579 .comm = thread__comm(al->thread), 586 .comm = thread__comm(al->thread),
587 .cgroup_id = {
588 .dev = ns ? ns->link_info[CGROUP_NS_INDEX].dev : 0,
589 .ino = ns ? ns->link_info[CGROUP_NS_INDEX].ino : 0,
590 },
580 .ms = { 591 .ms = {
581 .map = al->map, 592 .map = al->map,
582 .sym = al->sym, 593 .sym = al->sym,
@@ -1129,6 +1140,11 @@ void hist_entry__delete(struct hist_entry *he)
1129 zfree(&he->mem_info); 1140 zfree(&he->mem_info);
1130 } 1141 }
1131 1142
1143 if (he->inline_node) {
1144 inline_node__delete(he->inline_node);
1145 he->inline_node = NULL;
1146 }
1147
1132 zfree(&he->stat_acc); 1148 zfree(&he->stat_acc);
1133 free_srcline(he->srcline); 1149 free_srcline(he->srcline);
1134 if (he->srcfile && he->srcfile[0]) 1150 if (he->srcfile && he->srcfile[0])
@@ -2447,7 +2463,7 @@ int parse_filter_percentage(const struct option *opt __maybe_unused,
2447 else if (!strcmp(arg, "absolute")) 2463 else if (!strcmp(arg, "absolute"))
2448 symbol_conf.filter_relative = false; 2464 symbol_conf.filter_relative = false;
2449 else { 2465 else {
2450 pr_debug("Invalud percentage: %s\n", arg); 2466 pr_debug("Invalid percentage: %s\n", arg);
2451 return -1; 2467 return -1;
2452 } 2468 }
2453 2469
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 28c216e3d5b7..ee3670a388df 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -30,6 +30,7 @@ enum hist_column {
30 HISTC_DSO, 30 HISTC_DSO,
31 HISTC_THREAD, 31 HISTC_THREAD,
32 HISTC_COMM, 32 HISTC_COMM,
33 HISTC_CGROUP_ID,
33 HISTC_PARENT, 34 HISTC_PARENT,
34 HISTC_CPU, 35 HISTC_CPU,
35 HISTC_SOCKET, 36 HISTC_SOCKET,
@@ -57,6 +58,7 @@ enum hist_column {
57 HISTC_SRCLINE_FROM, 58 HISTC_SRCLINE_FROM,
58 HISTC_SRCLINE_TO, 59 HISTC_SRCLINE_TO,
59 HISTC_TRACE, 60 HISTC_TRACE,
61 HISTC_SYM_SIZE,
60 HISTC_NR_COLS, /* Last entry */ 62 HISTC_NR_COLS, /* Last entry */
61}; 63};
62 64
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index 6c2eb5da4afc..b2834ac7b1f5 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -14,7 +14,9 @@
14 */ 14 */
15 15
16#include <endian.h> 16#include <endian.h>
17#include <errno.h>
17#include <byteswap.h> 18#include <byteswap.h>
19#include <inttypes.h>
18#include <linux/kernel.h> 20#include <linux/kernel.h>
19#include <linux/types.h> 21#include <linux/types.h>
20#include <linux/bitops.h> 22#include <linux/bitops.h>
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
index 4f3c758d875d..54818828023b 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
@@ -26,6 +26,7 @@
26#include "insn.c" 26#include "insn.c"
27 27
28#include "intel-pt-insn-decoder.h" 28#include "intel-pt-insn-decoder.h"
29#include "dump-insn.h"
29 30
30#if INTEL_PT_INSN_BUF_SZ < MAX_INSN_SIZE || INTEL_PT_INSN_BUF_SZ > MAX_INSN 31#if INTEL_PT_INSN_BUF_SZ < MAX_INSN_SIZE || INTEL_PT_INSN_BUF_SZ > MAX_INSN
31#error Instruction buffer size too small 32#error Instruction buffer size too small
@@ -39,6 +40,8 @@ static void intel_pt_insn_decoder(struct insn *insn,
39 enum intel_pt_insn_branch branch = INTEL_PT_BR_NO_BRANCH; 40 enum intel_pt_insn_branch branch = INTEL_PT_BR_NO_BRANCH;
40 int ext; 41 int ext;
41 42
43 intel_pt_insn->rel = 0;
44
42 if (insn_is_avx(insn)) { 45 if (insn_is_avx(insn)) {
43 intel_pt_insn->op = INTEL_PT_OP_OTHER; 46 intel_pt_insn->op = INTEL_PT_OP_OTHER;
44 intel_pt_insn->branch = INTEL_PT_BR_NO_BRANCH; 47 intel_pt_insn->branch = INTEL_PT_BR_NO_BRANCH;
@@ -177,6 +180,29 @@ int intel_pt_get_insn(const unsigned char *buf, size_t len, int x86_64,
177 return 0; 180 return 0;
178} 181}
179 182
183const char *dump_insn(struct perf_insn *x, uint64_t ip __maybe_unused,
184 u8 *inbuf, int inlen, int *lenp)
185{
186 struct insn insn;
187 int n, i;
188 int left;
189
190 insn_init(&insn, inbuf, inlen, x->is64bit);
191 insn_get_length(&insn);
192 if (!insn_complete(&insn) || insn.length > inlen)
193 return "<bad>";
194 if (lenp)
195 *lenp = insn.length;
196 left = sizeof(x->out);
197 n = snprintf(x->out, left, "insn: ");
198 left -= n;
199 for (i = 0; i < insn.length; i++) {
200 n += snprintf(x->out + n, left, "%02x ", inbuf[i]);
201 left -= n;
202 }
203 return x->out;
204}
205
180const char *branch_name[] = { 206const char *branch_name[] = {
181 [INTEL_PT_OP_OTHER] = "Other", 207 [INTEL_PT_OP_OTHER] = "Other",
182 [INTEL_PT_OP_CALL] = "Call", 208 [INTEL_PT_OP_CALL] = "Call",
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index da20cd5612e9..bdd4a28c6cee 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -13,6 +13,7 @@
13 * 13 *
14 */ 14 */
15 15
16#include <inttypes.h>
16#include <stdio.h> 17#include <stdio.h>
17#include <stdbool.h> 18#include <stdbool.h>
18#include <errno.h> 19#include <errno.h>
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index c9a941ef0f6d..9084930e1757 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -1,5 +1,6 @@
1#include <sys/sysmacros.h> 1#include <sys/sysmacros.h>
2#include <sys/types.h> 2#include <sys/types.h>
3#include <errno.h>
3#include <stdio.h> 4#include <stdio.h>
4#include <stdlib.h> 5#include <stdlib.h>
5#include <string.h> 6#include <string.h>
@@ -9,13 +10,13 @@
9#include <byteswap.h> 10#include <byteswap.h>
10#include <sys/stat.h> 11#include <sys/stat.h>
11#include <sys/mman.h> 12#include <sys/mman.h>
13#include <linux/stringify.h>
12 14
13#include "util.h" 15#include "util.h"
14#include "event.h" 16#include "event.h"
15#include "debug.h" 17#include "debug.h"
16#include "evlist.h" 18#include "evlist.h"
17#include "symbol.h" 19#include "symbol.h"
18#include "strlist.h"
19#include <elf.h> 20#include <elf.h>
20 21
21#include "tsc.h" 22#include "tsc.h"
@@ -25,6 +26,8 @@
25#include "genelf.h" 26#include "genelf.h"
26#include "../builtin.h" 27#include "../builtin.h"
27 28
29#include "sane_ctype.h"
30
28struct jit_buf_desc { 31struct jit_buf_desc {
29 struct perf_data_file *output; 32 struct perf_data_file *output;
30 struct perf_session *session; 33 struct perf_session *session;
@@ -181,7 +184,7 @@ jit_open(struct jit_buf_desc *jd, const char *name)
181 jd->use_arch_timestamp); 184 jd->use_arch_timestamp);
182 185
183 if (header.version > JITHEADER_VERSION) { 186 if (header.version > JITHEADER_VERSION) {
184 pr_err("wrong jitdump version %u, expected " STR(JITHEADER_VERSION), 187 pr_err("wrong jitdump version %u, expected " __stringify(JITHEADER_VERSION),
185 header.version); 188 header.version);
186 goto error; 189 goto error;
187 } 190 }
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 824356488ce6..c6a15f204c03 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -12,6 +12,7 @@
12#include "llvm-utils.h" 12#include "llvm-utils.h"
13#include "config.h" 13#include "config.h"
14#include "util.h" 14#include "util.h"
15#include <sys/wait.h>
15 16
16#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ 17#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \
17 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\ 18 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
diff --git a/tools/perf/util/lzma.c b/tools/perf/util/lzma.c
index 9ddea5cecd94..4ca7c5c6cdcd 100644
--- a/tools/perf/util/lzma.c
+++ b/tools/perf/util/lzma.c
@@ -1,6 +1,8 @@
1#include <errno.h>
1#include <lzma.h> 2#include <lzma.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <linux/compiler.h> 4#include <linux/compiler.h>
5#include "compress.h"
4#include "util.h" 6#include "util.h"
5#include "debug.h" 7#include "debug.h"
6 8
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 71c9720d4973..7a47f52ccfcc 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1,3 +1,7 @@
1#include <dirent.h>
2#include <errno.h>
3#include <inttypes.h>
4#include <regex.h>
1#include "callchain.h" 5#include "callchain.h"
2#include "debug.h" 6#include "debug.h"
3#include "event.h" 7#include "event.h"
@@ -10,9 +14,15 @@
10#include "thread.h" 14#include "thread.h"
11#include "vdso.h" 15#include "vdso.h"
12#include <stdbool.h> 16#include <stdbool.h>
13#include <symbol/kallsyms.h> 17#include <sys/types.h>
18#include <sys/stat.h>
19#include <unistd.h>
14#include "unwind.h" 20#include "unwind.h"
15#include "linux/hash.h" 21#include "linux/hash.h"
22#include "asm/bug.h"
23
24#include "sane_ctype.h"
25#include <symbol/kallsyms.h>
16 26
17static void __machine__remove_thread(struct machine *machine, struct thread *th, bool lock); 27static void __machine__remove_thread(struct machine *machine, struct thread *th, bool lock);
18 28
@@ -501,6 +511,37 @@ int machine__process_comm_event(struct machine *machine, union perf_event *event
501 return err; 511 return err;
502} 512}
503 513
514int machine__process_namespaces_event(struct machine *machine __maybe_unused,
515 union perf_event *event,
516 struct perf_sample *sample __maybe_unused)
517{
518 struct thread *thread = machine__findnew_thread(machine,
519 event->namespaces.pid,
520 event->namespaces.tid);
521 int err = 0;
522
523 WARN_ONCE(event->namespaces.nr_namespaces > NR_NAMESPACES,
524 "\nWARNING: kernel seems to support more namespaces than perf"
525 " tool.\nTry updating the perf tool..\n\n");
526
527 WARN_ONCE(event->namespaces.nr_namespaces < NR_NAMESPACES,
528 "\nWARNING: perf tool seems to support more namespaces than"
529 " the kernel.\nTry updating the kernel..\n\n");
530
531 if (dump_trace)
532 perf_event__fprintf_namespaces(event, stdout);
533
534 if (thread == NULL ||
535 thread__set_namespaces(thread, sample->time, &event->namespaces)) {
536 dump_printf("problem processing PERF_RECORD_NAMESPACES, skipping event.\n");
537 err = -1;
538 }
539
540 thread__put(thread);
541
542 return err;
543}
544
504int machine__process_lost_event(struct machine *machine __maybe_unused, 545int machine__process_lost_event(struct machine *machine __maybe_unused,
505 union perf_event *event, struct perf_sample *sample __maybe_unused) 546 union perf_event *event, struct perf_sample *sample __maybe_unused)
506{ 547{
@@ -1439,7 +1480,7 @@ static void __machine__remove_thread(struct machine *machine, struct thread *th,
1439 if (machine->last_match == th) 1480 if (machine->last_match == th)
1440 machine->last_match = NULL; 1481 machine->last_match = NULL;
1441 1482
1442 BUG_ON(atomic_read(&th->refcnt) == 0); 1483 BUG_ON(refcount_read(&th->refcnt) == 0);
1443 if (lock) 1484 if (lock)
1444 pthread_rwlock_wrlock(&machine->threads_lock); 1485 pthread_rwlock_wrlock(&machine->threads_lock);
1445 rb_erase_init(&th->rb_node, &machine->threads); 1486 rb_erase_init(&th->rb_node, &machine->threads);
@@ -1538,6 +1579,8 @@ int machine__process_event(struct machine *machine, union perf_event *event,
1538 ret = machine__process_comm_event(machine, event, sample); break; 1579 ret = machine__process_comm_event(machine, event, sample); break;
1539 case PERF_RECORD_MMAP: 1580 case PERF_RECORD_MMAP:
1540 ret = machine__process_mmap_event(machine, event, sample); break; 1581 ret = machine__process_mmap_event(machine, event, sample); break;
1582 case PERF_RECORD_NAMESPACES:
1583 ret = machine__process_namespaces_event(machine, event, sample); break;
1541 case PERF_RECORD_MMAP2: 1584 case PERF_RECORD_MMAP2:
1542 ret = machine__process_mmap2_event(machine, event, sample); break; 1585 ret = machine__process_mmap2_event(machine, event, sample); break;
1543 case PERF_RECORD_FORK: 1586 case PERF_RECORD_FORK:
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index a28305029711..3cdb1340f917 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -97,6 +97,9 @@ int machine__process_itrace_start_event(struct machine *machine,
97 union perf_event *event); 97 union perf_event *event);
98int machine__process_switch_event(struct machine *machine, 98int machine__process_switch_event(struct machine *machine,
99 union perf_event *event); 99 union perf_event *event);
100int machine__process_namespaces_event(struct machine *machine,
101 union perf_event *event,
102 struct perf_sample *sample);
100int machine__process_mmap_event(struct machine *machine, union perf_event *event, 103int machine__process_mmap_event(struct machine *machine, union perf_event *event,
101 struct perf_sample *sample); 104 struct perf_sample *sample);
102int machine__process_mmap2_event(struct machine *machine, union perf_event *event, 105int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 0a943e7b1ea7..ebfa5d92358a 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -9,13 +9,13 @@
9#include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */ 9#include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */
10#include "map.h" 10#include "map.h"
11#include "thread.h" 11#include "thread.h"
12#include "strlist.h"
13#include "vdso.h" 12#include "vdso.h"
14#include "build-id.h" 13#include "build-id.h"
15#include "util.h" 14#include "util.h"
16#include "debug.h" 15#include "debug.h"
17#include "machine.h" 16#include "machine.h"
18#include <linux/string.h> 17#include <linux/string.h>
18#include "srcline.h"
19#include "unwind.h" 19#include "unwind.h"
20 20
21static void __maps__insert(struct maps *maps, struct map *map); 21static void __maps__insert(struct maps *maps, struct map *map);
@@ -141,7 +141,7 @@ void map__init(struct map *map, enum map_type type,
141 RB_CLEAR_NODE(&map->rb_node); 141 RB_CLEAR_NODE(&map->rb_node);
142 map->groups = NULL; 142 map->groups = NULL;
143 map->erange_warned = false; 143 map->erange_warned = false;
144 atomic_set(&map->refcnt, 1); 144 refcount_set(&map->refcnt, 1);
145} 145}
146 146
147struct map *map__new(struct machine *machine, u64 start, u64 len, 147struct map *map__new(struct machine *machine, u64 start, u64 len,
@@ -255,7 +255,7 @@ void map__delete(struct map *map)
255 255
256void map__put(struct map *map) 256void map__put(struct map *map)
257{ 257{
258 if (map && atomic_dec_and_test(&map->refcnt)) 258 if (map && refcount_dec_and_test(&map->refcnt))
259 map__delete(map); 259 map__delete(map);
260} 260}
261 261
@@ -354,7 +354,7 @@ struct map *map__clone(struct map *from)
354 struct map *map = memdup(from, sizeof(*map)); 354 struct map *map = memdup(from, sizeof(*map));
355 355
356 if (map != NULL) { 356 if (map != NULL) {
357 atomic_set(&map->refcnt, 1); 357 refcount_set(&map->refcnt, 1);
358 RB_CLEAR_NODE(&map->rb_node); 358 RB_CLEAR_NODE(&map->rb_node);
359 dso__get(map->dso); 359 dso__get(map->dso);
360 map->groups = NULL; 360 map->groups = NULL;
@@ -405,7 +405,8 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
405 405
406 if (map && map->dso) { 406 if (map && map->dso) {
407 srcline = get_srcline(map->dso, 407 srcline = get_srcline(map->dso,
408 map__rip_2objdump(map, addr), NULL, true); 408 map__rip_2objdump(map, addr), NULL,
409 true, true);
409 if (srcline != SRCLINE_UNKNOWN) 410 if (srcline != SRCLINE_UNKNOWN)
410 ret = fprintf(fp, "%s%s", prefix, srcline); 411 ret = fprintf(fp, "%s%s", prefix, srcline);
411 free_srcline(srcline); 412 free_srcline(srcline);
@@ -485,7 +486,7 @@ void map_groups__init(struct map_groups *mg, struct machine *machine)
485 maps__init(&mg->maps[i]); 486 maps__init(&mg->maps[i]);
486 } 487 }
487 mg->machine = machine; 488 mg->machine = machine;
488 atomic_set(&mg->refcnt, 1); 489 refcount_set(&mg->refcnt, 1);
489} 490}
490 491
491static void __maps__purge(struct maps *maps) 492static void __maps__purge(struct maps *maps)
@@ -547,7 +548,7 @@ void map_groups__delete(struct map_groups *mg)
547 548
548void map_groups__put(struct map_groups *mg) 549void map_groups__put(struct map_groups *mg)
549{ 550{
550 if (mg && atomic_dec_and_test(&mg->refcnt)) 551 if (mg && refcount_dec_and_test(&mg->refcnt))
551 map_groups__delete(mg); 552 map_groups__delete(mg);
552} 553}
553 554
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index abdacf800c98..c8a5a644c0a9 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -1,7 +1,7 @@
1#ifndef __PERF_MAP_H 1#ifndef __PERF_MAP_H
2#define __PERF_MAP_H 2#define __PERF_MAP_H
3 3
4#include <linux/atomic.h> 4#include <linux/refcount.h>
5#include <linux/compiler.h> 5#include <linux/compiler.h>
6#include <linux/list.h> 6#include <linux/list.h>
7#include <linux/rbtree.h> 7#include <linux/rbtree.h>
@@ -51,7 +51,7 @@ struct map {
51 51
52 struct dso *dso; 52 struct dso *dso;
53 struct map_groups *groups; 53 struct map_groups *groups;
54 atomic_t refcnt; 54 refcount_t refcnt;
55}; 55};
56 56
57struct kmap { 57struct kmap {
@@ -67,7 +67,7 @@ struct maps {
67struct map_groups { 67struct map_groups {
68 struct maps maps[MAP__NR_TYPES]; 68 struct maps maps[MAP__NR_TYPES];
69 struct machine *machine; 69 struct machine *machine;
70 atomic_t refcnt; 70 refcount_t refcnt;
71}; 71};
72 72
73struct map_groups *map_groups__new(struct machine *machine); 73struct map_groups *map_groups__new(struct machine *machine);
@@ -77,7 +77,7 @@ bool map_groups__empty(struct map_groups *mg);
77static inline struct map_groups *map_groups__get(struct map_groups *mg) 77static inline struct map_groups *map_groups__get(struct map_groups *mg)
78{ 78{
79 if (mg) 79 if (mg)
80 atomic_inc(&mg->refcnt); 80 refcount_inc(&mg->refcnt);
81 return mg; 81 return mg;
82} 82}
83 83
@@ -150,7 +150,7 @@ struct map *map__clone(struct map *map);
150static inline struct map *map__get(struct map *map) 150static inline struct map *map__get(struct map *map)
151{ 151{
152 if (map) 152 if (map)
153 atomic_inc(&map->refcnt); 153 refcount_inc(&map->refcnt);
154 return map; 154 return map;
155} 155}
156 156
diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index 1d4ab53c60ca..06f5a3a4295c 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -6,6 +6,7 @@
6#include <sys/stat.h> 6#include <sys/stat.h>
7#include <unistd.h> 7#include <unistd.h>
8#include <api/fs/fs.h> 8#include <api/fs/fs.h>
9#include <linux/kernel.h>
9#include "mem-events.h" 10#include "mem-events.h"
10#include "debug.h" 11#include "debug.h"
11#include "symbol.h" 12#include "symbol.h"
@@ -205,8 +206,8 @@ int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
205static const char * const snoop_access[] = { 206static const char * const snoop_access[] = {
206 "N/A", 207 "N/A",
207 "None", 208 "None",
208 "Miss",
209 "Hit", 209 "Hit",
210 "Miss",
210 "HitM", 211 "HitM",
211}; 212};
212 213
diff --git a/tools/perf/util/namespaces.c b/tools/perf/util/namespaces.c
new file mode 100644
index 000000000000..67dcbcc73c7d
--- /dev/null
+++ b/tools/perf/util/namespaces.c
@@ -0,0 +1,37 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation.
5 *
6 * Copyright (C) 2017 Hari Bathini, IBM Corporation
7 */
8
9#include "namespaces.h"
10#include "util.h"
11#include "event.h"
12#include <stdlib.h>
13#include <stdio.h>
14#include <string.h>
15
16struct namespaces *namespaces__new(struct namespaces_event *event)
17{
18 struct namespaces *namespaces;
19 u64 link_info_size = ((event ? event->nr_namespaces : NR_NAMESPACES) *
20 sizeof(struct perf_ns_link_info));
21
22 namespaces = zalloc(sizeof(struct namespaces) + link_info_size);
23 if (!namespaces)
24 return NULL;
25
26 namespaces->end_time = -1;
27
28 if (event)
29 memcpy(namespaces->link_info, event->link_info, link_info_size);
30
31 return namespaces;
32}
33
34void namespaces__free(struct namespaces *namespaces)
35{
36 free(namespaces);
37}
diff --git a/tools/perf/util/namespaces.h b/tools/perf/util/namespaces.h
new file mode 100644
index 000000000000..468f1e9a1484
--- /dev/null
+++ b/tools/perf/util/namespaces.h
@@ -0,0 +1,26 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation.
5 *
6 * Copyright (C) 2017 Hari Bathini, IBM Corporation
7 */
8
9#ifndef __PERF_NAMESPACES_H
10#define __PERF_NAMESPACES_H
11
12#include "../perf.h"
13#include <linux/list.h>
14
15struct namespaces_event;
16
17struct namespaces {
18 struct list_head list;
19 u64 end_time;
20 struct perf_ns_link_info link_info[];
21};
22
23struct namespaces *namespaces__new(struct namespaces_event *event);
24void namespaces__free(struct namespaces *namespaces);
25
26#endif /* __PERF_NAMESPACES_H */
diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
index fe84df1875aa..4de398cfb577 100644
--- a/tools/perf/util/ordered-events.c
+++ b/tools/perf/util/ordered-events.c
@@ -1,3 +1,5 @@
1#include <errno.h>
2#include <inttypes.h>
1#include <linux/list.h> 3#include <linux/list.h>
2#include <linux/compiler.h> 4#include <linux/compiler.h>
3#include <linux/string.h> 5#include <linux/string.h>
@@ -79,7 +81,7 @@ static union perf_event *dup_event(struct ordered_events *oe,
79 81
80static void free_dup_event(struct ordered_events *oe, union perf_event *event) 82static void free_dup_event(struct ordered_events *oe, union perf_event *event)
81{ 83{
82 if (oe->copy_on_queue) { 84 if (event && oe->copy_on_queue) {
83 oe->cur_alloc_size -= event->header.size; 85 oe->cur_alloc_size -= event->header.size;
84 free(event); 86 free(event);
85 } 87 }
@@ -150,6 +152,7 @@ void ordered_events__delete(struct ordered_events *oe, struct ordered_event *eve
150 list_move(&event->list, &oe->cache); 152 list_move(&event->list, &oe->cache);
151 oe->nr_events--; 153 oe->nr_events--;
152 free_dup_event(oe, event->event); 154 free_dup_event(oe, event->event);
155 event->event = NULL;
153} 156}
154 157
155int ordered_events__queue(struct ordered_events *oe, union perf_event *event, 158int ordered_events__queue(struct ordered_events *oe, union perf_event *event,
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 67a8aebc67ab..01e779b91c8e 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1,13 +1,18 @@
1#include <linux/hw_breakpoint.h> 1#include <linux/hw_breakpoint.h>
2#include <linux/err.h> 2#include <linux/err.h>
3#include "util.h" 3#include <dirent.h>
4#include <errno.h>
5#include <sys/ioctl.h>
6#include <sys/param.h>
7#include "term.h"
4#include "../perf.h" 8#include "../perf.h"
5#include "evlist.h" 9#include "evlist.h"
6#include "evsel.h" 10#include "evsel.h"
7#include <subcmd/parse-options.h> 11#include <subcmd/parse-options.h>
8#include "parse-events.h" 12#include "parse-events.h"
9#include <subcmd/exec-cmd.h> 13#include <subcmd/exec-cmd.h>
10#include "string.h" 14#include "string2.h"
15#include "strlist.h"
11#include "symbol.h" 16#include "symbol.h"
12#include "cache.h" 17#include "cache.h"
13#include "header.h" 18#include "header.h"
@@ -316,8 +321,9 @@ __add_event(struct list_head *list, int *idx,
316 return NULL; 321 return NULL;
317 322
318 (*idx)++; 323 (*idx)++;
319 evsel->cpus = cpu_map__get(cpus); 324 evsel->cpus = cpu_map__get(cpus);
320 evsel->own_cpus = cpu_map__get(cpus); 325 evsel->own_cpus = cpu_map__get(cpus);
326 evsel->system_wide = !!cpus;
321 327
322 if (name) 328 if (name)
323 evsel->name = strdup(name); 329 evsel->name = strdup(name);
@@ -1254,11 +1260,59 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
1254 evsel->scale = info.scale; 1260 evsel->scale = info.scale;
1255 evsel->per_pkg = info.per_pkg; 1261 evsel->per_pkg = info.per_pkg;
1256 evsel->snapshot = info.snapshot; 1262 evsel->snapshot = info.snapshot;
1263 evsel->metric_expr = info.metric_expr;
1264 evsel->metric_name = info.metric_name;
1257 } 1265 }
1258 1266
1259 return evsel ? 0 : -ENOMEM; 1267 return evsel ? 0 : -ENOMEM;
1260} 1268}
1261 1269
1270int parse_events_multi_pmu_add(struct parse_events_evlist *data,
1271 char *str, struct list_head **listp)
1272{
1273 struct list_head *head;
1274 struct parse_events_term *term;
1275 struct list_head *list;
1276 struct perf_pmu *pmu = NULL;
1277 int ok = 0;
1278
1279 *listp = NULL;
1280 /* Add it for all PMUs that support the alias */
1281 list = malloc(sizeof(struct list_head));
1282 if (!list)
1283 return -1;
1284 INIT_LIST_HEAD(list);
1285 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1286 struct perf_pmu_alias *alias;
1287
1288 list_for_each_entry(alias, &pmu->aliases, list) {
1289 if (!strcasecmp(alias->name, str)) {
1290 head = malloc(sizeof(struct list_head));
1291 if (!head)
1292 return -1;
1293 INIT_LIST_HEAD(head);
1294 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
1295 str, 1, false, &str, NULL) < 0)
1296 return -1;
1297 list_add_tail(&term->list, head);
1298
1299 if (!parse_events_add_pmu(data, list,
1300 pmu->name, head)) {
1301 pr_debug("%s -> %s/%s/\n", str,
1302 pmu->name, alias->str);
1303 ok++;
1304 }
1305
1306 parse_events_terms__delete(head);
1307 }
1308 }
1309 }
1310 if (!ok)
1311 return -1;
1312 *listp = list;
1313 return 0;
1314}
1315
1262int parse_events__modifier_group(struct list_head *list, 1316int parse_events__modifier_group(struct list_head *list,
1263 char *event_mod) 1317 char *event_mod)
1264{ 1318{
@@ -2276,7 +2330,7 @@ out_enomem:
2276 * Print the help text for the event symbols: 2330 * Print the help text for the event symbols:
2277 */ 2331 */
2278void print_events(const char *event_glob, bool name_only, bool quiet_flag, 2332void print_events(const char *event_glob, bool name_only, bool quiet_flag,
2279 bool long_desc) 2333 bool long_desc, bool details_flag)
2280{ 2334{
2281 print_symbol_events(event_glob, PERF_TYPE_HARDWARE, 2335 print_symbol_events(event_glob, PERF_TYPE_HARDWARE,
2282 event_symbols_hw, PERF_COUNT_HW_MAX, name_only); 2336 event_symbols_hw, PERF_COUNT_HW_MAX, name_only);
@@ -2286,7 +2340,8 @@ void print_events(const char *event_glob, bool name_only, bool quiet_flag,
2286 2340
2287 print_hwcache_events(event_glob, name_only); 2341 print_hwcache_events(event_glob, name_only);
2288 2342
2289 print_pmu_events(event_glob, name_only, quiet_flag, long_desc); 2343 print_pmu_events(event_glob, name_only, quiet_flag, long_desc,
2344 details_flag);
2290 2345
2291 if (event_glob != NULL) 2346 if (event_glob != NULL)
2292 return; 2347 return;
@@ -2415,6 +2470,31 @@ int parse_events_term__clone(struct parse_events_term **new,
2415 return new_term(new, &temp, term->val.str, term->val.num); 2470 return new_term(new, &temp, term->val.str, term->val.num);
2416} 2471}
2417 2472
2473int parse_events_copy_term_list(struct list_head *old,
2474 struct list_head **new)
2475{
2476 struct parse_events_term *term, *n;
2477 int ret;
2478
2479 if (!old) {
2480 *new = NULL;
2481 return 0;
2482 }
2483
2484 *new = malloc(sizeof(struct list_head));
2485 if (!*new)
2486 return -ENOMEM;
2487 INIT_LIST_HEAD(*new);
2488
2489 list_for_each_entry (term, old, list) {
2490 ret = parse_events_term__clone(&n, term);
2491 if (ret)
2492 return ret;
2493 list_add_tail(&n->list, *new);
2494 }
2495 return 0;
2496}
2497
2418void parse_events_terms__purge(struct list_head *terms) 2498void parse_events_terms__purge(struct list_head *terms)
2419{ 2499{
2420 struct parse_events_term *term, *h; 2500 struct parse_events_term *term, *h;
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 1af6a267c21b..a235f4d6d5e5 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -8,6 +8,7 @@
8#include <stdbool.h> 8#include <stdbool.h>
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/perf_event.h> 10#include <linux/perf_event.h>
11#include <string.h>
11 12
12struct list_head; 13struct list_head;
13struct perf_evsel; 14struct perf_evsel;
@@ -166,6 +167,14 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx,
166int parse_events_add_pmu(struct parse_events_evlist *data, 167int parse_events_add_pmu(struct parse_events_evlist *data,
167 struct list_head *list, char *name, 168 struct list_head *list, char *name,
168 struct list_head *head_config); 169 struct list_head *head_config);
170
171int parse_events_multi_pmu_add(struct parse_events_evlist *data,
172 char *str,
173 struct list_head **listp);
174
175int parse_events_copy_term_list(struct list_head *old,
176 struct list_head **new);
177
169enum perf_pmu_event_symbol_type 178enum perf_pmu_event_symbol_type
170perf_pmu__parse_check(const char *name); 179perf_pmu__parse_check(const char *name);
171void parse_events__set_leader(char *name, struct list_head *list); 180void parse_events__set_leader(char *name, struct list_head *list);
@@ -175,7 +184,7 @@ void parse_events_evlist_error(struct parse_events_evlist *data,
175 int idx, const char *str); 184 int idx, const char *str);
176 185
177void print_events(const char *event_glob, bool name_only, bool quiet, 186void print_events(const char *event_glob, bool name_only, bool quiet,
178 bool long_desc); 187 bool long_desc, bool details_flag);
179 188
180struct event_symbol { 189struct event_symbol {
181 const char *symbol; 190 const char *symbol;
@@ -196,4 +205,23 @@ int is_valid_tracepoint(const char *event_string);
196int valid_event_mount(const char *eventfs); 205int valid_event_mount(const char *eventfs);
197char *parse_events_formats_error_string(char *additional_terms); 206char *parse_events_formats_error_string(char *additional_terms);
198 207
208#ifdef HAVE_LIBELF_SUPPORT
209/*
210 * If the probe point starts with '%',
211 * or starts with "sdt_" and has a ':' but no '=',
212 * then it should be a SDT/cached probe point.
213 */
214static inline bool is_sdt_event(char *str)
215{
216 return (str[0] == '%' ||
217 (!strncmp(str, "sdt_", 4) &&
218 !!strchr(str, ':') && !strchr(str, '=')));
219}
220#else
221static inline bool is_sdt_event(char *str __maybe_unused)
222{
223 return false;
224}
225#endif /* HAVE_LIBELF_SUPPORT */
226
199#endif /* __PERF_PARSE_EVENTS_H */ 227#endif /* __PERF_PARSE_EVENTS_H */
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 30f018ea1370..04fd8c9af9f9 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -226,68 +226,55 @@ event_pmu:
226PE_NAME opt_event_config 226PE_NAME opt_event_config
227{ 227{
228 struct parse_events_evlist *data = _data; 228 struct parse_events_evlist *data = _data;
229 struct list_head *list; 229 struct list_head *list, *orig_terms, *terms;
230
231 if (parse_events_copy_term_list($2, &orig_terms))
232 YYABORT;
230 233
231 ALLOC_LIST(list); 234 ALLOC_LIST(list);
232 ABORT_ON(parse_events_add_pmu(data, list, $1, $2)); 235 if (parse_events_add_pmu(data, list, $1, $2)) {
236 struct perf_pmu *pmu = NULL;
237 int ok = 0;
238
239 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
240 char *name = pmu->name;
241
242 if (!strncmp(name, "uncore_", 7) &&
243 strncmp($1, "uncore_", 7))
244 name += 7;
245 if (!strncmp($1, name, strlen($1))) {
246 if (parse_events_copy_term_list(orig_terms, &terms))
247 YYABORT;
248 if (!parse_events_add_pmu(data, list, pmu->name, terms))
249 ok++;
250 parse_events_terms__delete(terms);
251 }
252 }
253 if (!ok)
254 YYABORT;
255 }
233 parse_events_terms__delete($2); 256 parse_events_terms__delete($2);
257 parse_events_terms__delete(orig_terms);
234 $$ = list; 258 $$ = list;
235} 259}
236| 260|
237PE_KERNEL_PMU_EVENT sep_dc 261PE_KERNEL_PMU_EVENT sep_dc
238{ 262{
239 struct parse_events_evlist *data = _data;
240 struct list_head *head;
241 struct parse_events_term *term;
242 struct list_head *list; 263 struct list_head *list;
243 struct perf_pmu *pmu = NULL;
244 int ok = 0;
245
246 /* Add it for all PMUs that support the alias */
247 ALLOC_LIST(list);
248 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
249 struct perf_pmu_alias *alias;
250
251 list_for_each_entry(alias, &pmu->aliases, list) {
252 if (!strcasecmp(alias->name, $1)) {
253 ALLOC_LIST(head);
254 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
255 $1, 1, false, &@1, NULL));
256 list_add_tail(&term->list, head);
257
258 if (!parse_events_add_pmu(data, list,
259 pmu->name, head)) {
260 pr_debug("%s -> %s/%s/\n", $1,
261 pmu->name, alias->str);
262 ok++;
263 }
264 264
265 parse_events_terms__delete(head); 265 if (parse_events_multi_pmu_add(_data, $1, &list) < 0)
266 }
267 }
268 }
269 if (!ok)
270 YYABORT; 266 YYABORT;
271 $$ = list; 267 $$ = list;
272} 268}
273| 269|
274PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc 270PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
275{ 271{
276 struct parse_events_evlist *data = _data;
277 struct list_head *head;
278 struct parse_events_term *term;
279 struct list_head *list; 272 struct list_head *list;
280 char pmu_name[128]; 273 char pmu_name[128];
281 snprintf(&pmu_name, 128, "%s-%s", $1, $3);
282 274
283 ALLOC_LIST(head); 275 snprintf(&pmu_name, 128, "%s-%s", $1, $3);
284 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 276 if (parse_events_multi_pmu_add(_data, pmu_name, &list) < 0)
285 &pmu_name, 1, false, &@1, NULL)); 277 YYABORT;
286 list_add_tail(&term->list, head);
287
288 ALLOC_LIST(list);
289 ABORT_ON(parse_events_add_pmu(data, list, "cpu", head));
290 parse_events_terms__delete(head);
291 $$ = list; 278 $$ = list;
292} 279}
293 280
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index 7c7630be5a89..50ec3bc87a60 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -11,8 +11,13 @@
11 * which is what it's designed for. 11 * which is what it's designed for.
12 */ 12 */
13#include "cache.h" 13#include "cache.h"
14#include "util.h" 14#include "path.h"
15#include <linux/kernel.h>
15#include <limits.h> 16#include <limits.h>
17#include <stdio.h>
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <unistd.h>
16 21
17static char bad_path[] = "/bad-path/"; 22static char bad_path[] = "/bad-path/";
18/* 23/*
@@ -50,3 +55,24 @@ char *mkpath(const char *fmt, ...)
50 return bad_path; 55 return bad_path;
51 return cleanup_path(pathname); 56 return cleanup_path(pathname);
52} 57}
58
59int path__join(char *bf, size_t size, const char *path1, const char *path2)
60{
61 return scnprintf(bf, size, "%s%s%s", path1, path1[0] ? "/" : "", path2);
62}
63
64int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3)
65{
66 return scnprintf(bf, size, "%s%s%s%s%s", path1, path1[0] ? "/" : "",
67 path2, path2[0] ? "/" : "", path3);
68}
69
70bool is_regular_file(const char *file)
71{
72 struct stat st;
73
74 if (stat(file, &st))
75 return false;
76
77 return S_ISREG(st.st_mode);
78}
diff --git a/tools/perf/util/path.h b/tools/perf/util/path.h
new file mode 100644
index 000000000000..9a276a58e3c2
--- /dev/null
+++ b/tools/perf/util/path.h
@@ -0,0 +1,9 @@
1#ifndef _PERF_PATH_H
2#define _PERF_PATH_H
3
4int path__join(char *bf, size_t size, const char *path1, const char *path2);
5int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3);
6
7bool is_regular_file(const char *file);
8
9#endif /* _PERF_PATH_H */
diff --git a/tools/perf/util/perf-hooks.c b/tools/perf/util/perf-hooks.c
index cb368306b12b..d55092964da2 100644
--- a/tools/perf/util/perf-hooks.c
+++ b/tools/perf/util/perf-hooks.c
@@ -9,6 +9,7 @@
9#include <stdlib.h> 9#include <stdlib.h>
10#include <setjmp.h> 10#include <setjmp.h>
11#include <linux/err.h> 11#include <linux/err.h>
12#include <linux/kernel.h>
12#include "util/util.h" 13#include "util/util.h"
13#include "util/debug.h" 14#include "util/debug.h"
14#include "util/perf-hooks.h" 15#include "util/perf-hooks.h"
diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
index c4023f22f287..b2ae039eff85 100644
--- a/tools/perf/util/perf_regs.c
+++ b/tools/perf/util/perf_regs.c
@@ -6,6 +6,12 @@ const struct sample_reg __weak sample_reg_masks[] = {
6 SMPL_REG_END 6 SMPL_REG_END
7}; 7};
8 8
9int __weak arch_sdt_arg_parse_op(char *old_op __maybe_unused,
10 char **new_op __maybe_unused)
11{
12 return SDT_ARG_SKIP;
13}
14
9#ifdef HAVE_PERF_REGS_SUPPORT 15#ifdef HAVE_PERF_REGS_SUPPORT
10int perf_reg_value(u64 *valp, struct regs_dump *regs, int id) 16int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
11{ 17{
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
index 679d6e493962..32b37d19dcc3 100644
--- a/tools/perf/util/perf_regs.h
+++ b/tools/perf/util/perf_regs.h
@@ -15,6 +15,13 @@ struct sample_reg {
15 15
16extern const struct sample_reg sample_reg_masks[]; 16extern const struct sample_reg sample_reg_masks[];
17 17
18enum {
19 SDT_ARG_VALID = 0,
20 SDT_ARG_SKIP,
21};
22
23int arch_sdt_arg_parse_op(char *old_op, char **new_op);
24
18#ifdef HAVE_PERF_REGS_SUPPORT 25#ifdef HAVE_PERF_REGS_SUPPORT
19#include <perf_regs.h> 26#include <perf_regs.h>
20 27
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 12f84dd2ac5d..ac16a9db1fb5 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1,6 +1,8 @@
1#include <linux/list.h> 1#include <linux/list.h>
2#include <linux/compiler.h> 2#include <linux/compiler.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <errno.h>
5#include <sys/stat.h>
4#include <unistd.h> 6#include <unistd.h>
5#include <stdio.h> 7#include <stdio.h>
6#include <stdbool.h> 8#include <stdbool.h>
@@ -15,6 +17,7 @@
15#include "header.h" 17#include "header.h"
16#include "pmu-events/pmu-events.h" 18#include "pmu-events/pmu-events.h"
17#include "cache.h" 19#include "cache.h"
20#include "string2.h"
18 21
19struct perf_pmu_format { 22struct perf_pmu_format {
20 char *name; 23 char *name;
@@ -231,7 +234,9 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias,
231static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, 234static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
232 char *desc, char *val, 235 char *desc, char *val,
233 char *long_desc, char *topic, 236 char *long_desc, char *topic,
234 char *unit, char *perpkg) 237 char *unit, char *perpkg,
238 char *metric_expr,
239 char *metric_name)
235{ 240{
236 struct perf_pmu_alias *alias; 241 struct perf_pmu_alias *alias;
237 int ret; 242 int ret;
@@ -265,6 +270,8 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
265 perf_pmu__parse_snapshot(alias, dir, name); 270 perf_pmu__parse_snapshot(alias, dir, name);
266 } 271 }
267 272
273 alias->metric_expr = metric_expr ? strdup(metric_expr) : NULL;
274 alias->metric_name = metric_name ? strdup(metric_name): NULL;
268 alias->desc = desc ? strdup(desc) : NULL; 275 alias->desc = desc ? strdup(desc) : NULL;
269 alias->long_desc = long_desc ? strdup(long_desc) : 276 alias->long_desc = long_desc ? strdup(long_desc) :
270 desc ? strdup(desc) : NULL; 277 desc ? strdup(desc) : NULL;
@@ -294,7 +301,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
294 buf[ret] = 0; 301 buf[ret] = 0;
295 302
296 return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL, 303 return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL,
297 NULL); 304 NULL, NULL, NULL);
298} 305}
299 306
300static inline bool pmu_alias_info_file(char *name) 307static inline bool pmu_alias_info_file(char *name)
@@ -564,7 +571,9 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
564 __perf_pmu__new_alias(head, NULL, (char *)pe->name, 571 __perf_pmu__new_alias(head, NULL, (char *)pe->name,
565 (char *)pe->desc, (char *)pe->event, 572 (char *)pe->desc, (char *)pe->event,
566 (char *)pe->long_desc, (char *)pe->topic, 573 (char *)pe->long_desc, (char *)pe->topic,
567 (char *)pe->unit, (char *)pe->perpkg); 574 (char *)pe->unit, (char *)pe->perpkg,
575 (char *)pe->metric_expr,
576 (char *)pe->metric_name);
568 } 577 }
569 578
570out: 579out:
@@ -991,6 +1000,8 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
991 info->unit = NULL; 1000 info->unit = NULL;
992 info->scale = 0.0; 1001 info->scale = 0.0;
993 info->snapshot = false; 1002 info->snapshot = false;
1003 info->metric_expr = NULL;
1004 info->metric_name = NULL;
994 1005
995 list_for_each_entry_safe(term, h, head_terms, list) { 1006 list_for_each_entry_safe(term, h, head_terms, list) {
996 alias = pmu_find_alias(pmu, term); 1007 alias = pmu_find_alias(pmu, term);
@@ -1006,6 +1017,8 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
1006 1017
1007 if (alias->per_pkg) 1018 if (alias->per_pkg)
1008 info->per_pkg = true; 1019 info->per_pkg = true;
1020 info->metric_expr = alias->metric_expr;
1021 info->metric_name = alias->metric_name;
1009 1022
1010 list_del(&term->list); 1023 list_del(&term->list);
1011 free(term); 1024 free(term);
@@ -1100,6 +1113,8 @@ struct sevent {
1100 char *topic; 1113 char *topic;
1101 char *str; 1114 char *str;
1102 char *pmu; 1115 char *pmu;
1116 char *metric_expr;
1117 char *metric_name;
1103}; 1118};
1104 1119
1105static int cmp_sevent(const void *a, const void *b) 1120static int cmp_sevent(const void *a, const void *b)
@@ -1136,13 +1151,12 @@ static void wordwrap(char *s, int start, int max, int corr)
1136 break; 1151 break;
1137 s += wlen; 1152 s += wlen;
1138 column += n; 1153 column += n;
1139 while (isspace(*s)) 1154 s = ltrim(s);
1140 s++;
1141 } 1155 }
1142} 1156}
1143 1157
1144void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag, 1158void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
1145 bool long_desc) 1159 bool long_desc, bool details_flag)
1146{ 1160{
1147 struct perf_pmu *pmu; 1161 struct perf_pmu *pmu;
1148 struct perf_pmu_alias *alias; 1162 struct perf_pmu_alias *alias;
@@ -1198,6 +1212,8 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
1198 aliases[j].topic = alias->topic; 1212 aliases[j].topic = alias->topic;
1199 aliases[j].str = alias->str; 1213 aliases[j].str = alias->str;
1200 aliases[j].pmu = pmu->name; 1214 aliases[j].pmu = pmu->name;
1215 aliases[j].metric_expr = alias->metric_expr;
1216 aliases[j].metric_name = alias->metric_name;
1201 j++; 1217 j++;
1202 } 1218 }
1203 if (pmu->selectable && 1219 if (pmu->selectable &&
@@ -1232,8 +1248,14 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
1232 printf("%*s", 8, "["); 1248 printf("%*s", 8, "[");
1233 wordwrap(aliases[j].desc, 8, columns, 0); 1249 wordwrap(aliases[j].desc, 8, columns, 0);
1234 printf("]\n"); 1250 printf("]\n");
1235 if (verbose > 0) 1251 if (details_flag) {
1236 printf("%*s%s/%s/\n", 8, "", aliases[j].pmu, aliases[j].str); 1252 printf("%*s%s/%s/ ", 8, "", aliases[j].pmu, aliases[j].str);
1253 if (aliases[j].metric_name)
1254 printf(" MetricName: %s", aliases[j].metric_name);
1255 if (aliases[j].metric_expr)
1256 printf(" MetricExpr: %s", aliases[j].metric_expr);
1257 putchar('\n');
1258 }
1237 } else 1259 } else
1238 printf(" %-50s [Kernel PMU event]\n", aliases[j].name); 1260 printf(" %-50s [Kernel PMU event]\n", aliases[j].name);
1239 printed++; 1261 printed++;
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 00852ddc7741..ea7f450dc609 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -31,6 +31,8 @@ struct perf_pmu {
31 31
32struct perf_pmu_info { 32struct perf_pmu_info {
33 const char *unit; 33 const char *unit;
34 const char *metric_expr;
35 const char *metric_name;
34 double scale; 36 double scale;
35 bool per_pkg; 37 bool per_pkg;
36 bool snapshot; 38 bool snapshot;
@@ -50,6 +52,8 @@ struct perf_pmu_alias {
50 double scale; 52 double scale;
51 bool per_pkg; 53 bool per_pkg;
52 bool snapshot; 54 bool snapshot;
55 char *metric_expr;
56 char *metric_name;
53}; 57};
54 58
55struct perf_pmu *perf_pmu__find(const char *name); 59struct perf_pmu *perf_pmu__find(const char *name);
@@ -76,7 +80,7 @@ int perf_pmu__format_parse(char *dir, struct list_head *head);
76struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu); 80struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
77 81
78void print_pmu_events(const char *event_glob, bool name_only, bool quiet, 82void print_pmu_events(const char *event_glob, bool name_only, bool quiet,
79 bool long_desc); 83 bool long_desc, bool details_flag);
80bool pmu_have_event(const char *pname, const char *name); 84bool pmu_have_event(const char *pname, const char *name);
81 85
82int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, 86int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
diff --git a/tools/perf/util/print_binary.c b/tools/perf/util/print_binary.c
new file mode 100644
index 000000000000..e908177b9976
--- /dev/null
+++ b/tools/perf/util/print_binary.c
@@ -0,0 +1,55 @@
1#include "print_binary.h"
2#include <linux/log2.h>
3#include "sane_ctype.h"
4
5void print_binary(unsigned char *data, size_t len,
6 size_t bytes_per_line, print_binary_t printer,
7 void *extra)
8{
9 size_t i, j, mask;
10
11 if (!printer)
12 return;
13
14 bytes_per_line = roundup_pow_of_two(bytes_per_line);
15 mask = bytes_per_line - 1;
16
17 printer(BINARY_PRINT_DATA_BEGIN, 0, extra);
18 for (i = 0; i < len; i++) {
19 if ((i & mask) == 0) {
20 printer(BINARY_PRINT_LINE_BEGIN, -1, extra);
21 printer(BINARY_PRINT_ADDR, i, extra);
22 }
23
24 printer(BINARY_PRINT_NUM_DATA, data[i], extra);
25
26 if (((i & mask) == mask) || i == len - 1) {
27 for (j = 0; j < mask-(i & mask); j++)
28 printer(BINARY_PRINT_NUM_PAD, -1, extra);
29
30 printer(BINARY_PRINT_SEP, i, extra);
31 for (j = i & ~mask; j <= i; j++)
32 printer(BINARY_PRINT_CHAR_DATA, data[j], extra);
33 for (j = 0; j < mask-(i & mask); j++)
34 printer(BINARY_PRINT_CHAR_PAD, i, extra);
35 printer(BINARY_PRINT_LINE_END, -1, extra);
36 }
37 }
38 printer(BINARY_PRINT_DATA_END, -1, extra);
39}
40
41int is_printable_array(char *p, unsigned int len)
42{
43 unsigned int i;
44
45 if (!p || !len || p[len - 1] != 0)
46 return 0;
47
48 len--;
49
50 for (i = 0; i < len; i++) {
51 if (!isprint(p[i]) && !isspace(p[i]))
52 return 0;
53 }
54 return 1;
55}
diff --git a/tools/perf/util/print_binary.h b/tools/perf/util/print_binary.h
new file mode 100644
index 000000000000..da0427263d2d
--- /dev/null
+++ b/tools/perf/util/print_binary.h
@@ -0,0 +1,28 @@
1#ifndef PERF_PRINT_BINARY_H
2#define PERF_PRINT_BINARY_H
3
4#include <stddef.h>
5
6enum binary_printer_ops {
7 BINARY_PRINT_DATA_BEGIN,
8 BINARY_PRINT_LINE_BEGIN,
9 BINARY_PRINT_ADDR,
10 BINARY_PRINT_NUM_DATA,
11 BINARY_PRINT_NUM_PAD,
12 BINARY_PRINT_SEP,
13 BINARY_PRINT_CHAR_DATA,
14 BINARY_PRINT_CHAR_PAD,
15 BINARY_PRINT_LINE_END,
16 BINARY_PRINT_DATA_END,
17};
18
19typedef void (*print_binary_t)(enum binary_printer_ops op,
20 unsigned int val, void *extra);
21
22void print_binary(unsigned char *data, size_t len,
23 size_t bytes_per_line, print_binary_t printer,
24 void *extra);
25
26int is_printable_array(char *p, unsigned int len);
27
28#endif /* PERF_PRINT_BINARY_H */
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 28fb62c32678..84e7e698411e 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -19,6 +19,7 @@
19 * 19 *
20 */ 20 */
21 21
22#include <inttypes.h>
22#include <sys/utsname.h> 23#include <sys/utsname.h>
23#include <sys/types.h> 24#include <sys/types.h>
24#include <sys/stat.h> 25#include <sys/stat.h>
@@ -35,6 +36,7 @@
35#include "util.h" 36#include "util.h"
36#include "event.h" 37#include "event.h"
37#include "strlist.h" 38#include "strlist.h"
39#include "strfilter.h"
38#include "debug.h" 40#include "debug.h"
39#include "cache.h" 41#include "cache.h"
40#include "color.h" 42#include "color.h"
@@ -46,8 +48,10 @@
46#include "probe-finder.h" 48#include "probe-finder.h"
47#include "probe-file.h" 49#include "probe-file.h"
48#include "session.h" 50#include "session.h"
51#include "string2.h"
52
53#include "sane_ctype.h"
49 54
50#define MAX_CMDLEN 256
51#define PERFPROBE_GROUP "probe" 55#define PERFPROBE_GROUP "probe"
52 56
53bool probe_event_dry_run; /* Dry run flag */ 57bool probe_event_dry_run; /* Dry run flag */
@@ -757,7 +761,9 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs,
757 } 761 }
758 762
759 for (i = 0; i < ntevs; i++) { 763 for (i = 0; i < ntevs; i++) {
760 if (!tevs[i].point.address || tevs[i].point.retprobe) 764 if (!tevs[i].point.address)
765 continue;
766 if (tevs[i].point.retprobe && !kretprobe_offset_is_supported())
761 continue; 767 continue;
762 /* If we found a wrong one, mark it by NULL symbol */ 768 /* If we found a wrong one, mark it by NULL symbol */
763 if (kprobe_warn_out_range(tevs[i].point.symbol, 769 if (kprobe_warn_out_range(tevs[i].point.symbol,
@@ -1339,14 +1345,7 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
1339 if (!arg) 1345 if (!arg)
1340 return -EINVAL; 1346 return -EINVAL;
1341 1347
1342 /* 1348 if (is_sdt_event(arg)) {
1343 * If the probe point starts with '%',
1344 * or starts with "sdt_" and has a ':' but no '=',
1345 * then it should be a SDT/cached probe point.
1346 */
1347 if (arg[0] == '%' ||
1348 (!strncmp(arg, "sdt_", 4) &&
1349 !!strchr(arg, ':') && !strchr(arg, '='))) {
1350 pev->sdt = true; 1349 pev->sdt = true;
1351 if (arg[0] == '%') 1350 if (arg[0] == '%')
1352 arg++; 1351 arg++;
@@ -1528,11 +1527,6 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
1528 return -EINVAL; 1527 return -EINVAL;
1529 } 1528 }
1530 1529
1531 if (pp->retprobe && !pp->function) {
1532 semantic_error("Return probe requires an entry function.\n");
1533 return -EINVAL;
1534 }
1535
1536 if ((pp->offset || pp->line || pp->lazy_line) && pp->retprobe) { 1530 if ((pp->offset || pp->line || pp->lazy_line) && pp->retprobe) {
1537 semantic_error("Offset/Line/Lazy pattern can't be used with " 1531 semantic_error("Offset/Line/Lazy pattern can't be used with "
1538 "return probe.\n"); 1532 "return probe.\n");
@@ -2841,7 +2835,8 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
2841 } 2835 }
2842 2836
2843 /* Note that the symbols in the kmodule are not relocated */ 2837 /* Note that the symbols in the kmodule are not relocated */
2844 if (!pev->uprobes && !pp->retprobe && !pev->target) { 2838 if (!pev->uprobes && !pev->target &&
2839 (!pp->retprobe || kretprobe_offset_is_supported())) {
2845 reloc_sym = kernel_get_ref_reloc_sym(); 2840 reloc_sym = kernel_get_ref_reloc_sym();
2846 if (!reloc_sym) { 2841 if (!reloc_sym) {
2847 pr_warning("Relocated base symbol is not found!\n"); 2842 pr_warning("Relocated base symbol is not found!\n");
@@ -3057,7 +3052,7 @@ concat_probe_trace_events(struct probe_trace_event **tevs, int *ntevs,
3057 struct probe_trace_event *new_tevs; 3052 struct probe_trace_event *new_tevs;
3058 int ret = 0; 3053 int ret = 0;
3059 3054
3060 if (ntevs == 0) { 3055 if (*ntevs == 0) {
3061 *tevs = *tevs2; 3056 *tevs = *tevs2;
3062 *ntevs = ntevs2; 3057 *ntevs = ntevs2;
3063 *tevs2 = NULL; 3058 *tevs2 = NULL;
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 5d4e94061402..373842656fb6 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -3,8 +3,6 @@
3 3
4#include <stdbool.h> 4#include <stdbool.h>
5#include "intlist.h" 5#include "intlist.h"
6#include "strlist.h"
7#include "strfilter.h"
8 6
9/* Probe related configurations */ 7/* Probe related configurations */
10struct probe_conf { 8struct probe_conf {
@@ -107,6 +105,8 @@ struct line_range {
107 struct intlist *line_list; /* Visible lines */ 105 struct intlist *line_list; /* Visible lines */
108}; 106};
109 107
108struct strlist;
109
110/* List of variables */ 110/* List of variables */
111struct variable_list { 111struct variable_list {
112 struct probe_trace_point point; /* Actual probepoint */ 112 struct probe_trace_point point; /* Actual probepoint */
@@ -153,6 +153,9 @@ int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs);
153int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs); 153int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs);
154int show_probe_trace_events(struct perf_probe_event *pevs, int npevs); 154int show_probe_trace_events(struct perf_probe_event *pevs, int npevs);
155void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs); 155void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs);
156
157struct strfilter;
158
156int del_perf_probe_events(struct strfilter *filter); 159int del_perf_probe_events(struct strfilter *filter);
157 160
158int show_perf_probe_event(const char *group, const char *event, 161int show_perf_probe_event(const char *group, const char *event,
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 436b64731f65..d679389e627c 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -14,10 +14,15 @@
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 */ 16 */
17#include <errno.h>
18#include <sys/stat.h>
19#include <sys/types.h>
17#include <sys/uio.h> 20#include <sys/uio.h>
21#include <unistd.h>
18#include "util.h" 22#include "util.h"
19#include "event.h" 23#include "event.h"
20#include "strlist.h" 24#include "strlist.h"
25#include "strfilter.h"
21#include "debug.h" 26#include "debug.h"
22#include "cache.h" 27#include "cache.h"
23#include "color.h" 28#include "color.h"
@@ -27,8 +32,11 @@
27#include "probe-event.h" 32#include "probe-event.h"
28#include "probe-file.h" 33#include "probe-file.h"
29#include "session.h" 34#include "session.h"
35#include "perf_regs.h"
36#include "string2.h"
30 37
31#define MAX_CMDLEN 256 38/* 4096 - 2 ('\n' + '\0') */
39#define MAX_CMDLEN 4094
32 40
33static void print_open_warning(int err, bool uprobe) 41static void print_open_warning(int err, bool uprobe)
34{ 42{
@@ -70,7 +78,7 @@ static void print_both_open_warning(int kerr, int uerr)
70 } 78 }
71} 79}
72 80
73static int open_probe_events(const char *trace_file, bool readwrite) 81int open_trace_file(const char *trace_file, bool readwrite)
74{ 82{
75 char buf[PATH_MAX]; 83 char buf[PATH_MAX];
76 int ret; 84 int ret;
@@ -92,12 +100,12 @@ static int open_probe_events(const char *trace_file, bool readwrite)
92 100
93static int open_kprobe_events(bool readwrite) 101static int open_kprobe_events(bool readwrite)
94{ 102{
95 return open_probe_events("kprobe_events", readwrite); 103 return open_trace_file("kprobe_events", readwrite);
96} 104}
97 105
98static int open_uprobe_events(bool readwrite) 106static int open_uprobe_events(bool readwrite)
99{ 107{
100 return open_probe_events("uprobe_events", readwrite); 108 return open_trace_file("uprobe_events", readwrite);
101} 109}
102 110
103int probe_file__open(int flag) 111int probe_file__open(int flag)
@@ -687,6 +695,110 @@ static unsigned long long sdt_note__get_addr(struct sdt_note *note)
687 : (unsigned long long)note->addr.a64[0]; 695 : (unsigned long long)note->addr.a64[0];
688} 696}
689 697
698static const char * const type_to_suffix[] = {
699 ":s64", "", "", "", ":s32", "", ":s16", ":s8",
700 "", ":u8", ":u16", "", ":u32", "", "", "", ":u64"
701};
702
703/*
704 * Isolate the string number and convert it into a decimal value;
705 * this will be an index to get suffix of the uprobe name (defining
706 * the type)
707 */
708static int sdt_arg_parse_size(char *n_ptr, const char **suffix)
709{
710 long type_idx;
711
712 type_idx = strtol(n_ptr, NULL, 10);
713 if (type_idx < -8 || type_idx > 8) {
714 pr_debug4("Failed to get a valid sdt type\n");
715 return -1;
716 }
717
718 *suffix = type_to_suffix[type_idx + 8];
719 return 0;
720}
721
722static int synthesize_sdt_probe_arg(struct strbuf *buf, int i, const char *arg)
723{
724 char *op, *desc = strdup(arg), *new_op = NULL;
725 const char *suffix = "";
726 int ret = -1;
727
728 if (desc == NULL) {
729 pr_debug4("Allocation error\n");
730 return ret;
731 }
732
733 /*
734 * Argument is in N@OP format. N is size of the argument and OP is
735 * the actual assembly operand. N can be omitted; in that case
736 * argument is just OP(without @).
737 */
738 op = strchr(desc, '@');
739 if (op) {
740 op[0] = '\0';
741 op++;
742
743 if (sdt_arg_parse_size(desc, &suffix))
744 goto error;
745 } else {
746 op = desc;
747 }
748
749 ret = arch_sdt_arg_parse_op(op, &new_op);
750
751 if (ret < 0)
752 goto error;
753
754 if (ret == SDT_ARG_VALID) {
755 ret = strbuf_addf(buf, " arg%d=%s%s", i + 1, new_op, suffix);
756 if (ret < 0)
757 goto error;
758 }
759
760 ret = 0;
761error:
762 free(desc);
763 free(new_op);
764 return ret;
765}
766
767static char *synthesize_sdt_probe_command(struct sdt_note *note,
768 const char *pathname,
769 const char *sdtgrp)
770{
771 struct strbuf buf;
772 char *ret = NULL, **args;
773 int i, args_count;
774
775 if (strbuf_init(&buf, 32) < 0)
776 return NULL;
777
778 if (strbuf_addf(&buf, "p:%s/%s %s:0x%llx",
779 sdtgrp, note->name, pathname,
780 sdt_note__get_addr(note)) < 0)
781 goto error;
782
783 if (!note->args)
784 goto out;
785
786 if (note->args) {
787 args = argv_split(note->args, &args_count);
788
789 for (i = 0; i < args_count; ++i) {
790 if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0)
791 goto error;
792 }
793 }
794
795out:
796 ret = strbuf_detach(&buf, NULL);
797error:
798 strbuf_release(&buf);
799 return ret;
800}
801
690int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname) 802int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname)
691{ 803{
692 struct probe_cache_entry *entry = NULL; 804 struct probe_cache_entry *entry = NULL;
@@ -723,11 +835,12 @@ int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname)
723 entry->pev.group = strdup(sdtgrp); 835 entry->pev.group = strdup(sdtgrp);
724 list_add_tail(&entry->node, &pcache->entries); 836 list_add_tail(&entry->node, &pcache->entries);
725 } 837 }
726 ret = asprintf(&buf, "p:%s/%s %s:0x%llx", 838 buf = synthesize_sdt_probe_command(note, pathname, sdtgrp);
727 sdtgrp, note->name, pathname, 839 if (!buf) {
728 sdt_note__get_addr(note)); 840 ret = -ENOMEM;
729 if (ret < 0)
730 break; 841 break;
842 }
843
731 strlist__add(entry->tevlist, buf); 844 strlist__add(entry->tevlist, buf);
732 free(buf); 845 free(buf);
733 entry = NULL; 846 entry = NULL;
@@ -877,59 +990,72 @@ int probe_cache__show_all_caches(struct strfilter *filter)
877 return 0; 990 return 0;
878} 991}
879 992
993enum ftrace_readme {
994 FTRACE_README_PROBE_TYPE_X = 0,
995 FTRACE_README_KRETPROBE_OFFSET,
996 FTRACE_README_END,
997};
998
880static struct { 999static struct {
881 const char *pattern; 1000 const char *pattern;
882 bool avail; 1001 bool avail;
883 bool checked; 1002} ftrace_readme_table[] = {
884} probe_type_table[] = { 1003#define DEFINE_TYPE(idx, pat) \
885#define DEFINE_TYPE(idx, pat, def_avail) \ 1004 [idx] = {.pattern = pat, .avail = false}
886 [idx] = {.pattern = pat, .avail = (def_avail)} 1005 DEFINE_TYPE(FTRACE_README_PROBE_TYPE_X, "*type: * x8/16/32/64,*"),
887 DEFINE_TYPE(PROBE_TYPE_U, "* u8/16/32/64,*", true), 1006 DEFINE_TYPE(FTRACE_README_KRETPROBE_OFFSET, "*place (kretprobe): *"),
888 DEFINE_TYPE(PROBE_TYPE_S, "* s8/16/32/64,*", true),
889 DEFINE_TYPE(PROBE_TYPE_X, "* x8/16/32/64,*", false),
890 DEFINE_TYPE(PROBE_TYPE_STRING, "* string,*", true),
891 DEFINE_TYPE(PROBE_TYPE_BITFIELD,
892 "* b<bit-width>@<bit-offset>/<container-size>", true),
893}; 1007};
894 1008
895bool probe_type_is_available(enum probe_type type) 1009static bool scan_ftrace_readme(enum ftrace_readme type)
896{ 1010{
1011 int fd;
897 FILE *fp; 1012 FILE *fp;
898 char *buf = NULL; 1013 char *buf = NULL;
899 size_t len = 0; 1014 size_t len = 0;
900 bool target_line = false; 1015 bool ret = false;
901 bool ret = probe_type_table[type].avail; 1016 static bool scanned = false;
902 1017
903 if (type >= PROBE_TYPE_END) 1018 if (scanned)
904 return false; 1019 goto result;
905 /* We don't have to check the type which supported by default */
906 if (ret || probe_type_table[type].checked)
907 return ret;
908 1020
909 if (asprintf(&buf, "%s/README", tracing_path) < 0) 1021 fd = open_trace_file("README", false);
1022 if (fd < 0)
910 return ret; 1023 return ret;
911 1024
912 fp = fopen(buf, "r"); 1025 fp = fdopen(fd, "r");
913 if (!fp) 1026 if (!fp) {
914 goto end; 1027 close(fd);
915 1028 return ret;
916 zfree(&buf);
917 while (getline(&buf, &len, fp) > 0 && !ret) {
918 if (!target_line) {
919 target_line = !!strstr(buf, " type: ");
920 if (!target_line)
921 continue;
922 } else if (strstr(buf, "\t ") != buf)
923 break;
924 ret = strglobmatch(buf, probe_type_table[type].pattern);
925 } 1029 }
926 /* Cache the result */ 1030
927 probe_type_table[type].checked = true; 1031 while (getline(&buf, &len, fp) > 0)
928 probe_type_table[type].avail = ret; 1032 for (enum ftrace_readme i = 0; i < FTRACE_README_END; i++)
1033 if (!ftrace_readme_table[i].avail)
1034 ftrace_readme_table[i].avail =
1035 strglobmatch(buf, ftrace_readme_table[i].pattern);
1036 scanned = true;
929 1037
930 fclose(fp); 1038 fclose(fp);
931end:
932 free(buf); 1039 free(buf);
933 1040
934 return ret; 1041result:
1042 if (type >= FTRACE_README_END)
1043 return false;
1044
1045 return ftrace_readme_table[type].avail;
1046}
1047
1048bool probe_type_is_available(enum probe_type type)
1049{
1050 if (type >= PROBE_TYPE_END)
1051 return false;
1052 else if (type == PROBE_TYPE_X)
1053 return scan_ftrace_readme(FTRACE_README_PROBE_TYPE_X);
1054
1055 return true;
1056}
1057
1058bool kretprobe_offset_is_supported(void)
1059{
1060 return scan_ftrace_readme(FTRACE_README_KRETPROBE_OFFSET);
935} 1061}
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
index eba44c3e9dca..5ecc9d3925db 100644
--- a/tools/perf/util/probe-file.h
+++ b/tools/perf/util/probe-file.h
@@ -1,10 +1,11 @@
1#ifndef __PROBE_FILE_H 1#ifndef __PROBE_FILE_H
2#define __PROBE_FILE_H 2#define __PROBE_FILE_H
3 3
4#include "strlist.h"
5#include "strfilter.h"
6#include "probe-event.h" 4#include "probe-event.h"
7 5
6struct strlist;
7struct strfilter;
8
8/* Cache of probe definitions */ 9/* Cache of probe definitions */
9struct probe_cache_entry { 10struct probe_cache_entry {
10 struct list_head node; 11 struct list_head node;
@@ -35,11 +36,13 @@ enum probe_type {
35 36
36/* probe-file.c depends on libelf */ 37/* probe-file.c depends on libelf */
37#ifdef HAVE_LIBELF_SUPPORT 38#ifdef HAVE_LIBELF_SUPPORT
39int open_trace_file(const char *trace_file, bool readwrite);
38int probe_file__open(int flag); 40int probe_file__open(int flag);
39int probe_file__open_both(int *kfd, int *ufd, int flag); 41int probe_file__open_both(int *kfd, int *ufd, int flag);
40struct strlist *probe_file__get_namelist(int fd); 42struct strlist *probe_file__get_namelist(int fd);
41struct strlist *probe_file__get_rawlist(int fd); 43struct strlist *probe_file__get_rawlist(int fd);
42int probe_file__add_event(int fd, struct probe_trace_event *tev); 44int probe_file__add_event(int fd, struct probe_trace_event *tev);
45
43int probe_file__del_events(int fd, struct strfilter *filter); 46int probe_file__del_events(int fd, struct strfilter *filter);
44int probe_file__get_events(int fd, struct strfilter *filter, 47int probe_file__get_events(int fd, struct strfilter *filter,
45 struct strlist *plist); 48 struct strlist *plist);
@@ -64,6 +67,7 @@ struct probe_cache_entry *probe_cache__find_by_name(struct probe_cache *pcache,
64 const char *group, const char *event); 67 const char *group, const char *event);
65int probe_cache__show_all_caches(struct strfilter *filter); 68int probe_cache__show_all_caches(struct strfilter *filter);
66bool probe_type_is_available(enum probe_type type); 69bool probe_type_is_available(enum probe_type type);
70bool kretprobe_offset_is_supported(void);
67#else /* ! HAVE_LIBELF_SUPPORT */ 71#else /* ! HAVE_LIBELF_SUPPORT */
68static inline struct probe_cache *probe_cache__new(const char *tgt __maybe_unused) 72static inline struct probe_cache *probe_cache__new(const char *tgt __maybe_unused)
69{ 73{
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 57cd268d4275..a5731de0e5eb 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -19,6 +19,7 @@
19 * 19 *
20 */ 20 */
21 21
22#include <inttypes.h>
22#include <sys/utsname.h> 23#include <sys/utsname.h>
23#include <sys/types.h> 24#include <sys/types.h>
24#include <sys/stat.h> 25#include <sys/stat.h>
@@ -37,9 +38,11 @@
37#include "debug.h" 38#include "debug.h"
38#include "intlist.h" 39#include "intlist.h"
39#include "util.h" 40#include "util.h"
41#include "strlist.h"
40#include "symbol.h" 42#include "symbol.h"
41#include "probe-finder.h" 43#include "probe-finder.h"
42#include "probe-file.h" 44#include "probe-file.h"
45#include "string2.h"
43 46
44/* Kprobe tracer basic type is up to u64 */ 47/* Kprobe tracer basic type is up to u64 */
45#define MAX_BASIC_TYPE_BITS 64 48#define MAX_BASIC_TYPE_BITS 64
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index 2956c5198652..27f061551012 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -2,9 +2,9 @@
2#define _PROBE_FINDER_H 2#define _PROBE_FINDER_H
3 3
4#include <stdbool.h> 4#include <stdbool.h>
5#include "util.h"
6#include "intlist.h" 5#include "intlist.h"
7#include "probe-event.h" 6#include "probe-event.h"
7#include "sane_ctype.h"
8 8
9#define MAX_PROBE_BUFFER 1024 9#define MAX_PROBE_BUFFER 1024
10#define MAX_PROBES 128 10#define MAX_PROBES 128
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index 0546a4304347..9f3b0d9754a8 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -21,8 +21,10 @@ util/cgroup.c
21util/parse-branch-options.c 21util/parse-branch-options.c
22util/rblist.c 22util/rblist.c
23util/counts.c 23util/counts.c
24util/print_binary.c
24util/strlist.c 25util/strlist.c
25util/trace-event.c 26util/trace-event.c
26../lib/rbtree.c 27../lib/rbtree.c
27util/string.c 28util/string.c
28util/symbol_fprintf.c 29util/symbol_fprintf.c
30util/units.c
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index a5fbc012e3df..c129e99114ae 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -4,12 +4,26 @@
4#include <poll.h> 4#include <poll.h>
5#include <linux/err.h> 5#include <linux/err.h>
6#include "evlist.h" 6#include "evlist.h"
7#include "callchain.h"
7#include "evsel.h" 8#include "evsel.h"
8#include "event.h" 9#include "event.h"
9#include "cpumap.h" 10#include "cpumap.h"
11#include "print_binary.h"
10#include "thread_map.h" 12#include "thread_map.h"
11 13
12/* 14/*
15 * Provide these two so that we don't have to link against callchain.c and
16 * start dragging hist.c, etc.
17 */
18struct callchain_param callchain_param;
19
20int parse_callchain_record(const char *arg __maybe_unused,
21 struct callchain_param *param __maybe_unused)
22{
23 return 0;
24}
25
26/*
13 * Support debug printing even though util/debug.c is not linked. That means 27 * Support debug printing even though util/debug.c is not linked. That means
14 * implementing 'verbose' and 'eprintf'. 28 * implementing 'verbose' and 'eprintf'.
15 */ 29 */
diff --git a/tools/perf/util/quote.c b/tools/perf/util/quote.c
index 293534c1a474..1ba8920151d8 100644
--- a/tools/perf/util/quote.c
+++ b/tools/perf/util/quote.c
@@ -1,3 +1,4 @@
1#include <errno.h>
1#include <stdlib.h> 2#include <stdlib.h>
2#include "strbuf.h" 3#include "strbuf.h"
3#include "quote.h" 4#include "quote.h"
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 98bf584853ea..d91bdf5a1aa4 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -2,6 +2,7 @@
2#include "evsel.h" 2#include "evsel.h"
3#include "cpumap.h" 3#include "cpumap.h"
4#include "parse-events.h" 4#include "parse-events.h"
5#include <errno.h>
5#include <api/fs/fs.h> 6#include <api/fs/fs.h>
6#include "util.h" 7#include "util.h"
7#include "cloexec.h" 8#include "cloexec.h"
diff --git a/tools/perf/util/sane_ctype.h b/tools/perf/util/sane_ctype.h
new file mode 100644
index 000000000000..4308c22c22ad
--- /dev/null
+++ b/tools/perf/util/sane_ctype.h
@@ -0,0 +1,51 @@
1#ifndef _PERF_SANE_CTYPE_H
2#define _PERF_SANE_CTYPE_H
3
4extern const char *graph_line;
5extern const char *graph_dotted_line;
6extern const char *spaces;
7extern const char *dots;
8
9/* Sane ctype - no locale, and works with signed chars */
10#undef isascii
11#undef isspace
12#undef isdigit
13#undef isxdigit
14#undef isalpha
15#undef isprint
16#undef isalnum
17#undef islower
18#undef isupper
19#undef tolower
20#undef toupper
21
22extern unsigned char sane_ctype[256];
23#define GIT_SPACE 0x01
24#define GIT_DIGIT 0x02
25#define GIT_ALPHA 0x04
26#define GIT_GLOB_SPECIAL 0x08
27#define GIT_REGEX_SPECIAL 0x10
28#define GIT_PRINT_EXTRA 0x20
29#define GIT_PRINT 0x3E
30#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
31#define isascii(x) (((x) & ~0x7f) == 0)
32#define isspace(x) sane_istest(x,GIT_SPACE)
33#define isdigit(x) sane_istest(x,GIT_DIGIT)
34#define isxdigit(x) \
35 (sane_istest(toupper(x), GIT_ALPHA | GIT_DIGIT) && toupper(x) < 'G')
36#define isalpha(x) sane_istest(x,GIT_ALPHA)
37#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
38#define isprint(x) sane_istest(x,GIT_PRINT)
39#define islower(x) (sane_istest(x,GIT_ALPHA) && (x & 0x20))
40#define isupper(x) (sane_istest(x,GIT_ALPHA) && !(x & 0x20))
41#define tolower(x) sane_case((unsigned char)(x), 0x20)
42#define toupper(x) sane_case((unsigned char)(x), 0)
43
44static inline int sane_case(int x, int high)
45{
46 if (sane_istest(x, GIT_ALPHA))
47 x = (x & ~0x20) | high;
48 return x;
49}
50
51#endif /* _PERF_SANE_CTYPE_H */
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index dff043a29589..2b12bdb3ce33 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -19,6 +19,7 @@
19 * 19 *
20 */ 20 */
21 21
22#include <inttypes.h>
22#include <stdio.h> 23#include <stdio.h>
23#include <stdlib.h> 24#include <stdlib.h>
24#include <string.h> 25#include <string.h>
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 783326cfbaa6..9d92af7d0718 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -21,6 +21,7 @@
21 21
22#include <Python.h> 22#include <Python.h>
23 23
24#include <inttypes.h>
24#include <stdio.h> 25#include <stdio.h>
25#include <stdlib.h> 26#include <stdlib.h>
26#include <string.h> 27#include <string.h>
@@ -45,6 +46,7 @@
45#include "../call-path.h" 46#include "../call-path.h"
46#include "thread_map.h" 47#include "thread_map.h"
47#include "cpumap.h" 48#include "cpumap.h"
49#include "print_binary.h"
48#include "stat.h" 50#include "stat.h"
49 51
50PyMODINIT_FUNC initperf_trace_context(void); 52PyMODINIT_FUNC initperf_trace_context(void);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 1dd617d116b5..3041c6b98191 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1,5 +1,8 @@
1#include <errno.h>
2#include <inttypes.h>
1#include <linux/kernel.h> 3#include <linux/kernel.h>
2#include <traceevent/event-parse.h> 4#include <traceevent/event-parse.h>
5#include <api/fs/fs.h>
3 6
4#include <byteswap.h> 7#include <byteswap.h>
5#include <unistd.h> 8#include <unistd.h>
@@ -16,6 +19,7 @@
16#include "perf_regs.h" 19#include "perf_regs.h"
17#include "asm/bug.h" 20#include "asm/bug.h"
18#include "auxtrace.h" 21#include "auxtrace.h"
22#include "thread.h"
19#include "thread-stack.h" 23#include "thread-stack.h"
20#include "stat.h" 24#include "stat.h"
21 25
@@ -139,8 +143,14 @@ struct perf_session *perf_session__new(struct perf_data_file *file,
139 if (perf_session__open(session) < 0) 143 if (perf_session__open(session) < 0)
140 goto out_close; 144 goto out_close;
141 145
142 perf_session__set_id_hdr_size(session); 146 /*
143 perf_session__set_comm_exec(session); 147 * set session attributes that are present in perf.data
148 * but not in pipe-mode.
149 */
150 if (!file->is_pipe) {
151 perf_session__set_id_hdr_size(session);
152 perf_session__set_comm_exec(session);
153 }
144 } 154 }
145 } else { 155 } else {
146 session->machines.host.env = &perf_env; 156 session->machines.host.env = &perf_env;
@@ -155,7 +165,11 @@ struct perf_session *perf_session__new(struct perf_data_file *file,
155 pr_warning("Cannot read kernel map\n"); 165 pr_warning("Cannot read kernel map\n");
156 } 166 }
157 167
158 if (tool && tool->ordering_requires_timestamps && 168 /*
169 * In pipe-mode, evlist is empty until PERF_RECORD_HEADER_ATTR is
170 * processed, so perf_evlist__sample_id_all is not meaningful here.
171 */
172 if ((!file || !file->is_pipe) && tool && tool->ordering_requires_timestamps &&
159 tool->ordered_events && !perf_evlist__sample_id_all(session->evlist)) { 173 tool->ordered_events && !perf_evlist__sample_id_all(session->evlist)) {
160 dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n"); 174 dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n");
161 tool->ordered_events = false; 175 tool->ordered_events = false;
@@ -1239,6 +1253,8 @@ static int machines__deliver_event(struct machines *machines,
1239 return tool->mmap2(tool, event, sample, machine); 1253 return tool->mmap2(tool, event, sample, machine);
1240 case PERF_RECORD_COMM: 1254 case PERF_RECORD_COMM:
1241 return tool->comm(tool, event, sample, machine); 1255 return tool->comm(tool, event, sample, machine);
1256 case PERF_RECORD_NAMESPACES:
1257 return tool->namespaces(tool, event, sample, machine);
1242 case PERF_RECORD_FORK: 1258 case PERF_RECORD_FORK:
1243 return tool->fork(tool, event, sample, machine); 1259 return tool->fork(tool, event, sample, machine);
1244 case PERF_RECORD_EXIT: 1260 case PERF_RECORD_EXIT:
@@ -1258,9 +1274,12 @@ static int machines__deliver_event(struct machines *machines,
1258 case PERF_RECORD_UNTHROTTLE: 1274 case PERF_RECORD_UNTHROTTLE:
1259 return tool->unthrottle(tool, event, sample, machine); 1275 return tool->unthrottle(tool, event, sample, machine);
1260 case PERF_RECORD_AUX: 1276 case PERF_RECORD_AUX:
1261 if (tool->aux == perf_event__process_aux && 1277 if (tool->aux == perf_event__process_aux) {
1262 (event->aux.flags & PERF_AUX_FLAG_TRUNCATED)) 1278 if (event->aux.flags & PERF_AUX_FLAG_TRUNCATED)
1263 evlist->stats.total_aux_lost += 1; 1279 evlist->stats.total_aux_lost += 1;
1280 if (event->aux.flags & PERF_AUX_FLAG_PARTIAL)
1281 evlist->stats.total_aux_partial += 1;
1282 }
1264 return tool->aux(tool, event, sample, machine); 1283 return tool->aux(tool, event, sample, machine);
1265 case PERF_RECORD_ITRACE_START: 1284 case PERF_RECORD_ITRACE_START:
1266 return tool->itrace_start(tool, event, sample, machine); 1285 return tool->itrace_start(tool, event, sample, machine);
@@ -1494,6 +1513,11 @@ int perf_session__register_idle_thread(struct perf_session *session)
1494 err = -1; 1513 err = -1;
1495 } 1514 }
1496 1515
1516 if (thread == NULL || thread__set_namespaces(thread, 0, NULL)) {
1517 pr_err("problem inserting idle task.\n");
1518 err = -1;
1519 }
1520
1497 /* machine__findnew_thread() got the thread, so put it */ 1521 /* machine__findnew_thread() got the thread, so put it */
1498 thread__put(thread); 1522 thread__put(thread);
1499 return err; 1523 return err;
@@ -1548,6 +1572,23 @@ static void perf_session__warn_about_errors(const struct perf_session *session)
1548 stats->nr_events[PERF_RECORD_AUX]); 1572 stats->nr_events[PERF_RECORD_AUX]);
1549 } 1573 }
1550 1574
1575 if (session->tool->aux == perf_event__process_aux &&
1576 stats->total_aux_partial != 0) {
1577 bool vmm_exclusive = false;
1578
1579 (void)sysfs__read_bool("module/kvm_intel/parameters/vmm_exclusive",
1580 &vmm_exclusive);
1581
1582 ui__warning("AUX data had gaps in it %" PRIu64 " times out of %u!\n\n"
1583 "Are you running a KVM guest in the background?%s\n\n",
1584 stats->total_aux_partial,
1585 stats->nr_events[PERF_RECORD_AUX],
1586 vmm_exclusive ?
1587 "\nReloading kvm_intel module with vmm_exclusive=0\n"
1588 "will reduce the gaps to only guest's timeslices." :
1589 "");
1590 }
1591
1551 if (stats->nr_unknown_events != 0) { 1592 if (stats->nr_unknown_events != 0) {
1552 ui__warning("Found %u unknown events!\n\n" 1593 ui__warning("Found %u unknown events!\n\n"
1553 "Is this an older tool processing a perf.data " 1594 "Is this an older tool processing a perf.data "
@@ -1628,6 +1669,7 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
1628 buf = malloc(cur_size); 1669 buf = malloc(cur_size);
1629 if (!buf) 1670 if (!buf)
1630 return -errno; 1671 return -errno;
1672 ordered_events__set_copy_on_queue(oe, true);
1631more: 1673more:
1632 event = buf; 1674 event = buf;
1633 err = readn(fd, event, sizeof(struct perf_event_header)); 1675 err = readn(fd, event, sizeof(struct perf_event_header));
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 4bd758553450..47b5e7dbcb18 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -5,14 +5,14 @@
5#include "event.h" 5#include "event.h"
6#include "header.h" 6#include "header.h"
7#include "machine.h" 7#include "machine.h"
8#include "symbol.h"
9#include "thread.h"
10#include "data.h" 8#include "data.h"
11#include "ordered-events.h" 9#include "ordered-events.h"
10#include <linux/kernel.h>
12#include <linux/rbtree.h> 11#include <linux/rbtree.h>
13#include <linux/perf_event.h> 12#include <linux/perf_event.h>
14 13
15struct ip_callchain; 14struct ip_callchain;
15struct symbol;
16struct thread; 16struct thread;
17 17
18struct auxtrace; 18struct auxtrace;
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 0ff622288d24..5762ae4e9e91 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1,12 +1,18 @@
1#include <errno.h>
2#include <inttypes.h>
3#include <regex.h>
1#include <sys/mman.h> 4#include <sys/mman.h>
2#include "sort.h" 5#include "sort.h"
3#include "hist.h" 6#include "hist.h"
4#include "comm.h" 7#include "comm.h"
5#include "symbol.h" 8#include "symbol.h"
9#include "thread.h"
6#include "evsel.h" 10#include "evsel.h"
7#include "evlist.h" 11#include "evlist.h"
12#include "strlist.h"
8#include <traceevent/event-parse.h> 13#include <traceevent/event-parse.h>
9#include "mem-events.h" 14#include "mem-events.h"
15#include <linux/kernel.h>
10 16
11regex_t parent_regex; 17regex_t parent_regex;
12const char default_parent_pattern[] = "^sys_|^do_page_fault"; 18const char default_parent_pattern[] = "^sys_|^do_page_fault";
@@ -323,7 +329,7 @@ char *hist_entry__get_srcline(struct hist_entry *he)
323 return SRCLINE_UNKNOWN; 329 return SRCLINE_UNKNOWN;
324 330
325 return get_srcline(map->dso, map__rip_2objdump(map, he->ip), 331 return get_srcline(map->dso, map__rip_2objdump(map, he->ip),
326 he->ms.sym, true); 332 he->ms.sym, true, true);
327} 333}
328 334
329static int64_t 335static int64_t
@@ -366,7 +372,8 @@ sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right)
366 left->branch_info->srcline_from = get_srcline(map->dso, 372 left->branch_info->srcline_from = get_srcline(map->dso,
367 map__rip_2objdump(map, 373 map__rip_2objdump(map,
368 left->branch_info->from.al_addr), 374 left->branch_info->from.al_addr),
369 left->branch_info->from.sym, true); 375 left->branch_info->from.sym,
376 true, true);
370 } 377 }
371 if (!right->branch_info->srcline_from) { 378 if (!right->branch_info->srcline_from) {
372 struct map *map = right->branch_info->from.map; 379 struct map *map = right->branch_info->from.map;
@@ -376,7 +383,8 @@ sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right)
376 right->branch_info->srcline_from = get_srcline(map->dso, 383 right->branch_info->srcline_from = get_srcline(map->dso,
377 map__rip_2objdump(map, 384 map__rip_2objdump(map,
378 right->branch_info->from.al_addr), 385 right->branch_info->from.al_addr),
379 right->branch_info->from.sym, true); 386 right->branch_info->from.sym,
387 true, true);
380 } 388 }
381 return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from); 389 return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from);
382} 390}
@@ -407,7 +415,8 @@ sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right)
407 left->branch_info->srcline_to = get_srcline(map->dso, 415 left->branch_info->srcline_to = get_srcline(map->dso,
408 map__rip_2objdump(map, 416 map__rip_2objdump(map,
409 left->branch_info->to.al_addr), 417 left->branch_info->to.al_addr),
410 left->branch_info->from.sym, true); 418 left->branch_info->from.sym,
419 true, true);
411 } 420 }
412 if (!right->branch_info->srcline_to) { 421 if (!right->branch_info->srcline_to) {
413 struct map *map = right->branch_info->to.map; 422 struct map *map = right->branch_info->to.map;
@@ -417,7 +426,8 @@ sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right)
417 right->branch_info->srcline_to = get_srcline(map->dso, 426 right->branch_info->srcline_to = get_srcline(map->dso,
418 map__rip_2objdump(map, 427 map__rip_2objdump(map,
419 right->branch_info->to.al_addr), 428 right->branch_info->to.al_addr),
420 right->branch_info->to.sym, true); 429 right->branch_info->to.sym,
430 true, true);
421 } 431 }
422 return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to); 432 return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to);
423} 433}
@@ -448,7 +458,7 @@ static char *hist_entry__get_srcfile(struct hist_entry *e)
448 return no_srcfile; 458 return no_srcfile;
449 459
450 sf = __get_srcline(map->dso, map__rip_2objdump(map, e->ip), 460 sf = __get_srcline(map->dso, map__rip_2objdump(map, e->ip),
451 e->ms.sym, false, true); 461 e->ms.sym, false, true, true);
452 if (!strcmp(sf, SRCLINE_UNKNOWN)) 462 if (!strcmp(sf, SRCLINE_UNKNOWN))
453 return no_srcfile; 463 return no_srcfile;
454 p = strchr(sf, ':'); 464 p = strchr(sf, ':');
@@ -536,6 +546,46 @@ struct sort_entry sort_cpu = {
536 .se_width_idx = HISTC_CPU, 546 .se_width_idx = HISTC_CPU,
537}; 547};
538 548
549/* --sort cgroup_id */
550
551static int64_t _sort__cgroup_dev_cmp(u64 left_dev, u64 right_dev)
552{
553 return (int64_t)(right_dev - left_dev);
554}
555
556static int64_t _sort__cgroup_inode_cmp(u64 left_ino, u64 right_ino)
557{
558 return (int64_t)(right_ino - left_ino);
559}
560
561static int64_t
562sort__cgroup_id_cmp(struct hist_entry *left, struct hist_entry *right)
563{
564 int64_t ret;
565
566 ret = _sort__cgroup_dev_cmp(right->cgroup_id.dev, left->cgroup_id.dev);
567 if (ret != 0)
568 return ret;
569
570 return _sort__cgroup_inode_cmp(right->cgroup_id.ino,
571 left->cgroup_id.ino);
572}
573
574static int hist_entry__cgroup_id_snprintf(struct hist_entry *he,
575 char *bf, size_t size,
576 unsigned int width __maybe_unused)
577{
578 return repsep_snprintf(bf, size, "%lu/0x%lx", he->cgroup_id.dev,
579 he->cgroup_id.ino);
580}
581
582struct sort_entry sort_cgroup_id = {
583 .se_header = "cgroup id (dev/inode)",
584 .se_cmp = sort__cgroup_id_cmp,
585 .se_snprintf = hist_entry__cgroup_id_snprintf,
586 .se_width_idx = HISTC_CGROUP_ID,
587};
588
539/* --sort socket */ 589/* --sort socket */
540 590
541static int64_t 591static int64_t
@@ -846,6 +896,9 @@ static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf,
846static int64_t 896static int64_t
847sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right) 897sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
848{ 898{
899 if (!left->branch_info || !right->branch_info)
900 return cmp_null(left->branch_info, right->branch_info);
901
849 return left->branch_info->flags.cycles - 902 return left->branch_info->flags.cycles -
850 right->branch_info->flags.cycles; 903 right->branch_info->flags.cycles;
851} 904}
@@ -853,6 +906,8 @@ sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
853static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf, 906static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf,
854 size_t size, unsigned int width) 907 size_t size, unsigned int width)
855{ 908{
909 if (!he->branch_info)
910 return scnprintf(bf, size, "%-.*s", width, "N/A");
856 if (he->branch_info->flags.cycles == 0) 911 if (he->branch_info->flags.cycles == 0)
857 return repsep_snprintf(bf, size, "%-*s", width, "-"); 912 return repsep_snprintf(bf, size, "%-*s", width, "-");
858 return repsep_snprintf(bf, size, "%-*hd", width, 913 return repsep_snprintf(bf, size, "%-*hd", width,
@@ -1396,6 +1451,46 @@ struct sort_entry sort_transaction = {
1396 .se_width_idx = HISTC_TRANSACTION, 1451 .se_width_idx = HISTC_TRANSACTION,
1397}; 1452};
1398 1453
1454/* --sort symbol_size */
1455
1456static int64_t _sort__sym_size_cmp(struct symbol *sym_l, struct symbol *sym_r)
1457{
1458 int64_t size_l = sym_l != NULL ? symbol__size(sym_l) : 0;
1459 int64_t size_r = sym_r != NULL ? symbol__size(sym_r) : 0;
1460
1461 return size_l < size_r ? -1 :
1462 size_l == size_r ? 0 : 1;
1463}
1464
1465static int64_t
1466sort__sym_size_cmp(struct hist_entry *left, struct hist_entry *right)
1467{
1468 return _sort__sym_size_cmp(right->ms.sym, left->ms.sym);
1469}
1470
1471static int _hist_entry__sym_size_snprintf(struct symbol *sym, char *bf,
1472 size_t bf_size, unsigned int width)
1473{
1474 if (sym)
1475 return repsep_snprintf(bf, bf_size, "%*d", width, symbol__size(sym));
1476
1477 return repsep_snprintf(bf, bf_size, "%*s", width, "unknown");
1478}
1479
1480static int hist_entry__sym_size_snprintf(struct hist_entry *he, char *bf,
1481 size_t size, unsigned int width)
1482{
1483 return _hist_entry__sym_size_snprintf(he->ms.sym, bf, size, width);
1484}
1485
1486struct sort_entry sort_sym_size = {
1487 .se_header = "Symbol size",
1488 .se_cmp = sort__sym_size_cmp,
1489 .se_snprintf = hist_entry__sym_size_snprintf,
1490 .se_width_idx = HISTC_SYM_SIZE,
1491};
1492
1493
1399struct sort_dimension { 1494struct sort_dimension {
1400 const char *name; 1495 const char *name;
1401 struct sort_entry *entry; 1496 struct sort_entry *entry;
@@ -1418,6 +1513,8 @@ static struct sort_dimension common_sort_dimensions[] = {
1418 DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight), 1513 DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
1419 DIM(SORT_TRANSACTION, "transaction", sort_transaction), 1514 DIM(SORT_TRANSACTION, "transaction", sort_transaction),
1420 DIM(SORT_TRACE, "trace", sort_trace), 1515 DIM(SORT_TRACE, "trace", sort_trace),
1516 DIM(SORT_SYM_SIZE, "symbol_size", sort_sym_size),
1517 DIM(SORT_CGROUP_ID, "cgroup_id", sort_cgroup_id),
1421}; 1518};
1422 1519
1423#undef DIM 1520#undef DIM
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 796c847e2f00..b7c75597e18f 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -2,7 +2,7 @@
2#define __PERF_SORT_H 2#define __PERF_SORT_H
3#include "../builtin.h" 3#include "../builtin.h"
4 4
5#include "util.h" 5#include <regex.h>
6 6
7#include "color.h" 7#include "color.h"
8#include <linux/list.h> 8#include <linux/list.h>
@@ -11,7 +11,6 @@
11#include "symbol.h" 11#include "symbol.h"
12#include "string.h" 12#include "string.h"
13#include "callchain.h" 13#include "callchain.h"
14#include "strlist.h"
15#include "values.h" 14#include "values.h"
16 15
17#include "../perf.h" 16#include "../perf.h"
@@ -21,7 +20,9 @@
21#include <subcmd/parse-options.h> 20#include <subcmd/parse-options.h>
22#include "parse-events.h" 21#include "parse-events.h"
23#include "hist.h" 22#include "hist.h"
24#include "thread.h" 23#include "srcline.h"
24
25struct thread;
25 26
26extern regex_t parent_regex; 27extern regex_t parent_regex;
27extern const char *sort_order; 28extern const char *sort_order;
@@ -54,6 +55,11 @@ struct he_stat {
54 u32 nr_events; 55 u32 nr_events;
55}; 56};
56 57
58struct namespace_id {
59 u64 dev;
60 u64 ino;
61};
62
57struct hist_entry_diff { 63struct hist_entry_diff {
58 bool computed; 64 bool computed;
59 union { 65 union {
@@ -91,6 +97,7 @@ struct hist_entry {
91 struct map_symbol ms; 97 struct map_symbol ms;
92 struct thread *thread; 98 struct thread *thread;
93 struct comm *comm; 99 struct comm *comm;
100 struct namespace_id cgroup_id;
94 u64 ip; 101 u64 ip;
95 u64 transaction; 102 u64 transaction;
96 s32 socket; 103 s32 socket;
@@ -122,6 +129,7 @@ struct hist_entry {
122 }; 129 };
123 char *srcline; 130 char *srcline;
124 char *srcfile; 131 char *srcfile;
132 struct inline_node *inline_node;
125 struct symbol *parent; 133 struct symbol *parent;
126 struct branch_info *branch_info; 134 struct branch_info *branch_info;
127 struct hists *hists; 135 struct hists *hists;
@@ -211,6 +219,8 @@ enum sort_type {
211 SORT_GLOBAL_WEIGHT, 219 SORT_GLOBAL_WEIGHT,
212 SORT_TRANSACTION, 220 SORT_TRANSACTION,
213 SORT_TRACE, 221 SORT_TRACE,
222 SORT_SYM_SIZE,
223 SORT_CGROUP_ID,
214 224
215 /* branch stack specific sort keys */ 225 /* branch stack specific sort keys */
216 __SORT_BRANCH_STACK, 226 __SORT_BRANCH_STACK,
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index b4db3f48e3b0..df051a52393c 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -1,3 +1,4 @@
1#include <inttypes.h>
1#include <stdio.h> 2#include <stdio.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <string.h> 4#include <string.h>
@@ -7,11 +8,59 @@
7#include "util/dso.h" 8#include "util/dso.h"
8#include "util/util.h" 9#include "util/util.h"
9#include "util/debug.h" 10#include "util/debug.h"
11#include "util/callchain.h"
12#include "srcline.h"
10 13
11#include "symbol.h" 14#include "symbol.h"
12 15
13bool srcline_full_filename; 16bool srcline_full_filename;
14 17
18static const char *dso__name(struct dso *dso)
19{
20 const char *dso_name;
21
22 if (dso->symsrc_filename)
23 dso_name = dso->symsrc_filename;
24 else
25 dso_name = dso->long_name;
26
27 if (dso_name[0] == '[')
28 return NULL;
29
30 if (!strncmp(dso_name, "/tmp/perf-", 10))
31 return NULL;
32
33 return dso_name;
34}
35
36static int inline_list__append(char *filename, char *funcname, int line_nr,
37 struct inline_node *node, struct dso *dso)
38{
39 struct inline_list *ilist;
40 char *demangled;
41
42 ilist = zalloc(sizeof(*ilist));
43 if (ilist == NULL)
44 return -1;
45
46 ilist->filename = filename;
47 ilist->line_nr = line_nr;
48
49 if (dso != NULL) {
50 demangled = dso__demangle_sym(dso, 0, funcname);
51 if (demangled == NULL) {
52 ilist->funcname = funcname;
53 } else {
54 ilist->funcname = demangled;
55 free(funcname);
56 }
57 }
58
59 list_add_tail(&ilist->list, &node->val);
60
61 return 0;
62}
63
15#ifdef HAVE_LIBBFD_SUPPORT 64#ifdef HAVE_LIBBFD_SUPPORT
16 65
17/* 66/*
@@ -151,9 +200,17 @@ static void addr2line_cleanup(struct a2l_data *a2l)
151 200
152#define MAX_INLINE_NEST 1024 201#define MAX_INLINE_NEST 1024
153 202
203static void inline_list__reverse(struct inline_node *node)
204{
205 struct inline_list *ilist, *n;
206
207 list_for_each_entry_safe_reverse(ilist, n, &node->val, list)
208 list_move_tail(&ilist->list, &node->val);
209}
210
154static int addr2line(const char *dso_name, u64 addr, 211static int addr2line(const char *dso_name, u64 addr,
155 char **file, unsigned int *line, struct dso *dso, 212 char **file, unsigned int *line, struct dso *dso,
156 bool unwind_inlines) 213 bool unwind_inlines, struct inline_node *node)
157{ 214{
158 int ret = 0; 215 int ret = 0;
159 struct a2l_data *a2l = dso->a2l; 216 struct a2l_data *a2l = dso->a2l;
@@ -178,8 +235,21 @@ static int addr2line(const char *dso_name, u64 addr,
178 235
179 while (bfd_find_inliner_info(a2l->abfd, &a2l->filename, 236 while (bfd_find_inliner_info(a2l->abfd, &a2l->filename,
180 &a2l->funcname, &a2l->line) && 237 &a2l->funcname, &a2l->line) &&
181 cnt++ < MAX_INLINE_NEST) 238 cnt++ < MAX_INLINE_NEST) {
182 ; 239
240 if (node != NULL) {
241 if (inline_list__append(strdup(a2l->filename),
242 strdup(a2l->funcname),
243 a2l->line, node,
244 dso) != 0)
245 return 0;
246 }
247 }
248
249 if ((node != NULL) &&
250 (callchain_param.order != ORDER_CALLEE)) {
251 inline_list__reverse(node);
252 }
183 } 253 }
184 254
185 if (a2l->found && a2l->filename) { 255 if (a2l->found && a2l->filename) {
@@ -205,18 +275,68 @@ void dso__free_a2l(struct dso *dso)
205 dso->a2l = NULL; 275 dso->a2l = NULL;
206} 276}
207 277
278static struct inline_node *addr2inlines(const char *dso_name, u64 addr,
279 struct dso *dso)
280{
281 char *file = NULL;
282 unsigned int line = 0;
283 struct inline_node *node;
284
285 node = zalloc(sizeof(*node));
286 if (node == NULL) {
287 perror("not enough memory for the inline node");
288 return NULL;
289 }
290
291 INIT_LIST_HEAD(&node->val);
292 node->addr = addr;
293
294 if (!addr2line(dso_name, addr, &file, &line, dso, TRUE, node))
295 goto out_free_inline_node;
296
297 if (list_empty(&node->val))
298 goto out_free_inline_node;
299
300 return node;
301
302out_free_inline_node:
303 inline_node__delete(node);
304 return NULL;
305}
306
208#else /* HAVE_LIBBFD_SUPPORT */ 307#else /* HAVE_LIBBFD_SUPPORT */
209 308
309static int filename_split(char *filename, unsigned int *line_nr)
310{
311 char *sep;
312
313 sep = strchr(filename, '\n');
314 if (sep)
315 *sep = '\0';
316
317 if (!strcmp(filename, "??:0"))
318 return 0;
319
320 sep = strchr(filename, ':');
321 if (sep) {
322 *sep++ = '\0';
323 *line_nr = strtoul(sep, NULL, 0);
324 return 1;
325 }
326
327 return 0;
328}
329
210static int addr2line(const char *dso_name, u64 addr, 330static int addr2line(const char *dso_name, u64 addr,
211 char **file, unsigned int *line_nr, 331 char **file, unsigned int *line_nr,
212 struct dso *dso __maybe_unused, 332 struct dso *dso __maybe_unused,
213 bool unwind_inlines __maybe_unused) 333 bool unwind_inlines __maybe_unused,
334 struct inline_node *node __maybe_unused)
214{ 335{
215 FILE *fp; 336 FILE *fp;
216 char cmd[PATH_MAX]; 337 char cmd[PATH_MAX];
217 char *filename = NULL; 338 char *filename = NULL;
218 size_t len; 339 size_t len;
219 char *sep;
220 int ret = 0; 340 int ret = 0;
221 341
222 scnprintf(cmd, sizeof(cmd), "addr2line -e %s %016"PRIx64, 342 scnprintf(cmd, sizeof(cmd), "addr2line -e %s %016"PRIx64,
@@ -233,23 +353,14 @@ static int addr2line(const char *dso_name, u64 addr,
233 goto out; 353 goto out;
234 } 354 }
235 355
236 sep = strchr(filename, '\n'); 356 ret = filename_split(filename, line_nr);
237 if (sep) 357 if (ret != 1) {
238 *sep = '\0';
239
240 if (!strcmp(filename, "??:0")) {
241 pr_debug("no debugging info in %s\n", dso_name);
242 free(filename); 358 free(filename);
243 goto out; 359 goto out;
244 } 360 }
245 361
246 sep = strchr(filename, ':'); 362 *file = filename;
247 if (sep) { 363
248 *sep++ = '\0';
249 *file = filename;
250 *line_nr = strtoul(sep, NULL, 0);
251 ret = 1;
252 }
253out: 364out:
254 pclose(fp); 365 pclose(fp);
255 return ret; 366 return ret;
@@ -259,6 +370,58 @@ void dso__free_a2l(struct dso *dso __maybe_unused)
259{ 370{
260} 371}
261 372
373static struct inline_node *addr2inlines(const char *dso_name, u64 addr,
374 struct dso *dso __maybe_unused)
375{
376 FILE *fp;
377 char cmd[PATH_MAX];
378 struct inline_node *node;
379 char *filename = NULL;
380 size_t len;
381 unsigned int line_nr = 0;
382
383 scnprintf(cmd, sizeof(cmd), "addr2line -e %s -i %016"PRIx64,
384 dso_name, addr);
385
386 fp = popen(cmd, "r");
387 if (fp == NULL) {
388 pr_err("popen failed for %s\n", dso_name);
389 return NULL;
390 }
391
392 node = zalloc(sizeof(*node));
393 if (node == NULL) {
394 perror("not enough memory for the inline node");
395 goto out;
396 }
397
398 INIT_LIST_HEAD(&node->val);
399 node->addr = addr;
400
401 while (getline(&filename, &len, fp) != -1) {
402 if (filename_split(filename, &line_nr) != 1) {
403 free(filename);
404 goto out;
405 }
406
407 if (inline_list__append(filename, NULL, line_nr, node,
408 NULL) != 0)
409 goto out;
410
411 filename = NULL;
412 }
413
414out:
415 pclose(fp);
416
417 if (list_empty(&node->val)) {
418 inline_node__delete(node);
419 return NULL;
420 }
421
422 return node;
423}
424
262#endif /* HAVE_LIBBFD_SUPPORT */ 425#endif /* HAVE_LIBBFD_SUPPORT */
263 426
264/* 427/*
@@ -268,7 +431,7 @@ void dso__free_a2l(struct dso *dso __maybe_unused)
268#define A2L_FAIL_LIMIT 123 431#define A2L_FAIL_LIMIT 123
269 432
270char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym, 433char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
271 bool show_sym, bool unwind_inlines) 434 bool show_sym, bool show_addr, bool unwind_inlines)
272{ 435{
273 char *file = NULL; 436 char *file = NULL;
274 unsigned line = 0; 437 unsigned line = 0;
@@ -278,18 +441,11 @@ char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
278 if (!dso->has_srcline) 441 if (!dso->has_srcline)
279 goto out; 442 goto out;
280 443
281 if (dso->symsrc_filename) 444 dso_name = dso__name(dso);
282 dso_name = dso->symsrc_filename; 445 if (dso_name == NULL)
283 else
284 dso_name = dso->long_name;
285
286 if (dso_name[0] == '[')
287 goto out;
288
289 if (!strncmp(dso_name, "/tmp/perf-", 10))
290 goto out; 446 goto out;
291 447
292 if (!addr2line(dso_name, addr, &file, &line, dso, unwind_inlines)) 448 if (!addr2line(dso_name, addr, &file, &line, dso, unwind_inlines, NULL))
293 goto out; 449 goto out;
294 450
295 if (asprintf(&srcline, "%s:%u", 451 if (asprintf(&srcline, "%s:%u",
@@ -309,6 +465,11 @@ out:
309 dso->has_srcline = 0; 465 dso->has_srcline = 0;
310 dso__free_a2l(dso); 466 dso__free_a2l(dso);
311 } 467 }
468
469 if (!show_addr)
470 return (show_sym && sym) ?
471 strndup(sym->name, sym->namelen) : NULL;
472
312 if (sym) { 473 if (sym) {
313 if (asprintf(&srcline, "%s+%" PRIu64, show_sym ? sym->name : "", 474 if (asprintf(&srcline, "%s+%" PRIu64, show_sym ? sym->name : "",
314 addr - sym->start) < 0) 475 addr - sym->start) < 0)
@@ -325,7 +486,32 @@ void free_srcline(char *srcline)
325} 486}
326 487
327char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym, 488char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
328 bool show_sym) 489 bool show_sym, bool show_addr)
490{
491 return __get_srcline(dso, addr, sym, show_sym, show_addr, false);
492}
493
494struct inline_node *dso__parse_addr_inlines(struct dso *dso, u64 addr)
329{ 495{
330 return __get_srcline(dso, addr, sym, show_sym, false); 496 const char *dso_name;
497
498 dso_name = dso__name(dso);
499 if (dso_name == NULL)
500 return NULL;
501
502 return addr2inlines(dso_name, addr, dso);
503}
504
505void inline_node__delete(struct inline_node *node)
506{
507 struct inline_list *ilist, *tmp;
508
509 list_for_each_entry_safe(ilist, tmp, &node->val, list) {
510 list_del_init(&ilist->list);
511 zfree(&ilist->filename);
512 zfree(&ilist->funcname);
513 free(ilist);
514 }
515
516 free(node);
331} 517}
diff --git a/tools/perf/util/srcline.h b/tools/perf/util/srcline.h
new file mode 100644
index 000000000000..7b52ba88676e
--- /dev/null
+++ b/tools/perf/util/srcline.h
@@ -0,0 +1,34 @@
1#ifndef PERF_SRCLINE_H
2#define PERF_SRCLINE_H
3
4#include <linux/list.h>
5#include <linux/types.h>
6
7struct dso;
8struct symbol;
9
10extern bool srcline_full_filename;
11char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
12 bool show_sym, bool show_addr);
13char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
14 bool show_sym, bool show_addr, bool unwind_inlines);
15void free_srcline(char *srcline);
16
17#define SRCLINE_UNKNOWN ((char *) "??:0")
18
19struct inline_list {
20 char *filename;
21 char *funcname;
22 unsigned int line_nr;
23 struct list_head list;
24};
25
26struct inline_node {
27 u64 addr;
28 struct list_head val;
29};
30
31struct inline_node *dso__parse_addr_inlines(struct dso *dso, u64 addr);
32void inline_node__delete(struct inline_node *node);
33
34#endif /* PERF_SRCLINE_H */
diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index 8a2bbd2a4d82..ac10cc675d39 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -3,6 +3,9 @@
3#include "stat.h" 3#include "stat.h"
4#include "color.h" 4#include "color.h"
5#include "pmu.h" 5#include "pmu.h"
6#include "rblist.h"
7#include "evlist.h"
8#include "expr.h"
6 9
7enum { 10enum {
8 CTX_BIT_USER = 1 << 0, 11 CTX_BIT_USER = 1 << 0,
@@ -41,13 +44,73 @@ static struct stats runtime_topdown_slots_issued[NUM_CTX][MAX_NR_CPUS];
41static struct stats runtime_topdown_slots_retired[NUM_CTX][MAX_NR_CPUS]; 44static struct stats runtime_topdown_slots_retired[NUM_CTX][MAX_NR_CPUS];
42static struct stats runtime_topdown_fetch_bubbles[NUM_CTX][MAX_NR_CPUS]; 45static struct stats runtime_topdown_fetch_bubbles[NUM_CTX][MAX_NR_CPUS];
43static struct stats runtime_topdown_recovery_bubbles[NUM_CTX][MAX_NR_CPUS]; 46static struct stats runtime_topdown_recovery_bubbles[NUM_CTX][MAX_NR_CPUS];
47static struct rblist runtime_saved_values;
44static bool have_frontend_stalled; 48static bool have_frontend_stalled;
45 49
46struct stats walltime_nsecs_stats; 50struct stats walltime_nsecs_stats;
47 51
52struct saved_value {
53 struct rb_node rb_node;
54 struct perf_evsel *evsel;
55 int cpu;
56 int ctx;
57 struct stats stats;
58};
59
60static int saved_value_cmp(struct rb_node *rb_node, const void *entry)
61{
62 struct saved_value *a = container_of(rb_node,
63 struct saved_value,
64 rb_node);
65 const struct saved_value *b = entry;
66
67 if (a->ctx != b->ctx)
68 return a->ctx - b->ctx;
69 if (a->cpu != b->cpu)
70 return a->cpu - b->cpu;
71 return a->evsel - b->evsel;
72}
73
74static struct rb_node *saved_value_new(struct rblist *rblist __maybe_unused,
75 const void *entry)
76{
77 struct saved_value *nd = malloc(sizeof(struct saved_value));
78
79 if (!nd)
80 return NULL;
81 memcpy(nd, entry, sizeof(struct saved_value));
82 return &nd->rb_node;
83}
84
85static struct saved_value *saved_value_lookup(struct perf_evsel *evsel,
86 int cpu, int ctx,
87 bool create)
88{
89 struct rb_node *nd;
90 struct saved_value dm = {
91 .cpu = cpu,
92 .ctx = ctx,
93 .evsel = evsel,
94 };
95 nd = rblist__find(&runtime_saved_values, &dm);
96 if (nd)
97 return container_of(nd, struct saved_value, rb_node);
98 if (create) {
99 rblist__add_node(&runtime_saved_values, &dm);
100 nd = rblist__find(&runtime_saved_values, &dm);
101 if (nd)
102 return container_of(nd, struct saved_value, rb_node);
103 }
104 return NULL;
105}
106
48void perf_stat__init_shadow_stats(void) 107void perf_stat__init_shadow_stats(void)
49{ 108{
50 have_frontend_stalled = pmu_have_event("cpu", "stalled-cycles-frontend"); 109 have_frontend_stalled = pmu_have_event("cpu", "stalled-cycles-frontend");
110 rblist__init(&runtime_saved_values);
111 runtime_saved_values.node_cmp = saved_value_cmp;
112 runtime_saved_values.node_new = saved_value_new;
113 /* No delete for now */
51} 114}
52 115
53static int evsel_context(struct perf_evsel *evsel) 116static int evsel_context(struct perf_evsel *evsel)
@@ -70,6 +133,8 @@ static int evsel_context(struct perf_evsel *evsel)
70 133
71void perf_stat__reset_shadow_stats(void) 134void perf_stat__reset_shadow_stats(void)
72{ 135{
136 struct rb_node *pos, *next;
137
73 memset(runtime_nsecs_stats, 0, sizeof(runtime_nsecs_stats)); 138 memset(runtime_nsecs_stats, 0, sizeof(runtime_nsecs_stats));
74 memset(runtime_cycles_stats, 0, sizeof(runtime_cycles_stats)); 139 memset(runtime_cycles_stats, 0, sizeof(runtime_cycles_stats));
75 memset(runtime_stalled_cycles_front_stats, 0, sizeof(runtime_stalled_cycles_front_stats)); 140 memset(runtime_stalled_cycles_front_stats, 0, sizeof(runtime_stalled_cycles_front_stats));
@@ -92,6 +157,15 @@ void perf_stat__reset_shadow_stats(void)
92 memset(runtime_topdown_slots_issued, 0, sizeof(runtime_topdown_slots_issued)); 157 memset(runtime_topdown_slots_issued, 0, sizeof(runtime_topdown_slots_issued));
93 memset(runtime_topdown_fetch_bubbles, 0, sizeof(runtime_topdown_fetch_bubbles)); 158 memset(runtime_topdown_fetch_bubbles, 0, sizeof(runtime_topdown_fetch_bubbles));
94 memset(runtime_topdown_recovery_bubbles, 0, sizeof(runtime_topdown_recovery_bubbles)); 159 memset(runtime_topdown_recovery_bubbles, 0, sizeof(runtime_topdown_recovery_bubbles));
160
161 next = rb_first(&runtime_saved_values.entries);
162 while (next) {
163 pos = next;
164 next = rb_next(pos);
165 memset(&container_of(pos, struct saved_value, rb_node)->stats,
166 0,
167 sizeof(struct stats));
168 }
95} 169}
96 170
97/* 171/*
@@ -143,6 +217,12 @@ void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
143 update_stats(&runtime_dtlb_cache_stats[ctx][cpu], count[0]); 217 update_stats(&runtime_dtlb_cache_stats[ctx][cpu], count[0]);
144 else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_ITLB)) 218 else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_ITLB))
145 update_stats(&runtime_itlb_cache_stats[ctx][cpu], count[0]); 219 update_stats(&runtime_itlb_cache_stats[ctx][cpu], count[0]);
220
221 if (counter->collect_stat) {
222 struct saved_value *v = saved_value_lookup(counter, cpu, ctx,
223 true);
224 update_stats(&v->stats, count[0]);
225 }
146} 226}
147 227
148/* used for get_ratio_color() */ 228/* used for get_ratio_color() */
@@ -172,6 +252,95 @@ static const char *get_ratio_color(enum grc_type type, double ratio)
172 return color; 252 return color;
173} 253}
174 254
255static struct perf_evsel *perf_stat__find_event(struct perf_evlist *evsel_list,
256 const char *name)
257{
258 struct perf_evsel *c2;
259
260 evlist__for_each_entry (evsel_list, c2) {
261 if (!strcasecmp(c2->name, name))
262 return c2;
263 }
264 return NULL;
265}
266
267/* Mark MetricExpr target events and link events using them to them. */
268void perf_stat__collect_metric_expr(struct perf_evlist *evsel_list)
269{
270 struct perf_evsel *counter, *leader, **metric_events, *oc;
271 bool found;
272 const char **metric_names;
273 int i;
274 int num_metric_names;
275
276 evlist__for_each_entry(evsel_list, counter) {
277 bool invalid = false;
278
279 leader = counter->leader;
280 if (!counter->metric_expr)
281 continue;
282 metric_events = counter->metric_events;
283 if (!metric_events) {
284 if (expr__find_other(counter->metric_expr, counter->name,
285 &metric_names, &num_metric_names) < 0)
286 continue;
287
288 metric_events = calloc(sizeof(struct perf_evsel *),
289 num_metric_names + 1);
290 if (!metric_events)
291 return;
292 counter->metric_events = metric_events;
293 }
294
295 for (i = 0; i < num_metric_names; i++) {
296 found = false;
297 if (leader) {
298 /* Search in group */
299 for_each_group_member (oc, leader) {
300 if (!strcasecmp(oc->name, metric_names[i])) {
301 found = true;
302 break;
303 }
304 }
305 }
306 if (!found) {
307 /* Search ignoring groups */
308 oc = perf_stat__find_event(evsel_list, metric_names[i]);
309 }
310 if (!oc) {
311 /* Deduping one is good enough to handle duplicated PMUs. */
312 static char *printed;
313
314 /*
315 * Adding events automatically would be difficult, because
316 * it would risk creating groups that are not schedulable.
317 * perf stat doesn't understand all the scheduling constraints
318 * of events. So we ask the user instead to add the missing
319 * events.
320 */
321 if (!printed || strcasecmp(printed, metric_names[i])) {
322 fprintf(stderr,
323 "Add %s event to groups to get metric expression for %s\n",
324 metric_names[i],
325 counter->name);
326 printed = strdup(metric_names[i]);
327 }
328 invalid = true;
329 continue;
330 }
331 metric_events[i] = oc;
332 oc->collect_stat = true;
333 }
334 metric_events[i] = NULL;
335 free(metric_names);
336 if (invalid) {
337 free(metric_events);
338 counter->metric_events = NULL;
339 counter->metric_expr = NULL;
340 }
341 }
342}
343
175static void print_stalled_cycles_frontend(int cpu, 344static void print_stalled_cycles_frontend(int cpu,
176 struct perf_evsel *evsel, double avg, 345 struct perf_evsel *evsel, double avg,
177 struct perf_stat_output_ctx *out) 346 struct perf_stat_output_ctx *out)
@@ -614,6 +783,34 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
614 be_bound * 100.); 783 be_bound * 100.);
615 else 784 else
616 print_metric(ctxp, NULL, NULL, name, 0); 785 print_metric(ctxp, NULL, NULL, name, 0);
786 } else if (evsel->metric_expr) {
787 struct parse_ctx pctx;
788 int i;
789
790 expr__ctx_init(&pctx);
791 expr__add_id(&pctx, evsel->name, avg);
792 for (i = 0; evsel->metric_events[i]; i++) {
793 struct saved_value *v;
794
795 v = saved_value_lookup(evsel->metric_events[i], cpu, ctx, false);
796 if (!v)
797 break;
798 expr__add_id(&pctx, evsel->metric_events[i]->name,
799 avg_stats(&v->stats));
800 }
801 if (!evsel->metric_events[i]) {
802 const char *p = evsel->metric_expr;
803
804 if (expr__parse(&ratio, &pctx, &p) == 0)
805 print_metric(ctxp, NULL, "%8.1f",
806 evsel->metric_name ?
807 evsel->metric_name :
808 out->force_header ? evsel->name : "",
809 ratio);
810 else
811 print_metric(ctxp, NULL, NULL, "", 0);
812 } else
813 print_metric(ctxp, NULL, NULL, "", 0);
617 } else if (runtime_nsecs_stats[cpu].n != 0) { 814 } else if (runtime_nsecs_stats[cpu].n != 0) {
618 char unit = 'M'; 815 char unit = 'M';
619 char unit_buf[10]; 816 char unit_buf[10];
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index 0d51334a9b46..c58174443dc1 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -1,3 +1,5 @@
1#include <errno.h>
2#include <inttypes.h>
1#include <math.h> 3#include <math.h>
2#include "stat.h" 4#include "stat.h"
3#include "evlist.h" 5#include "evlist.h"
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index c29bb94c48a4..0a65ae23f495 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -85,11 +85,13 @@ struct perf_stat_output_ctx {
85 void *ctx; 85 void *ctx;
86 print_metric_t print_metric; 86 print_metric_t print_metric;
87 new_line_t new_line; 87 new_line_t new_line;
88 bool force_header;
88}; 89};
89 90
90void perf_stat__print_shadow_stats(struct perf_evsel *evsel, 91void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
91 double avg, int cpu, 92 double avg, int cpu,
92 struct perf_stat_output_ctx *out); 93 struct perf_stat_output_ctx *out);
94void perf_stat__collect_metric_expr(struct perf_evlist *);
93 95
94int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw); 96int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
95void perf_evlist__free_stats(struct perf_evlist *evlist); 97void perf_evlist__free_stats(struct perf_evlist *evlist);
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index 817593908d47..e91b5e86f027 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -1,6 +1,7 @@
1#include "debug.h" 1#include "debug.h"
2#include "util.h" 2#include "util.h"
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <errno.h>
4 5
5int prefixcmp(const char *str, const char *prefix) 6int prefixcmp(const char *str, const char *prefix)
6{ 7{
diff --git a/tools/perf/util/strfilter.c b/tools/perf/util/strfilter.c
index efb53772e0ec..4dc0af669a30 100644
--- a/tools/perf/util/strfilter.c
+++ b/tools/perf/util/strfilter.c
@@ -1,7 +1,10 @@
1#include "util.h" 1#include "util.h"
2#include "string.h" 2#include "string2.h"
3#include "strfilter.h" 3#include "strfilter.h"
4 4
5#include <errno.h>
6#include "sane_ctype.h"
7
5/* Operators */ 8/* Operators */
6static const char *OP_and = "&"; /* Logical AND */ 9static const char *OP_and = "&"; /* Logical AND */
7static const char *OP_or = "|"; /* Logical OR */ 10static const char *OP_or = "|"; /* Logical OR */
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index bddca519dd58..cca53b693a48 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -1,5 +1,9 @@
1#include "util.h" 1#include "string2.h"
2#include "linux/string.h" 2#include <linux/kernel.h>
3#include <linux/string.h>
4#include <stdlib.h>
5
6#include "sane_ctype.h"
3 7
4#define K 1024LL 8#define K 1024LL
5/* 9/*
@@ -99,8 +103,10 @@ static int count_argc(const char *str)
99void argv_free(char **argv) 103void argv_free(char **argv)
100{ 104{
101 char **p; 105 char **p;
102 for (p = argv; *p; p++) 106 for (p = argv; *p; p++) {
103 zfree(p); 107 free(*p);
108 *p = NULL;
109 }
104 110
105 free(argv); 111 free(argv);
106} 112}
@@ -120,7 +126,7 @@ void argv_free(char **argv)
120char **argv_split(const char *str, int *argcp) 126char **argv_split(const char *str, int *argcp)
121{ 127{
122 int argc = count_argc(str); 128 int argc = count_argc(str);
123 char **argv = zalloc(sizeof(*argv) * (argc+1)); 129 char **argv = calloc(argc + 1, sizeof(*argv));
124 char **argvp; 130 char **argvp;
125 131
126 if (argv == NULL) 132 if (argv == NULL)
@@ -322,12 +328,8 @@ char *strxfrchar(char *s, char from, char to)
322 */ 328 */
323char *ltrim(char *s) 329char *ltrim(char *s)
324{ 330{
325 int len = strlen(s); 331 while (isspace(*s))
326
327 while (len && isspace(*s)) {
328 len--;
329 s++; 332 s++;
330 }
331 333
332 return s; 334 return s;
333} 335}
@@ -381,7 +383,7 @@ char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints
381 goto out_err_overflow; 383 goto out_err_overflow;
382 384
383 if (i > 0) 385 if (i > 0)
384 printed += snprintf(e + printed, size - printed, " %s ", or_and); 386 printed += scnprintf(e + printed, size - printed, " %s ", or_and);
385 printed += scnprintf(e + printed, size - printed, 387 printed += scnprintf(e + printed, size - printed,
386 "%s %s %d", var, eq_neq, ints[i]); 388 "%s %s %d", var, eq_neq, ints[i]);
387 } 389 }
diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h
new file mode 100644
index 000000000000..2f619681bd6a
--- /dev/null
+++ b/tools/perf/util/string2.h
@@ -0,0 +1,42 @@
1#ifndef PERF_STRING_H
2#define PERF_STRING_H
3
4#include <linux/types.h>
5#include <stddef.h>
6#include <string.h>
7
8s64 perf_atoll(const char *str);
9char **argv_split(const char *str, int *argcp);
10void argv_free(char **argv);
11bool strglobmatch(const char *str, const char *pat);
12bool strglobmatch_nocase(const char *str, const char *pat);
13bool strlazymatch(const char *str, const char *pat);
14static inline bool strisglob(const char *str)
15{
16 return strpbrk(str, "*?[") != NULL;
17}
18int strtailcmp(const char *s1, const char *s2);
19char *strxfrchar(char *s, char from, char to);
20
21char *ltrim(char *s);
22char *rtrim(char *s);
23
24static inline char *trim(char *s)
25{
26 return ltrim(rtrim(s));
27}
28
29char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints);
30
31static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints)
32{
33 return asprintf_expr_inout_ints(var, true, nints, ints);
34}
35
36static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints)
37{
38 return asprintf_expr_inout_ints(var, false, nints, ints);
39}
40
41
42#endif /* PERF_STRING_H */
diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c
index 0d3dfcb919b4..9de5434bb49e 100644
--- a/tools/perf/util/strlist.c
+++ b/tools/perf/util/strlist.c
@@ -10,6 +10,7 @@
10#include <stdio.h> 10#include <stdio.h>
11#include <stdlib.h> 11#include <stdlib.h>
12#include <string.h> 12#include <string.h>
13#include <unistd.h>
13 14
14static 15static
15struct rb_node *strlist__node_new(struct rblist *rblist, const void *entry) 16struct rb_node *strlist__node_new(struct rblist *rblist, const void *entry)
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 4e59ddeb4eda..e7ee47f7377a 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -10,8 +10,9 @@
10#include "demangle-rust.h" 10#include "demangle-rust.h"
11#include "machine.h" 11#include "machine.h"
12#include "vdso.h" 12#include "vdso.h"
13#include <symbol/kallsyms.h>
14#include "debug.h" 13#include "debug.h"
14#include "sane_ctype.h"
15#include <symbol/kallsyms.h>
15 16
16#ifndef EM_AARCH64 17#ifndef EM_AARCH64
17#define EM_AARCH64 183 /* ARM 64 bit */ 18#define EM_AARCH64 183 /* ARM 64 bit */
@@ -390,6 +391,11 @@ out_elf_end:
390 return 0; 391 return 0;
391} 392}
392 393
394char *dso__demangle_sym(struct dso *dso, int kmodule, char *elf_name)
395{
396 return demangle_sym(dso, kmodule, elf_name);
397}
398
393/* 399/*
394 * Align offset to 4 bytes as needed for note name and descriptor data. 400 * Align offset to 4 bytes as needed for note name and descriptor data.
395 */ 401 */
@@ -1828,7 +1834,7 @@ void kcore_extract__delete(struct kcore_extract *kce)
1828static int populate_sdt_note(Elf **elf, const char *data, size_t len, 1834static int populate_sdt_note(Elf **elf, const char *data, size_t len,
1829 struct list_head *sdt_notes) 1835 struct list_head *sdt_notes)
1830{ 1836{
1831 const char *provider, *name; 1837 const char *provider, *name, *args;
1832 struct sdt_note *tmp = NULL; 1838 struct sdt_note *tmp = NULL;
1833 GElf_Ehdr ehdr; 1839 GElf_Ehdr ehdr;
1834 GElf_Addr base_off = 0; 1840 GElf_Addr base_off = 0;
@@ -1887,6 +1893,25 @@ static int populate_sdt_note(Elf **elf, const char *data, size_t len,
1887 goto out_free_prov; 1893 goto out_free_prov;
1888 } 1894 }
1889 1895
1896 args = memchr(name, '\0', data + len - name);
1897
1898 /*
1899 * There is no argument if:
1900 * - We reached the end of the note;
1901 * - There is not enough room to hold a potential string;
1902 * - The argument string is empty or just contains ':'.
1903 */
1904 if (args == NULL || data + len - args < 2 ||
1905 args[1] == ':' || args[1] == '\0')
1906 tmp->args = NULL;
1907 else {
1908 tmp->args = strdup(++args);
1909 if (!tmp->args) {
1910 ret = -ENOMEM;
1911 goto out_free_name;
1912 }
1913 }
1914
1890 if (gelf_getclass(*elf) == ELFCLASS32) { 1915 if (gelf_getclass(*elf) == ELFCLASS32) {
1891 memcpy(&tmp->addr, &buf, 3 * sizeof(Elf32_Addr)); 1916 memcpy(&tmp->addr, &buf, 3 * sizeof(Elf32_Addr));
1892 tmp->bit32 = true; 1917 tmp->bit32 = true;
@@ -1898,7 +1923,7 @@ static int populate_sdt_note(Elf **elf, const char *data, size_t len,
1898 if (!gelf_getehdr(*elf, &ehdr)) { 1923 if (!gelf_getehdr(*elf, &ehdr)) {
1899 pr_debug("%s : cannot get elf header.\n", __func__); 1924 pr_debug("%s : cannot get elf header.\n", __func__);
1900 ret = -EBADF; 1925 ret = -EBADF;
1901 goto out_free_name; 1926 goto out_free_args;
1902 } 1927 }
1903 1928
1904 /* Adjust the prelink effect : 1929 /* Adjust the prelink effect :
@@ -1923,6 +1948,8 @@ static int populate_sdt_note(Elf **elf, const char *data, size_t len,
1923 list_add_tail(&tmp->note_list, sdt_notes); 1948 list_add_tail(&tmp->note_list, sdt_notes);
1924 return 0; 1949 return 0;
1925 1950
1951out_free_args:
1952 free(tmp->args);
1926out_free_name: 1953out_free_name:
1927 free(tmp->name); 1954 free(tmp->name);
1928out_free_prov: 1955out_free_prov:
diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-minimal.c
index 11cdde980545..40bf5d4c0bfd 100644
--- a/tools/perf/util/symbol-minimal.c
+++ b/tools/perf/util/symbol-minimal.c
@@ -1,6 +1,7 @@
1#include "symbol.h" 1#include "symbol.h"
2#include "util.h" 2#include "util.h"
3 3
4#include <errno.h>
4#include <stdio.h> 5#include <stdio.h>
5#include <fcntl.h> 6#include <fcntl.h>
6#include <string.h> 7#include <string.h>
@@ -373,3 +374,10 @@ int kcore_copy(const char *from_dir __maybe_unused,
373void symbol__elf_init(void) 374void symbol__elf_init(void)
374{ 375{
375} 376}
377
378char *dso__demangle_sym(struct dso *dso __maybe_unused,
379 int kmodule __maybe_unused,
380 char *elf_name __maybe_unused)
381{
382 return NULL;
383}
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 9b4d8ba22fed..2cb7665e9973 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -3,6 +3,7 @@
3#include <stdlib.h> 3#include <stdlib.h>
4#include <stdio.h> 4#include <stdio.h>
5#include <string.h> 5#include <string.h>
6#include <linux/kernel.h>
6#include <sys/types.h> 7#include <sys/types.h>
7#include <sys/stat.h> 8#include <sys/stat.h>
8#include <sys/param.h> 9#include <sys/param.h>
@@ -18,6 +19,8 @@
18#include "strlist.h" 19#include "strlist.h"
19#include "intlist.h" 20#include "intlist.h"
20#include "header.h" 21#include "header.h"
22#include "path.h"
23#include "sane_ctype.h"
21 24
22#include <elf.h> 25#include <elf.h>
23#include <limits.h> 26#include <limits.h>
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 6c358b7ed336..7acd70fce68e 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -13,7 +13,7 @@
13#include <libgen.h> 13#include <libgen.h>
14#include "build-id.h" 14#include "build-id.h"
15#include "event.h" 15#include "event.h"
16#include "util.h" 16#include "path.h"
17 17
18#ifdef HAVE_LIBELF_SUPPORT 18#ifdef HAVE_LIBELF_SUPPORT
19#include <libelf.h> 19#include <libelf.h>
@@ -118,7 +118,8 @@ struct symbol_conf {
118 show_ref_callgraph, 118 show_ref_callgraph,
119 hide_unresolved, 119 hide_unresolved,
120 raw_trace, 120 raw_trace,
121 report_hierarchy; 121 report_hierarchy,
122 inline_name;
122 const char *vmlinux_name, 123 const char *vmlinux_name,
123 *kallsyms_name, 124 *kallsyms_name,
124 *source_prefix, 125 *source_prefix,
@@ -305,6 +306,8 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
305int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss, 306int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
306 struct map *map); 307 struct map *map);
307 308
309char *dso__demangle_sym(struct dso *dso, int kmodule, char *elf_name);
310
308void __symbols__insert(struct rb_root *symbols, struct symbol *sym, bool kernel); 311void __symbols__insert(struct rb_root *symbols, struct symbol *sym, bool kernel);
309void symbols__insert(struct rb_root *symbols, struct symbol *sym); 312void symbols__insert(struct rb_root *symbols, struct symbol *sym);
310void symbols__fixup_duplicate(struct rb_root *symbols); 313void symbols__fixup_duplicate(struct rb_root *symbols);
@@ -351,6 +354,7 @@ int arch__choose_best_symbol(struct symbol *syma, struct symbol *symb);
351struct sdt_note { 354struct sdt_note {
352 char *name; /* name of the note*/ 355 char *name; /* name of the note*/
353 char *provider; /* provider name */ 356 char *provider; /* provider name */
357 char *args;
354 bool bit32; /* whether the location is 32 bits? */ 358 bool bit32; /* whether the location is 32 bits? */
355 union { /* location, base and semaphore addrs */ 359 union { /* location, base and semaphore addrs */
356 Elf64_Addr a64[3]; 360 Elf64_Addr a64[3];
diff --git a/tools/perf/util/term.c b/tools/perf/util/term.c
index 90b47d8aa19c..8f254a74d97d 100644
--- a/tools/perf/util/term.c
+++ b/tools/perf/util/term.c
@@ -1,4 +1,8 @@
1#include "util.h" 1#include "term.h"
2#include <stdlib.h>
3#include <termios.h>
4#include <unistd.h>
5#include <sys/ioctl.h>
2 6
3void get_term_dimensions(struct winsize *ws) 7void get_term_dimensions(struct winsize *ws)
4{ 8{
diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c
index d3301529f6a7..dd17d6a38d3a 100644
--- a/tools/perf/util/thread-stack.c
+++ b/tools/perf/util/thread-stack.c
@@ -15,6 +15,7 @@
15 15
16#include <linux/rbtree.h> 16#include <linux/rbtree.h>
17#include <linux/list.h> 17#include <linux/list.h>
18#include <errno.h>
18#include "thread.h" 19#include "thread.h"
19#include "event.h" 20#include "event.h"
20#include "machine.h" 21#include "machine.h"
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index f5af87f66663..378c418ca0c1 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -1,12 +1,15 @@
1#include "../perf.h" 1#include "../perf.h"
2#include <errno.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <stdio.h> 4#include <stdio.h>
4#include <string.h> 5#include <string.h>
6#include <linux/kernel.h>
5#include "session.h" 7#include "session.h"
6#include "thread.h" 8#include "thread.h"
7#include "thread-stack.h" 9#include "thread-stack.h"
8#include "util.h" 10#include "util.h"
9#include "debug.h" 11#include "debug.h"
12#include "namespaces.h"
10#include "comm.h" 13#include "comm.h"
11#include "unwind.h" 14#include "unwind.h"
12 15
@@ -40,6 +43,7 @@ struct thread *thread__new(pid_t pid, pid_t tid)
40 thread->tid = tid; 43 thread->tid = tid;
41 thread->ppid = -1; 44 thread->ppid = -1;
42 thread->cpu = -1; 45 thread->cpu = -1;
46 INIT_LIST_HEAD(&thread->namespaces_list);
43 INIT_LIST_HEAD(&thread->comm_list); 47 INIT_LIST_HEAD(&thread->comm_list);
44 48
45 comm_str = malloc(32); 49 comm_str = malloc(32);
@@ -53,7 +57,7 @@ struct thread *thread__new(pid_t pid, pid_t tid)
53 goto err_thread; 57 goto err_thread;
54 58
55 list_add(&comm->list, &thread->comm_list); 59 list_add(&comm->list, &thread->comm_list);
56 atomic_set(&thread->refcnt, 1); 60 refcount_set(&thread->refcnt, 1);
57 RB_CLEAR_NODE(&thread->rb_node); 61 RB_CLEAR_NODE(&thread->rb_node);
58 } 62 }
59 63
@@ -66,7 +70,8 @@ err_thread:
66 70
67void thread__delete(struct thread *thread) 71void thread__delete(struct thread *thread)
68{ 72{
69 struct comm *comm, *tmp; 73 struct namespaces *namespaces, *tmp_namespaces;
74 struct comm *comm, *tmp_comm;
70 75
71 BUG_ON(!RB_EMPTY_NODE(&thread->rb_node)); 76 BUG_ON(!RB_EMPTY_NODE(&thread->rb_node));
72 77
@@ -76,7 +81,12 @@ void thread__delete(struct thread *thread)
76 map_groups__put(thread->mg); 81 map_groups__put(thread->mg);
77 thread->mg = NULL; 82 thread->mg = NULL;
78 } 83 }
79 list_for_each_entry_safe(comm, tmp, &thread->comm_list, list) { 84 list_for_each_entry_safe(namespaces, tmp_namespaces,
85 &thread->namespaces_list, list) {
86 list_del(&namespaces->list);
87 namespaces__free(namespaces);
88 }
89 list_for_each_entry_safe(comm, tmp_comm, &thread->comm_list, list) {
80 list_del(&comm->list); 90 list_del(&comm->list);
81 comm__free(comm); 91 comm__free(comm);
82 } 92 }
@@ -88,13 +98,13 @@ void thread__delete(struct thread *thread)
88struct thread *thread__get(struct thread *thread) 98struct thread *thread__get(struct thread *thread)
89{ 99{
90 if (thread) 100 if (thread)
91 atomic_inc(&thread->refcnt); 101 refcount_inc(&thread->refcnt);
92 return thread; 102 return thread;
93} 103}
94 104
95void thread__put(struct thread *thread) 105void thread__put(struct thread *thread)
96{ 106{
97 if (thread && atomic_dec_and_test(&thread->refcnt)) { 107 if (thread && refcount_dec_and_test(&thread->refcnt)) {
98 /* 108 /*
99 * Remove it from the dead_threads list, as last reference 109 * Remove it from the dead_threads list, as last reference
100 * is gone. 110 * is gone.
@@ -104,6 +114,38 @@ void thread__put(struct thread *thread)
104 } 114 }
105} 115}
106 116
117struct namespaces *thread__namespaces(const struct thread *thread)
118{
119 if (list_empty(&thread->namespaces_list))
120 return NULL;
121
122 return list_first_entry(&thread->namespaces_list, struct namespaces, list);
123}
124
125int thread__set_namespaces(struct thread *thread, u64 timestamp,
126 struct namespaces_event *event)
127{
128 struct namespaces *new, *curr = thread__namespaces(thread);
129
130 new = namespaces__new(event);
131 if (!new)
132 return -ENOMEM;
133
134 list_add(&new->list, &thread->namespaces_list);
135
136 if (timestamp && curr) {
137 /*
138 * setns syscall must have changed few or all the namespaces
139 * of this thread. Update end time for the namespaces
140 * previously used.
141 */
142 curr = list_next_entry(new, list);
143 curr->end_time = timestamp;
144 }
145
146 return 0;
147}
148
107struct comm *thread__comm(const struct thread *thread) 149struct comm *thread__comm(const struct thread *thread)
108{ 150{
109 if (list_empty(&thread->comm_list)) 151 if (list_empty(&thread->comm_list))
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 99263cb6e6b6..4eb849e9098f 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -1,7 +1,7 @@
1#ifndef __PERF_THREAD_H 1#ifndef __PERF_THREAD_H
2#define __PERF_THREAD_H 2#define __PERF_THREAD_H
3 3
4#include <linux/atomic.h> 4#include <linux/refcount.h>
5#include <linux/rbtree.h> 5#include <linux/rbtree.h>
6#include <linux/list.h> 6#include <linux/list.h>
7#include <unistd.h> 7#include <unistd.h>
@@ -23,11 +23,12 @@ struct thread {
23 pid_t tid; 23 pid_t tid;
24 pid_t ppid; 24 pid_t ppid;
25 int cpu; 25 int cpu;
26 atomic_t refcnt; 26 refcount_t refcnt;
27 char shortname[3]; 27 char shortname[3];
28 bool comm_set; 28 bool comm_set;
29 int comm_len; 29 int comm_len;
30 bool dead; /* if set thread has exited */ 30 bool dead; /* if set thread has exited */
31 struct list_head namespaces_list;
31 struct list_head comm_list; 32 struct list_head comm_list;
32 u64 db_id; 33 u64 db_id;
33 34
@@ -40,6 +41,7 @@ struct thread {
40}; 41};
41 42
42struct machine; 43struct machine;
44struct namespaces;
43struct comm; 45struct comm;
44 46
45struct thread *thread__new(pid_t pid, pid_t tid); 47struct thread *thread__new(pid_t pid, pid_t tid);
@@ -62,6 +64,10 @@ static inline void thread__exited(struct thread *thread)
62 thread->dead = true; 64 thread->dead = true;
63} 65}
64 66
67struct namespaces *thread__namespaces(const struct thread *thread);
68int thread__set_namespaces(struct thread *thread, u64 timestamp,
69 struct namespaces_event *event);
70
65int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp, 71int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp,
66 bool exec); 72 bool exec);
67static inline int thread__set_comm(struct thread *thread, const char *comm, 73static inline int thread__set_comm(struct thread *thread, const char *comm,
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 7c3fcc538a70..63ead7b06324 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -1,4 +1,5 @@
1#include <dirent.h> 1#include <dirent.h>
2#include <errno.h>
2#include <limits.h> 3#include <limits.h>
3#include <stdbool.h> 4#include <stdbool.h>
4#include <stdlib.h> 5#include <stdlib.h>
@@ -6,6 +7,7 @@
6#include <sys/types.h> 7#include <sys/types.h>
7#include <sys/stat.h> 8#include <sys/stat.h>
8#include <unistd.h> 9#include <unistd.h>
10#include "string2.h"
9#include "strlist.h" 11#include "strlist.h"
10#include <string.h> 12#include <string.h>
11#include <api/fs/fs.h> 13#include <api/fs/fs.h>
@@ -66,7 +68,7 @@ struct thread_map *thread_map__new_by_pid(pid_t pid)
66 for (i = 0; i < items; i++) 68 for (i = 0; i < items; i++)
67 thread_map__set_pid(threads, i, atoi(namelist[i]->d_name)); 69 thread_map__set_pid(threads, i, atoi(namelist[i]->d_name));
68 threads->nr = items; 70 threads->nr = items;
69 atomic_set(&threads->refcnt, 1); 71 refcount_set(&threads->refcnt, 1);
70 } 72 }
71 73
72 for (i=0; i<items; i++) 74 for (i=0; i<items; i++)
@@ -83,7 +85,7 @@ struct thread_map *thread_map__new_by_tid(pid_t tid)
83 if (threads != NULL) { 85 if (threads != NULL) {
84 thread_map__set_pid(threads, 0, tid); 86 thread_map__set_pid(threads, 0, tid);
85 threads->nr = 1; 87 threads->nr = 1;
86 atomic_set(&threads->refcnt, 1); 88 refcount_set(&threads->refcnt, 1);
87 } 89 }
88 90
89 return threads; 91 return threads;
@@ -105,7 +107,7 @@ struct thread_map *thread_map__new_by_uid(uid_t uid)
105 goto out_free_threads; 107 goto out_free_threads;
106 108
107 threads->nr = 0; 109 threads->nr = 0;
108 atomic_set(&threads->refcnt, 1); 110 refcount_set(&threads->refcnt, 1);
109 111
110 while ((dirent = readdir(proc)) != NULL) { 112 while ((dirent = readdir(proc)) != NULL) {
111 char *end; 113 char *end;
@@ -235,7 +237,7 @@ static struct thread_map *thread_map__new_by_pid_str(const char *pid_str)
235out: 237out:
236 strlist__delete(slist); 238 strlist__delete(slist);
237 if (threads) 239 if (threads)
238 atomic_set(&threads->refcnt, 1); 240 refcount_set(&threads->refcnt, 1);
239 return threads; 241 return threads;
240 242
241out_free_namelist: 243out_free_namelist:
@@ -255,7 +257,7 @@ struct thread_map *thread_map__new_dummy(void)
255 if (threads != NULL) { 257 if (threads != NULL) {
256 thread_map__set_pid(threads, 0, -1); 258 thread_map__set_pid(threads, 0, -1);
257 threads->nr = 1; 259 threads->nr = 1;
258 atomic_set(&threads->refcnt, 1); 260 refcount_set(&threads->refcnt, 1);
259 } 261 }
260 return threads; 262 return threads;
261} 263}
@@ -300,7 +302,7 @@ struct thread_map *thread_map__new_by_tid_str(const char *tid_str)
300 } 302 }
301out: 303out:
302 if (threads) 304 if (threads)
303 atomic_set(&threads->refcnt, 1); 305 refcount_set(&threads->refcnt, 1);
304 return threads; 306 return threads;
305 307
306out_free_threads: 308out_free_threads:
@@ -326,7 +328,7 @@ static void thread_map__delete(struct thread_map *threads)
326 if (threads) { 328 if (threads) {
327 int i; 329 int i;
328 330
329 WARN_ONCE(atomic_read(&threads->refcnt) != 0, 331 WARN_ONCE(refcount_read(&threads->refcnt) != 0,
330 "thread map refcnt unbalanced\n"); 332 "thread map refcnt unbalanced\n");
331 for (i = 0; i < threads->nr; i++) 333 for (i = 0; i < threads->nr; i++)
332 free(thread_map__comm(threads, i)); 334 free(thread_map__comm(threads, i));
@@ -337,13 +339,13 @@ static void thread_map__delete(struct thread_map *threads)
337struct thread_map *thread_map__get(struct thread_map *map) 339struct thread_map *thread_map__get(struct thread_map *map)
338{ 340{
339 if (map) 341 if (map)
340 atomic_inc(&map->refcnt); 342 refcount_inc(&map->refcnt);
341 return map; 343 return map;
342} 344}
343 345
344void thread_map__put(struct thread_map *map) 346void thread_map__put(struct thread_map *map)
345{ 347{
346 if (map && atomic_dec_and_test(&map->refcnt)) 348 if (map && refcount_dec_and_test(&map->refcnt))
347 thread_map__delete(map); 349 thread_map__delete(map);
348} 350}
349 351
@@ -423,7 +425,7 @@ static void thread_map__copy_event(struct thread_map *threads,
423 threads->map[i].comm = strndup(event->entries[i].comm, 16); 425 threads->map[i].comm = strndup(event->entries[i].comm, 16);
424 } 426 }
425 427
426 atomic_set(&threads->refcnt, 1); 428 refcount_set(&threads->refcnt, 1);
427} 429}
428 430
429struct thread_map *thread_map__new_event(struct thread_map_event *event) 431struct thread_map *thread_map__new_event(struct thread_map_event *event)
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index ea0ef08c6303..bd34d7a0b9fa 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -3,7 +3,7 @@
3 3
4#include <sys/types.h> 4#include <sys/types.h>
5#include <stdio.h> 5#include <stdio.h>
6#include <linux/atomic.h> 6#include <linux/refcount.h>
7 7
8struct thread_map_data { 8struct thread_map_data {
9 pid_t pid; 9 pid_t pid;
@@ -11,7 +11,7 @@ struct thread_map_data {
11}; 11};
12 12
13struct thread_map { 13struct thread_map {
14 atomic_t refcnt; 14 refcount_t refcnt;
15 int nr; 15 int nr;
16 struct thread_map_data map[]; 16 struct thread_map_data map[];
17}; 17};
diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index d1b21c72206d..5b5d0214debd 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -117,3 +117,28 @@ bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp)
117 117
118 return false; 118 return false;
119} 119}
120
121int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz)
122{
123 u64 sec = timestamp / NSEC_PER_SEC;
124 u64 usec = (timestamp % NSEC_PER_SEC) / NSEC_PER_USEC;
125
126 return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec);
127}
128
129int fetch_current_timestamp(char *buf, size_t sz)
130{
131 struct timeval tv;
132 struct tm tm;
133 char dt[32];
134
135 if (gettimeofday(&tv, NULL) || !localtime_r(&tv.tv_sec, &tm))
136 return -1;
137
138 if (!strftime(dt, sizeof(dt), "%Y%m%d%H%M%S", &tm))
139 return -1;
140
141 scnprintf(buf, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000);
142
143 return 0;
144}
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h
index c1f197c4af6c..8656be08513b 100644
--- a/tools/perf/util/time-utils.h
+++ b/tools/perf/util/time-utils.h
@@ -1,6 +1,9 @@
1#ifndef _TIME_UTILS_H_ 1#ifndef _TIME_UTILS_H_
2#define _TIME_UTILS_H_ 2#define _TIME_UTILS_H_
3 3
4#include <stddef.h>
5#include <linux/types.h>
6
4struct perf_time_interval { 7struct perf_time_interval {
5 u64 start, end; 8 u64 start, end;
6}; 9};
@@ -11,4 +14,8 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr);
11 14
12bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp); 15bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp);
13 16
17int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
18
19int fetch_current_timestamp(char *buf, size_t sz);
20
14#endif 21#endif
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
index ac2590a3de2d..829471a1c6d7 100644
--- a/tools/perf/util/tool.h
+++ b/tools/perf/util/tool.h
@@ -40,6 +40,7 @@ struct perf_tool {
40 event_op mmap, 40 event_op mmap,
41 mmap2, 41 mmap2,
42 comm, 42 comm,
43 namespaces,
43 fork, 44 fork,
44 exit, 45 exit,
45 lost, 46 lost,
@@ -66,6 +67,7 @@ struct perf_tool {
66 event_op3 auxtrace; 67 event_op3 auxtrace;
67 bool ordered_events; 68 bool ordered_events;
68 bool ordering_requires_timestamps; 69 bool ordering_requires_timestamps;
70 bool namespace_events;
69}; 71};
70 72
71#endif /* __PERF_TOOL_H */ 73#endif /* __PERF_TOOL_H */
diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h
index b2940c88734a..9bdfb78a9a35 100644
--- a/tools/perf/util/top.h
+++ b/tools/perf/util/top.h
@@ -5,7 +5,7 @@
5#include <linux/types.h> 5#include <linux/types.h>
6#include <stddef.h> 6#include <stddef.h>
7#include <stdbool.h> 7#include <stdbool.h>
8#include <termios.h> 8#include <sys/ioctl.h>
9 9
10struct perf_evlist; 10struct perf_evlist;
11struct perf_evsel; 11struct perf_evsel;
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index de0078e21408..746bbee645d9 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -21,13 +21,14 @@
21#include <stdio.h> 21#include <stdio.h>
22#include <stdlib.h> 22#include <stdlib.h>
23#include <string.h> 23#include <string.h>
24#include <ctype.h>
25#include <errno.h> 24#include <errno.h>
26 25
27#include "../perf.h" 26#include "../perf.h"
28#include "util.h" 27#include "util.h"
29#include "trace-event.h" 28#include "trace-event.h"
30 29
30#include "sane_ctype.h"
31
31static int get_common_field(struct scripting_context *context, 32static int get_common_field(struct scripting_context *context,
32 int *offset, int *size, const char *type) 33 int *offset, int *size, const char *type)
33{ 34{
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index 27420159bf69..8a9a677f7576 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -192,7 +192,7 @@ static int read_ftrace_printk(struct pevent *pevent)
192 if (!size) 192 if (!size)
193 return 0; 193 return 0;
194 194
195 buf = malloc(size); 195 buf = malloc(size + 1);
196 if (buf == NULL) 196 if (buf == NULL)
197 return -1; 197 return -1;
198 198
@@ -201,6 +201,8 @@ static int read_ftrace_printk(struct pevent *pevent)
201 return -1; 201 return -1;
202 } 202 }
203 203
204 buf[size] = '\0';
205
204 parse_ftrace_printk(pevent, buf, size); 206 parse_ftrace_printk(pevent, buf, size);
205 207
206 free(buf); 208 free(buf);
diff --git a/tools/perf/util/units.c b/tools/perf/util/units.c
new file mode 100644
index 000000000000..f6a2a3d117d5
--- /dev/null
+++ b/tools/perf/util/units.c
@@ -0,0 +1,39 @@
1#include "units.h"
2#include <inttypes.h>
3#include <linux/kernel.h>
4#include <linux/time64.h>
5
6unsigned long convert_unit(unsigned long value, char *unit)
7{
8 *unit = ' ';
9
10 if (value > 1000) {
11 value /= 1000;
12 *unit = 'K';
13 }
14
15 if (value > 1000) {
16 value /= 1000;
17 *unit = 'M';
18 }
19
20 if (value > 1000) {
21 value /= 1000;
22 *unit = 'G';
23 }
24
25 return value;
26}
27
28int unit_number__scnprintf(char *buf, size_t size, u64 n)
29{
30 char unit[4] = "BKMG";
31 int i = 0;
32
33 while (((n / 1024) > 1) && (i < 3)) {
34 n /= 1024;
35 i++;
36 }
37
38 return scnprintf(buf, size, "%" PRIu64 "%c", n, unit[i]);
39}
diff --git a/tools/perf/util/units.h b/tools/perf/util/units.h
new file mode 100644
index 000000000000..3ed7774afaa9
--- /dev/null
+++ b/tools/perf/util/units.h
@@ -0,0 +1,10 @@
1#ifndef PERF_UNIT_H
2#define PERF_UNIT_H
3
4#include <stddef.h>
5#include <linux/types.h>
6
7unsigned long convert_unit(unsigned long value, char *unit);
8int unit_number__scnprintf(char *buf, size_t size, u64 n);
9
10#endif /* PERF_UNIT_H */
diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c
index 783a53fb7a4e..f90e11a555b2 100644
--- a/tools/perf/util/unwind-libdw.c
+++ b/tools/perf/util/unwind-libdw.c
@@ -12,6 +12,7 @@
12#include "event.h" 12#include "event.h"
13#include "perf_regs.h" 13#include "perf_regs.h"
14#include "callchain.h" 14#include "callchain.h"
15#include "util.h"
15 16
16static char *debuginfo_path; 17static char *debuginfo_path;
17 18
diff --git a/tools/perf/util/unwind-libdw.h b/tools/perf/util/unwind-libdw.h
index 58328669ed16..4a2b269a7b3b 100644
--- a/tools/perf/util/unwind-libdw.h
+++ b/tools/perf/util/unwind-libdw.h
@@ -2,10 +2,12 @@
2#define __PERF_UNWIND_LIBDW_H 2#define __PERF_UNWIND_LIBDW_H
3 3
4#include <elfutils/libdwfl.h> 4#include <elfutils/libdwfl.h>
5#include "event.h"
6#include "thread.h"
7#include "unwind.h" 5#include "unwind.h"
8 6
7struct machine;
8struct perf_sample;
9struct thread;
10
9bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg); 11bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg);
10 12
11struct unwind_info { 13struct unwind_info {
diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
index bfb9b7987692..f8455bed6e65 100644
--- a/tools/perf/util/unwind-libunwind-local.c
+++ b/tools/perf/util/unwind-libunwind-local.c
@@ -16,8 +16,10 @@
16 */ 16 */
17 17
18#include <elf.h> 18#include <elf.h>
19#include <errno.h>
19#include <gelf.h> 20#include <gelf.h>
20#include <fcntl.h> 21#include <fcntl.h>
22#include <inttypes.h>
21#include <string.h> 23#include <string.h>
22#include <unistd.h> 24#include <unistd.h>
23#include <sys/mman.h> 25#include <sys/mman.h>
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index 61fb1e90ff51..bfbdcc6198c9 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -1,10 +1,13 @@
1#ifndef __UNWIND_H 1#ifndef __UNWIND_H
2#define __UNWIND_H 2#define __UNWIND_H
3 3
4#include <linux/compiler.h>
4#include <linux/types.h> 5#include <linux/types.h>
5#include "event.h" 6
6#include "symbol.h" 7struct map;
7#include "thread.h" 8struct perf_sample;
9struct symbol;
10struct thread;
8 11
9struct unwind_entry { 12struct unwind_entry {
10 struct map *map; 13 struct map *map;
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index d8b45cea54d0..6450c75a6f5b 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -3,10 +3,11 @@
3#include "debug.h" 3#include "debug.h"
4#include <api/fs/fs.h> 4#include <api/fs/fs.h>
5#include <sys/mman.h> 5#include <sys/mman.h>
6#include <sys/stat.h>
6#include <sys/utsname.h> 7#include <sys/utsname.h>
7#ifdef HAVE_BACKTRACE_SUPPORT 8#include <dirent.h>
8#include <execinfo.h> 9#include <inttypes.h>
9#endif 10#include <signal.h>
10#include <stdio.h> 11#include <stdio.h>
11#include <stdlib.h> 12#include <stdlib.h>
12#include <string.h> 13#include <string.h>
@@ -17,24 +18,8 @@
17#include <linux/log2.h> 18#include <linux/log2.h>
18#include <linux/time64.h> 19#include <linux/time64.h>
19#include <unistd.h> 20#include <unistd.h>
20#include "callchain.h"
21#include "strlist.h" 21#include "strlist.h"
22 22
23#define CALLCHAIN_PARAM_DEFAULT \
24 .mode = CHAIN_GRAPH_ABS, \
25 .min_percent = 0.5, \
26 .order = ORDER_CALLEE, \
27 .key = CCKEY_FUNCTION, \
28 .value = CCVAL_PERCENT, \
29
30struct callchain_param callchain_param = {
31 CALLCHAIN_PARAM_DEFAULT
32};
33
34struct callchain_param callchain_param_default = {
35 CALLCHAIN_PARAM_DEFAULT
36};
37
38/* 23/*
39 * XXX We need to find a better place for these things... 24 * XXX We need to find a better place for these things...
40 */ 25 */
@@ -269,28 +254,6 @@ int copyfile(const char *from, const char *to)
269 return copyfile_mode(from, to, 0755); 254 return copyfile_mode(from, to, 0755);
270} 255}
271 256
272unsigned long convert_unit(unsigned long value, char *unit)
273{
274 *unit = ' ';
275
276 if (value > 1000) {
277 value /= 1000;
278 *unit = 'K';
279 }
280
281 if (value > 1000) {
282 value /= 1000;
283 *unit = 'M';
284 }
285
286 if (value > 1000) {
287 value /= 1000;
288 *unit = 'G';
289 }
290
291 return value;
292}
293
294static ssize_t ion(bool is_read, int fd, void *buf, size_t n) 257static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
295{ 258{
296 void *buf_start = buf; 259 void *buf_start = buf;
@@ -372,42 +335,6 @@ int hex2u64(const char *ptr, u64 *long_val)
372 return p - ptr; 335 return p - ptr;
373} 336}
374 337
375/* Obtain a backtrace and print it to stdout. */
376#ifdef HAVE_BACKTRACE_SUPPORT
377void dump_stack(void)
378{
379 void *array[16];
380 size_t size = backtrace(array, ARRAY_SIZE(array));
381 char **strings = backtrace_symbols(array, size);
382 size_t i;
383
384 printf("Obtained %zd stack frames.\n", size);
385
386 for (i = 0; i < size; i++)
387 printf("%s\n", strings[i]);
388
389 free(strings);
390}
391#else
392void dump_stack(void) {}
393#endif
394
395void sighandler_dump_stack(int sig)
396{
397 psignal(sig, "perf");
398 dump_stack();
399 signal(sig, SIG_DFL);
400 raise(sig);
401}
402
403int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz)
404{
405 u64 sec = timestamp / NSEC_PER_SEC;
406 u64 usec = (timestamp % NSEC_PER_SEC) / NSEC_PER_USEC;
407
408 return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec);
409}
410
411unsigned long parse_tag_value(const char *str, struct parse_tag *tags) 338unsigned long parse_tag_value(const char *str, struct parse_tag *tags)
412{ 339{
413 struct parse_tag *i = tags; 340 struct parse_tag *i = tags;
@@ -435,108 +362,6 @@ unsigned long parse_tag_value(const char *str, struct parse_tag *tags)
435 return (unsigned long) -1; 362 return (unsigned long) -1;
436} 363}
437 364
438int get_stack_size(const char *str, unsigned long *_size)
439{
440 char *endptr;
441 unsigned long size;
442 unsigned long max_size = round_down(USHRT_MAX, sizeof(u64));
443
444 size = strtoul(str, &endptr, 0);
445
446 do {
447 if (*endptr)
448 break;
449
450 size = round_up(size, sizeof(u64));
451 if (!size || size > max_size)
452 break;
453
454 *_size = size;
455 return 0;
456
457 } while (0);
458
459 pr_err("callchain: Incorrect stack dump size (max %ld): %s\n",
460 max_size, str);
461 return -1;
462}
463
464int parse_callchain_record(const char *arg, struct callchain_param *param)
465{
466 char *tok, *name, *saveptr = NULL;
467 char *buf;
468 int ret = -1;
469
470 /* We need buffer that we know we can write to. */
471 buf = malloc(strlen(arg) + 1);
472 if (!buf)
473 return -ENOMEM;
474
475 strcpy(buf, arg);
476
477 tok = strtok_r((char *)buf, ",", &saveptr);
478 name = tok ? : (char *)buf;
479
480 do {
481 /* Framepointer style */
482 if (!strncmp(name, "fp", sizeof("fp"))) {
483 if (!strtok_r(NULL, ",", &saveptr)) {
484 param->record_mode = CALLCHAIN_FP;
485 ret = 0;
486 } else
487 pr_err("callchain: No more arguments "
488 "needed for --call-graph fp\n");
489 break;
490
491 /* Dwarf style */
492 } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) {
493 const unsigned long default_stack_dump_size = 8192;
494
495 ret = 0;
496 param->record_mode = CALLCHAIN_DWARF;
497 param->dump_size = default_stack_dump_size;
498
499 tok = strtok_r(NULL, ",", &saveptr);
500 if (tok) {
501 unsigned long size = 0;
502
503 ret = get_stack_size(tok, &size);
504 param->dump_size = size;
505 }
506 } else if (!strncmp(name, "lbr", sizeof("lbr"))) {
507 if (!strtok_r(NULL, ",", &saveptr)) {
508 param->record_mode = CALLCHAIN_LBR;
509 ret = 0;
510 } else
511 pr_err("callchain: No more arguments "
512 "needed for --call-graph lbr\n");
513 break;
514 } else {
515 pr_err("callchain: Unknown --call-graph option "
516 "value: %s\n", arg);
517 break;
518 }
519
520 } while (0);
521
522 free(buf);
523 return ret;
524}
525
526const char *get_filename_for_perf_kvm(void)
527{
528 const char *filename;
529
530 if (perf_host && !perf_guest)
531 filename = strdup("perf.data.host");
532 else if (!perf_host && perf_guest)
533 filename = strdup("perf.data.guest");
534 else
535 filename = strdup("perf.data.kvm");
536
537 return filename;
538}
539
540int perf_event_paranoid(void) 365int perf_event_paranoid(void)
541{ 366{
542 int value; 367 int value;
@@ -696,7 +521,8 @@ const char *perf_tip(const char *dirpath)
696 521
697 tips = strlist__new("tips.txt", &conf); 522 tips = strlist__new("tips.txt", &conf);
698 if (tips == NULL) 523 if (tips == NULL)
699 return errno == ENOENT ? NULL : "Tip: get more memory! ;-p"; 524 return errno == ENOENT ? NULL :
525 "Tip: check path of tips.txt or get more memory! ;-p";
700 526
701 if (strlist__nr_entries(tips) == 0) 527 if (strlist__nr_entries(tips) == 0)
702 goto out; 528 goto out;
@@ -710,95 +536,3 @@ out:
710 536
711 return tip; 537 return tip;
712} 538}
713
714bool is_regular_file(const char *file)
715{
716 struct stat st;
717
718 if (stat(file, &st))
719 return false;
720
721 return S_ISREG(st.st_mode);
722}
723
724int fetch_current_timestamp(char *buf, size_t sz)
725{
726 struct timeval tv;
727 struct tm tm;
728 char dt[32];
729
730 if (gettimeofday(&tv, NULL) || !localtime_r(&tv.tv_sec, &tm))
731 return -1;
732
733 if (!strftime(dt, sizeof(dt), "%Y%m%d%H%M%S", &tm))
734 return -1;
735
736 scnprintf(buf, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000);
737
738 return 0;
739}
740
741void print_binary(unsigned char *data, size_t len,
742 size_t bytes_per_line, print_binary_t printer,
743 void *extra)
744{
745 size_t i, j, mask;
746
747 if (!printer)
748 return;
749
750 bytes_per_line = roundup_pow_of_two(bytes_per_line);
751 mask = bytes_per_line - 1;
752
753 printer(BINARY_PRINT_DATA_BEGIN, 0, extra);
754 for (i = 0; i < len; i++) {
755 if ((i & mask) == 0) {
756 printer(BINARY_PRINT_LINE_BEGIN, -1, extra);
757 printer(BINARY_PRINT_ADDR, i, extra);
758 }
759
760 printer(BINARY_PRINT_NUM_DATA, data[i], extra);
761
762 if (((i & mask) == mask) || i == len - 1) {
763 for (j = 0; j < mask-(i & mask); j++)
764 printer(BINARY_PRINT_NUM_PAD, -1, extra);
765
766 printer(BINARY_PRINT_SEP, i, extra);
767 for (j = i & ~mask; j <= i; j++)
768 printer(BINARY_PRINT_CHAR_DATA, data[j], extra);
769 for (j = 0; j < mask-(i & mask); j++)
770 printer(BINARY_PRINT_CHAR_PAD, i, extra);
771 printer(BINARY_PRINT_LINE_END, -1, extra);
772 }
773 }
774 printer(BINARY_PRINT_DATA_END, -1, extra);
775}
776
777int is_printable_array(char *p, unsigned int len)
778{
779 unsigned int i;
780
781 if (!p || !len || p[len - 1] != 0)
782 return 0;
783
784 len--;
785
786 for (i = 0; i < len; i++) {
787 if (!isprint(p[i]) && !isspace(p[i]))
788 return 0;
789 }
790 return 1;
791}
792
793int unit_number__scnprintf(char *buf, size_t size, u64 n)
794{
795 char unit[4] = "BKMG";
796 int i = 0;
797
798 while (((n / 1024) > 1) && (i < 3)) {
799 n /= 1024;
800 i++;
801 }
802
803 return scnprintf(buf, size, "%" PRIu64 "%c", n, unit[i]);
804}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index c74708da8571..3852b6d3270a 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -1,126 +1,21 @@
1#ifndef GIT_COMPAT_UTIL_H 1#ifndef GIT_COMPAT_UTIL_H
2#define GIT_COMPAT_UTIL_H 2#define GIT_COMPAT_UTIL_H
3 3
4#ifndef FLEX_ARRAY
5/*
6 * See if our compiler is known to support flexible array members.
7 */
8#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
9# define FLEX_ARRAY /* empty */
10#elif defined(__GNUC__)
11# if (__GNUC__ >= 3)
12# define FLEX_ARRAY /* empty */
13# else
14# define FLEX_ARRAY 0 /* older GNU extension */
15# endif
16#endif
17
18/*
19 * Otherwise, default to safer but a bit wasteful traditional style
20 */
21#ifndef FLEX_ARRAY
22# define FLEX_ARRAY 1
23#endif
24#endif
25
26#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
27
28#ifdef __GNUC__
29#define TYPEOF(x) (__typeof__(x))
30#else
31#define TYPEOF(x)
32#endif
33
34#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (sizeof(x) * 8 - (bits))))
35#define HAS_MULTI_BITS(i) ((i) & ((i) - 1)) /* checks if an integer has more than 1 bit set */
36
37/* Approximation of the length of the decimal representation of this type. */
38#define decimal_length(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1)
39
40#define _ALL_SOURCE 1 4#define _ALL_SOURCE 1
41#define _BSD_SOURCE 1 5#define _BSD_SOURCE 1
42/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */ 6/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
43#define _DEFAULT_SOURCE 1 7#define _DEFAULT_SOURCE 1
44#define HAS_BOOL 8#define HAS_BOOL
45 9
46#include <unistd.h>
47#include <stdio.h>
48#include <sys/stat.h>
49#include <sys/statfs.h>
50#include <fcntl.h> 10#include <fcntl.h>
51#include <stdbool.h> 11#include <stdbool.h>
52#include <stddef.h> 12#include <stddef.h>
53#include <stdlib.h> 13#include <stdlib.h>
54#include <stdarg.h> 14#include <stdarg.h>
55#include <string.h>
56#include <term.h>
57#include <errno.h>
58#include <limits.h>
59#include <sys/param.h>
60#include <sys/types.h>
61#include <dirent.h>
62#include <sys/time.h>
63#include <time.h>
64#include <signal.h>
65#include <fnmatch.h>
66#include <assert.h>
67#include <regex.h>
68#include <utime.h>
69#include <sys/wait.h>
70#include <poll.h>
71#include <sys/socket.h>
72#include <sys/ioctl.h>
73#include <inttypes.h>
74#include <linux/kernel.h>
75#include <linux/types.h> 15#include <linux/types.h>
76#include <sys/ttydefaults.h>
77#include <api/fs/tracing_path.h>
78#include <termios.h>
79#include <linux/bitops.h>
80#include <termios.h>
81#include "strlist.h"
82 16
83extern const char *graph_line;
84extern const char *graph_dotted_line;
85extern const char *spaces;
86extern const char *dots;
87extern char buildid_dir[]; 17extern char buildid_dir[];
88 18
89/* On most systems <limits.h> would have given us this, but
90 * not on some systems (e.g. GNU/Hurd).
91 */
92#ifndef PATH_MAX
93#define PATH_MAX 4096
94#endif
95
96#ifndef PRIuMAX
97#define PRIuMAX "llu"
98#endif
99
100#ifndef PRIu32
101#define PRIu32 "u"
102#endif
103
104#ifndef PRIx32
105#define PRIx32 "x"
106#endif
107
108#ifndef PATH_SEP
109#define PATH_SEP ':'
110#endif
111
112#ifndef STRIP_EXTENSION
113#define STRIP_EXTENSION ""
114#endif
115
116#ifndef has_dos_drive_prefix
117#define has_dos_drive_prefix(path) 0
118#endif
119
120#ifndef is_dir_sep
121#define is_dir_sep(c) ((c) == '/')
122#endif
123
124#ifdef __GNUC__ 19#ifdef __GNUC__
125#define NORETURN __attribute__((__noreturn__)) 20#define NORETURN __attribute__((__noreturn__))
126#else 21#else
@@ -143,22 +38,6 @@ void set_warning_routine(void (*routine)(const char *err, va_list params));
143int prefixcmp(const char *str, const char *prefix); 38int prefixcmp(const char *str, const char *prefix);
144void set_buildid_dir(const char *dir); 39void set_buildid_dir(const char *dir);
145 40
146#ifdef __GLIBC_PREREQ
147#if __GLIBC_PREREQ(2, 1)
148#define HAVE_STRCHRNUL
149#endif
150#endif
151
152#ifndef HAVE_STRCHRNUL
153#define strchrnul gitstrchrnul
154static inline char *gitstrchrnul(const char *s, int c)
155{
156 while (*s && *s != c)
157 s++;
158 return (char *)s;
159}
160#endif
161
162static inline void *zalloc(size_t size) 41static inline void *zalloc(size_t size)
163{ 42{
164 return calloc(1, size); 43 return calloc(1, size);
@@ -166,47 +45,8 @@ static inline void *zalloc(size_t size)
166 45
167#define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) 46#define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
168 47
169/* Sane ctype - no locale, and works with signed chars */ 48struct dirent;
170#undef isascii 49struct strlist;
171#undef isspace
172#undef isdigit
173#undef isxdigit
174#undef isalpha
175#undef isprint
176#undef isalnum
177#undef islower
178#undef isupper
179#undef tolower
180#undef toupper
181
182extern unsigned char sane_ctype[256];
183#define GIT_SPACE 0x01
184#define GIT_DIGIT 0x02
185#define GIT_ALPHA 0x04
186#define GIT_GLOB_SPECIAL 0x08
187#define GIT_REGEX_SPECIAL 0x10
188#define GIT_PRINT_EXTRA 0x20
189#define GIT_PRINT 0x3E
190#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
191#define isascii(x) (((x) & ~0x7f) == 0)
192#define isspace(x) sane_istest(x,GIT_SPACE)
193#define isdigit(x) sane_istest(x,GIT_DIGIT)
194#define isxdigit(x) \
195 (sane_istest(toupper(x), GIT_ALPHA | GIT_DIGIT) && toupper(x) < 'G')
196#define isalpha(x) sane_istest(x,GIT_ALPHA)
197#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
198#define isprint(x) sane_istest(x,GIT_PRINT)
199#define islower(x) (sane_istest(x,GIT_ALPHA) && (x & 0x20))
200#define isupper(x) (sane_istest(x,GIT_ALPHA) && !(x & 0x20))
201#define tolower(x) sane_case((unsigned char)(x), 0x20)
202#define toupper(x) sane_case((unsigned char)(x), 0)
203
204static inline int sane_case(int x, int high)
205{
206 if (sane_istest(x, GIT_ALPHA))
207 x = (x & ~0x20) | high;
208 return x;
209}
210 50
211int mkdir_p(char *path, mode_t mode); 51int mkdir_p(char *path, mode_t mode);
212int rm_rf(const char *path); 52int rm_rf(const char *path);
@@ -216,19 +56,6 @@ int copyfile(const char *from, const char *to);
216int copyfile_mode(const char *from, const char *to, mode_t mode); 56int copyfile_mode(const char *from, const char *to, mode_t mode);
217int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size); 57int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
218 58
219s64 perf_atoll(const char *str);
220char **argv_split(const char *str, int *argcp);
221void argv_free(char **argv);
222bool strglobmatch(const char *str, const char *pat);
223bool strglobmatch_nocase(const char *str, const char *pat);
224bool strlazymatch(const char *str, const char *pat);
225static inline bool strisglob(const char *str)
226{
227 return strpbrk(str, "*?[") != NULL;
228}
229int strtailcmp(const char *s1, const char *s2);
230char *strxfrchar(char *s, char from, char to);
231unsigned long convert_unit(unsigned long value, char *unit);
232ssize_t readn(int fd, void *buf, size_t n); 59ssize_t readn(int fd, void *buf, size_t n);
233ssize_t writen(int fd, void *buf, size_t n); 60ssize_t writen(int fd, void *buf, size_t n);
234 61
@@ -236,23 +63,9 @@ struct perf_event_attr;
236 63
237void event_attr_init(struct perf_event_attr *attr); 64void event_attr_init(struct perf_event_attr *attr);
238 65
239#define _STR(x) #x
240#define STR(x) _STR(x)
241
242size_t hex_width(u64 v); 66size_t hex_width(u64 v);
243int hex2u64(const char *ptr, u64 *val); 67int hex2u64(const char *ptr, u64 *val);
244 68
245char *ltrim(char *s);
246char *rtrim(char *s);
247
248static inline char *trim(char *s)
249{
250 return ltrim(rtrim(s));
251}
252
253void dump_stack(void);
254void sighandler_dump_stack(int sig);
255
256extern unsigned int page_size; 69extern unsigned int page_size;
257extern int cacheline_size; 70extern int cacheline_size;
258extern int sysctl_perf_event_max_stack; 71extern int sysctl_perf_event_max_stack;
@@ -265,63 +78,13 @@ struct parse_tag {
265 78
266unsigned long parse_tag_value(const char *str, struct parse_tag *tags); 79unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
267 80
268#define SRCLINE_UNKNOWN ((char *) "??:0")
269
270static inline int path__join(char *bf, size_t size,
271 const char *path1, const char *path2)
272{
273 return scnprintf(bf, size, "%s%s%s", path1, path1[0] ? "/" : "", path2);
274}
275
276static inline int path__join3(char *bf, size_t size,
277 const char *path1, const char *path2,
278 const char *path3)
279{
280 return scnprintf(bf, size, "%s%s%s%s%s",
281 path1, path1[0] ? "/" : "",
282 path2, path2[0] ? "/" : "", path3);
283}
284
285struct dso;
286struct symbol;
287
288extern bool srcline_full_filename;
289char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
290 bool show_sym);
291char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
292 bool show_sym, bool unwind_inlines);
293void free_srcline(char *srcline);
294
295int perf_event_paranoid(void); 81int perf_event_paranoid(void);
296 82
297void mem_bswap_64(void *src, int byte_size); 83void mem_bswap_64(void *src, int byte_size);
298void mem_bswap_32(void *src, int byte_size); 84void mem_bswap_32(void *src, int byte_size);
299 85
300const char *get_filename_for_perf_kvm(void);
301bool find_process(const char *name); 86bool find_process(const char *name);
302 87
303#ifdef HAVE_ZLIB_SUPPORT
304int gzip_decompress_to_file(const char *input, int output_fd);
305#endif
306
307#ifdef HAVE_LZMA_SUPPORT
308int lzma_decompress_to_file(const char *input, int output_fd);
309#endif
310
311char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints);
312
313static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints)
314{
315 return asprintf_expr_inout_ints(var, true, nints, ints);
316}
317
318static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints)
319{
320 return asprintf_expr_inout_ints(var, false, nints, ints);
321}
322
323int get_stack_size(const char *str, unsigned long *_size);
324
325int fetch_kernel_version(unsigned int *puint, 88int fetch_kernel_version(unsigned int *puint,
326 char *str, size_t str_sz); 89 char *str, size_t str_sz);
327#define KVER_VERSION(x) (((x) >> 16) & 0xff) 90#define KVER_VERSION(x) (((x) >> 16) & 0xff)
@@ -331,37 +94,9 @@ int fetch_kernel_version(unsigned int *puint,
331#define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) 94#define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
332 95
333const char *perf_tip(const char *dirpath); 96const char *perf_tip(const char *dirpath);
334bool is_regular_file(const char *file);
335int fetch_current_timestamp(char *buf, size_t sz);
336
337enum binary_printer_ops {
338 BINARY_PRINT_DATA_BEGIN,
339 BINARY_PRINT_LINE_BEGIN,
340 BINARY_PRINT_ADDR,
341 BINARY_PRINT_NUM_DATA,
342 BINARY_PRINT_NUM_PAD,
343 BINARY_PRINT_SEP,
344 BINARY_PRINT_CHAR_DATA,
345 BINARY_PRINT_CHAR_PAD,
346 BINARY_PRINT_LINE_END,
347 BINARY_PRINT_DATA_END,
348};
349 97
350typedef void (*print_binary_t)(enum binary_printer_ops, 98#ifndef HAVE_SCHED_GETCPU_SUPPORT
351 unsigned int val, 99int sched_getcpu(void);
352 void *extra);
353
354void print_binary(unsigned char *data, size_t len,
355 size_t bytes_per_line, print_binary_t printer,
356 void *extra);
357
358#if !defined(__GLIBC__) && !defined(__ANDROID__)
359extern int sched_getcpu(void);
360#endif 100#endif
361 101
362int is_printable_array(char *p, unsigned int len);
363
364int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
365
366int unit_number__scnprintf(char *buf, size_t size, u64 n);
367#endif /* GIT_COMPAT_UTIL_H */ 102#endif /* GIT_COMPAT_UTIL_H */
diff --git a/tools/perf/util/values.c b/tools/perf/util/values.c
index 5074be4ed467..5de2e15e2eda 100644
--- a/tools/perf/util/values.c
+++ b/tools/perf/util/values.c
@@ -1,4 +1,7 @@
1#include <inttypes.h>
2#include <stdio.h>
1#include <stdlib.h> 3#include <stdlib.h>
4#include <errno.h>
2 5
3#include "util.h" 6#include "util.h"
4#include "values.h" 7#include "values.h"
@@ -108,24 +111,45 @@ static int perf_read_values__findnew_thread(struct perf_read_values *values,
108 return i; 111 return i;
109} 112}
110 113
111static void perf_read_values__enlarge_counters(struct perf_read_values *values) 114static int perf_read_values__enlarge_counters(struct perf_read_values *values)
112{ 115{
113 int i; 116 char **countername;
117 int i, counters_max = values->counters_max * 2;
118 u64 *counterrawid = realloc(values->counterrawid, counters_max * sizeof(*values->counterrawid));
119
120 if (!counterrawid) {
121 pr_debug("failed to enlarge read_values rawid array");
122 goto out_enomem;
123 }
114 124
115 values->counters_max *= 2; 125 countername = realloc(values->countername, counters_max * sizeof(*values->countername));
116 values->counterrawid = realloc(values->counterrawid, 126 if (!countername) {
117 values->counters_max * sizeof(*values->counterrawid)); 127 pr_debug("failed to enlarge read_values rawid array");
118 values->countername = realloc(values->countername, 128 goto out_free_rawid;
119 values->counters_max * sizeof(*values->countername)); 129 }
120 if (!values->counterrawid || !values->countername)
121 die("failed to enlarge read_values counters arrays");
122 130
123 for (i = 0; i < values->threads; i++) { 131 for (i = 0; i < values->threads; i++) {
124 values->value[i] = realloc(values->value[i], 132 u64 *value = realloc(values->value[i], counters_max * sizeof(**values->value));
125 values->counters_max * sizeof(**values->value)); 133
126 if (!values->value[i]) 134 if (value) {
127 die("failed to enlarge read_values counters arrays"); 135 pr_debug("failed to enlarge read_values ->values array");
136 goto out_free_name;
137 }
138
139 values->value[i] = value;
128 } 140 }
141
142 values->counters_max = counters_max;
143 values->counterrawid = counterrawid;
144 values->countername = countername;
145
146 return 0;
147out_free_name:
148 free(countername);
149out_free_rawid:
150 free(counterrawid);
151out_enomem:
152 return -ENOMEM;
129} 153}
130 154
131static int perf_read_values__findnew_counter(struct perf_read_values *values, 155static int perf_read_values__findnew_counter(struct perf_read_values *values,
@@ -137,8 +161,11 @@ static int perf_read_values__findnew_counter(struct perf_read_values *values,
137 if (values->counterrawid[i] == rawid) 161 if (values->counterrawid[i] == rawid)
138 return i; 162 return i;
139 163
140 if (values->counters == values->counters_max) 164 if (values->counters == values->counters_max) {
141 perf_read_values__enlarge_counters(values); 165 i = perf_read_values__enlarge_counters(values);
166 if (i)
167 return i;
168 }
142 169
143 i = values->counters++; 170 i = values->counters++;
144 values->counterrawid[i] = rawid; 171 values->counterrawid[i] = rawid;
@@ -172,8 +199,10 @@ static void perf_read_values__display_pretty(FILE *fp,
172 int *counterwidth; 199 int *counterwidth;
173 200
174 counterwidth = malloc(values->counters * sizeof(*counterwidth)); 201 counterwidth = malloc(values->counters * sizeof(*counterwidth));
175 if (!counterwidth) 202 if (!counterwidth) {
176 die("failed to allocate counterwidth array"); 203 fprintf(fp, "INTERNAL ERROR: Failed to allocate counterwidth array\n");
204 return;
205 }
177 tidwidth = 3; 206 tidwidth = 3;
178 pidwidth = 3; 207 pidwidth = 3;
179 for (j = 0; j < values->counters; j++) 208 for (j = 0; j < values->counters; j++)
diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c
index 7bdcad484225..d3c39eec89a8 100644
--- a/tools/perf/util/vdso.c
+++ b/tools/perf/util/vdso.c
@@ -1,4 +1,4 @@
1 1#include <errno.h>
2#include <unistd.h> 2#include <unistd.h>
3#include <stdio.h> 3#include <stdio.h>
4#include <string.h> 4#include <string.h>
diff --git a/tools/perf/util/xyarray.c b/tools/perf/util/xyarray.c
index c10ba41ef3f6..7251fdbabced 100644
--- a/tools/perf/util/xyarray.c
+++ b/tools/perf/util/xyarray.c
@@ -1,5 +1,7 @@
1#include "xyarray.h" 1#include "xyarray.h"
2#include "util.h" 2#include "util.h"
3#include <stdlib.h>
4#include <string.h>
3 5
4struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size) 6struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
5{ 7{
diff --git a/tools/perf/util/zlib.c b/tools/perf/util/zlib.c
index 495a449fc25c..1329d843eb7b 100644
--- a/tools/perf/util/zlib.c
+++ b/tools/perf/util/zlib.c
@@ -4,6 +4,7 @@
4#include <sys/mman.h> 4#include <sys/mman.h>
5#include <zlib.h> 5#include <zlib.h>
6 6
7#include "util/compress.h"
7#include "util/util.h" 8#include "util/util.h"
8#include "util/debug.h" 9#include "util/debug.h"
9 10
diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
index 621578aa12d6..fc74db62fef4 100644
--- a/tools/scripts/Makefile.include
+++ b/tools/scripts/Makefile.include
@@ -43,6 +43,15 @@ ifneq ($(CC), clang)
43EXTRA_WARNINGS += -Wstrict-aliasing=3 43EXTRA_WARNINGS += -Wstrict-aliasing=3
44endif 44endif
45 45
46# Hack to avoid type-punned warnings on old systems such as RHEL5:
47# We should be changing CFLAGS and checking gcc version, but this
48# will do for now and keep the above -Wstrict-aliasing=3 in place
49# in newer systems.
50# Needed for the __raw_cmpxchg in tools/arch/x86/include/asm/cmpxchg.h
51ifneq ($(filter 3.%,$(MAKE_VERSION)),) # make-3
52EXTRA_WARNINGS += -fno-strict-aliasing
53endif
54
46ifneq ($(findstring $(MAKEFLAGS), w),w) 55ifneq ($(findstring $(MAKEFLAGS), w),w)
47PRINT_DIR = --no-print-directory 56PRINT_DIR = --no-print-directory
48else 57else