projects/linux·commit c206353d

Merge tag 'perf-tools-for-v6.5-2-2023-07-06' of git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next

c206353d · Linus Torvalds <[email protected]> · 2023-07-08 10:21:51 -07:00

Pull more perf tools updates from Namhyung Kim:
 "These are remaining changes and fixes for this cycle.

  Build:

   - Allow generating vmlinux.h from BTF using `make GEN_VMLINUX_H=1`
     and skip if the vmlinux has no BTF.

   - Replace deprecated clang -target xxx option by --target=xxx.

  perf record:

   - Print event attributes with well known type and config symbols in
     the debug output like below:

       # perf record -e cycles,cpu-clock -C0 -vv true
       <SNIP>
       ------------------------------------------------------------
       perf_event_attr:
         type                             0 (PERF_TYPE_HARDWARE)
         size                             136
         config                           0 (PERF_COUNT_HW_CPU_CYCLES)
         { sample_period, sample_freq }   4000
         sample_type                      IP|TID|TIME|CPU|PERIOD|IDENTIFIER
         read_format                      ID
         disabled                         1
         inherit                          1
         freq                             1
         sample_id_all                    1
         exclude_guest                    1
       ------------------------------------------------------------
       sys_perf_event_open: pid -1  cpu 0  group_fd -1  flags 0x8 = 5
       ------------------------------------------------------------
       perf_event_attr:
         type                             1 (PERF_TYPE_SOFTWARE)
         size                             136
         config                           0 (PERF_COUNT_SW_CPU_CLOCK)
         { sample_period, sample_freq }   4000
         sample_type                      IP|TID|TIME|CPU|PERIOD|IDENTIFIER
         read_format                      ID
         disabled                         1
         inherit                          1
         freq                             1
         sample_id_all                    1
         exclude_guest                    1

   - Update AMD IBS event error message since it now support per-process
     profiling but no priviledge filters.

       $ sudo perf record -e ibs_op//k -C 0
       Error:
       AMD IBS doesn't support privilege filtering. Try again without
       the privilege modifiers (like 'k') at the end.

  perf lock contention:

   - Support CSV style output using -x option

       $ sudo perf lock con -ab -x, sleep 1
       # output: contended, total wait, max wait, avg wait, type, caller
       19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
       15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
       4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
       1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
       8, 67608, 27404, 8451, spinlock, __queue_work+0x174
       3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
       3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
       2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
       1, 24619, 24619, 24619, spinlock, rcu_core+0xd4

   - Add --output option to save the data to a file not to be interfered
     by other debug messages.

  Test:

   - Fix event parsing test on ARM where there's no raw PMU nor supports
     PERF_PMU_CAP_EXTENDED_HW_TYPE.

   - Update the lock contention test case for CSV output.

   - Fix a segfault in the daemon command test.

  Vendor events (JSON):

   - Add has_event() to check if the given event is available on system
     at runtime. On Intel machines, some transaction events may not be
     present when TSC extensions are disabled.

   - Update Intel event metrics.

  Misc:

   - Sort symbols by name using an external array of pointers instead of
     a rbtree node in the symbol. This will save 16-bytes or 24-bytes
     per symbol whether the sorting is actually requested or not.

   - Fix unwinding DWARF callstacks using libdw when --symfs option is
     used"

* tag 'perf-tools-for-v6.5-2-2023-07-06' of git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next: (38 commits)
  perf test: Fix event parsing test when PERF_PMU_CAP_EXTENDED_HW_TYPE isn't supported.
  perf test: Fix event parsing test on Arm
  perf evsel amd: Fix IBS error message
  perf: unwind: Fix symfs with libdw
  perf symbol: Fix uninitialized return value in symbols__find_by_name()
  perf test: Test perf lock contention CSV output
  perf lock contention: Add --output option
  perf lock contention: Add -x option for CSV style output
  perf lock: Remove stale comments
  perf vendor events intel: Update tigerlake to 1.13
  perf vendor events intel: Update skylakex to 1.31
  perf vendor events intel: Update skylake to 57
  perf vendor events intel: Update sapphirerapids to 1.14
  perf vendor events intel: Update icelakex to 1.21
  perf vendor events intel: Update icelake to 1.19
  perf vendor events intel: Update cascadelakex to 1.19
  perf vendor events intel: Update meteorlake to 1.03
  perf vendor events intel: Add rocketlake events/metrics
  perf vendor metrics intel: Make transaction metrics conditional
  perf jevents: Support for has_event function
  ...
Commit
c206353dfdf026dafd42679cf82d6f0a89781e36
Parents
ad8258e8 · bcd981db

Merge commit. Changes below are compared with the first parent: ad8258e8.

Changes

95 files changed · +9361 −493

FileStatusAddDelContent
tools/perf/Documentation/perf-config.txtmodified+1−1View file
tools/perf/Documentation/perf-lock.txtmodified+8−0View file
tools/perf/Makefile.configmodified+14−3View file
tools/perf/Makefile.perfmodified+42−3View file
tools/perf/arch/x86/util/evsel.cmodified+20−0View file
tools/perf/builtin-daemon.cmodified+1−1View file
tools/perf/builtin-kallsyms.cmodified+0−1View file
tools/perf/builtin-lock.cmodified+287−98View file
tools/perf/builtin-report.cmodified+0−1View file
tools/perf/pmu-events/arch/x86/alderlake/adl-metrics.jsonmodified+4−4View file
tools/perf/pmu-events/arch/x86/cascadelakex/clx-metrics.jsonmodified+4−4View file
tools/perf/pmu-events/arch/x86/cascadelakex/frontend.jsonmodified+38−5View file
tools/perf/pmu-events/arch/x86/cascadelakex/pipeline.jsonmodified+13−4View file
tools/perf/pmu-events/arch/x86/cascadelakex/uncore-interconnect.jsonmodified+1−1View file
tools/perf/pmu-events/arch/x86/cascadelakex/uncore-memory.jsonmodified+1−1View file
tools/perf/pmu-events/arch/x86/icelake/cache.jsonmodified+4−4View file
tools/perf/pmu-events/arch/x86/icelake/frontend.jsonmodified+28−4View file
tools/perf/pmu-events/arch/x86/icelake/icl-metrics.jsonmodified+4−4View file
tools/perf/pmu-events/arch/x86/icelake/pipeline.jsonmodified+3−3View file
tools/perf/pmu-events/arch/x86/icelakex/frontend.jsonmodified+28−4View file
tools/perf/pmu-events/arch/x86/icelakex/icx-metrics.jsonmodified+4−4View file
tools/perf/pmu-events/arch/x86/icelakex/pipeline.jsonmodified+2−2View file
tools/perf/pmu-events/arch/x86/icelakex/uncore-interconnect.jsonmodified+1−1View file
tools/perf/pmu-events/arch/x86/mapfile.csvmodified+9−8View file
tools/perf/pmu-events/arch/x86/meteorlake/cache.jsonmodified+811−0View file
tools/perf/pmu-events/arch/x86/meteorlake/floating-point.jsonadded+143−0View file
tools/perf/pmu-events/arch/x86/meteorlake/frontend.jsonmodified+410−0View file
tools/perf/pmu-events/arch/x86/meteorlake/memory.jsonmodified+112−30View file
tools/perf/pmu-events/arch/x86/meteorlake/other.jsonmodified+33−24View file
tools/perf/pmu-events/arch/x86/meteorlake/pipeline.jsonmodified+1163−48View file
tools/perf/pmu-events/arch/x86/meteorlake/uncore-cache.jsonadded+18−0View file
tools/perf/pmu-events/arch/x86/meteorlake/uncore-interconnect.jsonadded+42−0View file
tools/perf/pmu-events/arch/x86/meteorlake/uncore-memory.jsonadded+126−0View file
tools/perf/pmu-events/arch/x86/meteorlake/virtual-memory.jsonmodified+257−0View file
tools/perf/pmu-events/arch/x86/rocketlake/cache.jsonadded+894−0View file
tools/perf/pmu-events/arch/x86/rocketlake/floating-point.jsonadded+105−0View file
tools/perf/pmu-events/arch/x86/rocketlake/frontend.jsonadded+377−0View file
tools/perf/pmu-events/arch/x86/rocketlake/memory.jsonadded+394−0View file
tools/perf/pmu-events/arch/x86/rocketlake/metricgroups.jsonadded+113−0View file
tools/perf/pmu-events/arch/x86/rocketlake/other.jsonadded+242−0View file
tools/perf/pmu-events/arch/x86/rocketlake/pipeline.jsonadded+801−0View file
tools/perf/pmu-events/arch/x86/rocketlake/rkl-metrics.jsonadded+1571−0View file
tools/perf/pmu-events/arch/x86/rocketlake/uncore-interconnect.jsonadded+74−0View file
tools/perf/pmu-events/arch/x86/rocketlake/uncore-other.jsonadded+9−0View file
tools/perf/pmu-events/arch/x86/rocketlake/virtual-memory.jsonadded+165−0View file
tools/perf/pmu-events/arch/x86/sapphirerapids/pipeline.jsonmodified+1−1View file
tools/perf/pmu-events/arch/x86/sapphirerapids/spr-metrics.jsonmodified+4−4View file
tools/perf/pmu-events/arch/x86/sapphirerapids/uncore-cache.jsonmodified+308−0View file
tools/perf/pmu-events/arch/x86/sapphirerapids/uncore-interconnect.jsonmodified+1−1View file
tools/perf/pmu-events/arch/x86/skylake/frontend.jsonmodified+38−5View file
tools/perf/pmu-events/arch/x86/skylake/pipeline.jsonmodified+13−4View file
tools/perf/pmu-events/arch/x86/skylake/skl-metrics.jsonmodified+4−4View file
tools/perf/pmu-events/arch/x86/skylakex/frontend.jsonmodified+38−5View file
tools/perf/pmu-events/arch/x86/skylakex/pipeline.jsonmodified+13−4View file
tools/perf/pmu-events/arch/x86/skylakex/skx-metrics.jsonmodified+4−4View file
tools/perf/pmu-events/arch/x86/skylakex/uncore-interconnect.jsonmodified+1−1View file
tools/perf/pmu-events/arch/x86/skylakex/uncore-memory.jsonmodified+1−1View file
tools/perf/pmu-events/arch/x86/tigerlake/frontend.jsonmodified+28−4View file
tools/perf/pmu-events/arch/x86/tigerlake/pipeline.jsonmodified+3−3View file
tools/perf/pmu-events/arch/x86/tigerlake/tgl-metrics.jsonmodified+4−4View file
tools/perf/pmu-events/metric.pymodified+7−1View file
tools/perf/tests/builtin-test.cmodified+0−1View file
tools/perf/tests/expr.cmodified+4−0View file
tools/perf/tests/makemodified+4−0View file
tools/perf/tests/parse-events.cmodified+63−37View file
tools/perf/tests/pe-file-parsing.cmodified+2−1View file
tools/perf/tests/shell/lock_contention.shmodified+36−0View file
tools/perf/util/bpf_skel/.gitignoremodified+1−0View file
tools/perf/util/bpf_skel/lock_contention.bpf.cmodified+0−2View file
tools/perf/util/bpf_skel/vmlinux.h → tools/perf/util/bpf_skel/vmlinux/vmlinux.hrenamed+10−0View file
tools/perf/util/dso.cmodified+5−2View file
tools/perf/util/dso.hmodified+2−1View file
tools/perf/util/event.cmodified+2−5View file
tools/perf/util/evsel.cmodified+9−21View file
tools/perf/util/evsel.hmodified+1−0View file
tools/perf/util/expr.cmodified+21−0View file
tools/perf/util/expr.hmodified+1−0View file
tools/perf/util/expr.lmodified+1−0View file
tools/perf/util/expr.ymodified+7−1View file
tools/perf/util/llvm-utils.cmodified+2−2View file
tools/perf/util/map.cmodified+10−4View file
tools/perf/util/map.hmodified+7−5View file
tools/perf/util/perf_event_attr_fprintf.cmodified+177−9View file
tools/perf/util/pmu.cmodified+26−1View file
tools/perf/util/pmu.hmodified+1−0View file
tools/perf/util/pmus.cmodified+6−1View file
tools/perf/util/probe-event.cmodified+7−9View file
tools/perf/util/python.cmodified+8−0View file
tools/perf/util/symbol.cmodified+72−64View file
tools/perf/util/symbol.hmodified+3−9View file
tools/perf/util/symbol_conf.hmodified+0−1View file
tools/perf/util/symbol_fprintf.cmodified+4−6View file
tools/perf/util/trace-event-info.cmodified+12−0View file
tools/perf/util/trace-event.hmodified+6−0View file
tools/perf/util/unwind-libdw.cmodified+6−2View file

Only the first 600 diff lines are shown. Download the complete patch.

tools/perf/Documentation/perf-config.txt

View file
diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index e56ae54..1478068 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -669,7 +669,7 @@ llvm.*::
"$CLANG_OPTIONS $PERF_BPF_INC_OPTIONS $KERNEL_INC_OPTIONS " \
"-Wno-unused-value -Wno-pointer-sign " \
"-working-directory $WORKING_DIR " \
- "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE"
+ "-c \"$CLANG_SOURCE\" --target=bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE"
llvm.clang-opt::
Options passed to clang.

tools/perf/Documentation/perf-lock.txt

View file
diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentation/perf-lock.txt
index 6e5ba3c..30eea57 100644
--- a/tools/perf/Documentation/perf-lock.txt
+++ b/tools/perf/Documentation/perf-lock.txt
@@ -36,6 +36,9 @@ COMMON OPTIONS
--input=<file>::
Input file name. (default: perf.data unless stdin is a fifo)
+--output=<file>::
+ Output file name for perf lock contention and report.
+
-v::
--verbose::
Be more verbose (show symbol address, etc).
@@ -200,6 +203,11 @@ CONTENTION OPTIONS
Note that it matches the substring so 'rq' would match both 'raw_spin_rq_lock'
and 'irq_enter_rcu'.
+-x::
+--field-separator=<SEP>::
+ Show results using a CSV-style output to make it easy to import directly
+ into spreadsheets. Columns are separated by the string specified in SEP.
+
SEE ALSO
--------

tools/perf/Makefile.config

View file
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 9c5aa14..0609c19 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -315,6 +315,9 @@ FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
FEATURE_CHECK_LDFLAGS-libaio = -lrt
+FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
+FEATURE_CHECK_LDFLAGS-disassembler-init-styled = -lbfd -lopcodes -ldl
+
CORE_CFLAGS += -fno-omit-frame-pointer
CORE_CFLAGS += -ggdb3
CORE_CFLAGS += -funwind-tables
@@ -344,8 +347,8 @@ ifneq ($(TCMALLOC),)
endif
ifeq ($(FEATURES_DUMP),)
-# We will display at the end of this Makefile.config, using $(call feature_display_entries),
-# as we may retry some feature detection here.
+# We will display at the end of this Makefile.config, using $(call feature_display_entries)
+# As we may retry some feature detection here, see the disassembler-four-args case, for instance
FEATURE_DISPLAY_DEFERRED := 1
include $(srctree)/tools/build/Makefile.feature
else
@@ -680,6 +683,10 @@ ifdef BUILD_BPF_SKEL
CFLAGS += -DHAVE_BPF_SKEL
endif
+ifndef GEN_VMLINUX_H
+ VMLINUX_H=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h
+endif
+
dwarf-post-unwind := 1
dwarf-post-unwind-text := BUG
@@ -903,9 +910,13 @@ ifdef BUILD_NONDISTRO
ifeq ($(feature-libbfd-liberty), 1)
EXTLIBS += -lbfd -lopcodes -liberty
+ FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
+ FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -ldl
else
ifeq ($(feature-libbfd-liberty-z), 1)
EXTLIBS += -lbfd -lopcodes -liberty -lz
+ FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
+ FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -lz -ldl
endif
endif
$(call feature_check,disassembler-four-args)
@@ -1329,6 +1340,6 @@ endif
# re-generate FEATURE-DUMP as we may have called feature_check, found out
# extra libraries to add to LDFLAGS of some other test and then redo those
-# tests.
+# tests, see the block about libbfd, disassembler-four-args, for instance.
$(shell rm -f $(FEATURE_DUMP_FILENAME))
$(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))

tools/perf/Makefile.perf

View file
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index b1e62a6..097316e 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -132,6 +132,8 @@ include ../scripts/utilities.mak
# Define EXTRA_TESTS to enable building extra tests useful mainly to perf
# developers, such as:
# x86 instruction decoder - new instructions test
+#
+# Define GEN_VMLINUX_H to generate vmlinux.h from the BTF.
# As per kernel Makefile, avoid funny character set dependencies
unexport LC_ALL
@@ -197,6 +199,7 @@ FLEX ?= flex
BISON ?= bison
STRIP = strip
AWK = awk
+READELF ?= readelf
# include Makefile.config by default and rule out
# non-config cases
@@ -1061,7 +1064,7 @@ $(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_
ifdef BUILD_BPF_SKEL
BPFTOOL := $(SKEL_TMP_OUT)/bootstrap/bpftool
# Get Clang's default includes on this system, as opposed to those seen by
-# '-target bpf'. This fixes "missing" files on some architectures/distros,
+# '--target=bpf'. This fixes "missing" files on some architectures/distros,
# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
#
# Use '-idirafter': Don't interfere with include mechanics except where the
@@ -1084,8 +1087,44 @@ $(BPFTOOL): | $(SKEL_TMP_OUT)
$(Q)CFLAGS= $(MAKE) -C ../bpf/bpftool \
OUTPUT=$(SKEL_TMP_OUT)/ bootstrap
-$(SKEL_TMP_OUT)/%.bpf.o: util/bpf_skel/%.bpf.c $(LIBBPF) | $(SKEL_TMP_OUT)
- $(QUIET_CLANG)$(CLANG) -g -O2 -target bpf -Wall -Werror $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \
+# Paths to search for a kernel to generate vmlinux.h from.
+VMLINUX_BTF_ELF_PATHS ?= $(if $(O),$(O)/vmlinux) \
+ $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
+ ../../vmlinux \
+ /boot/vmlinux-$(shell uname -r)
+
+# Paths to BTF information.
+VMLINUX_BTF_BTF_PATHS ?= /sys/kernel/btf/vmlinux
+
+# Filter out kernels that don't exist or without a BTF section.
+VMLINUX_BTF_ELF_ABSPATHS ?= $(abspath $(wildcard $(VMLINUX_BTF_ELF_PATHS)))
+VMLINUX_BTF_PATHS ?= $(shell for file in $(VMLINUX_BTF_ELF_ABSPATHS); \
+ do \
+ if [ -f $$file ] && ($(READELF) -S "$$file" | grep -q .BTF); \
+ then \
+ echo "$$file"; \
+ fi; \
+ done) \
+ $(wildcard $(VMLINUX_BTF_BTF_PATHS))
+
+# Select the first as the source of vmlinux.h.
+VMLINUX_BTF ?= $(firstword $(VMLINUX_BTF_PATHS))
+
+ifeq ($(VMLINUX_H),)
+ ifeq ($(VMLINUX_BTF),)
+ $(error Missing bpftool input for generating vmlinux.h)
+ endif
+endif
+
+$(SKEL_OUT)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL)
+ifeq ($(VMLINUX_H),)
+ $(QUIET_GEN)$(BPFTOOL) btf dump file $< format c > $@
+else
+ $(Q)cp "$(VMLINUX_H)" $@
+endif
+
+$(SKEL_TMP_OUT)/%.bpf.o: util/bpf_skel/%.bpf.c $(LIBBPF) $(SKEL_OUT)/vmlinux.h | $(SKEL_TMP_OUT)
+ $(QUIET_CLANG)$(CLANG) -g -O2 --target=bpf -Wall -Werror $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \
-c $(filter util/bpf_skel/%.bpf.c,$^) -o $@
$(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o | $(BPFTOOL)

tools/perf/arch/x86/util/evsel.c

View file
diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.c
index 512c2d8..81d2265 100644
--- a/tools/perf/arch/x86/util/evsel.c
+++ b/tools/perf/arch/x86/util/evsel.c
@@ -102,3 +102,23 @@ void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr)
}
}
}
+
+int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size)
+{
+ if (!x86__is_amd_cpu())
+ return 0;
+
+ if (!evsel->core.attr.precise_ip &&
+ !(evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3)))
+ return 0;
+
+ /* More verbose IBS errors. */
+ if (evsel->core.attr.exclude_kernel || evsel->core.attr.exclude_user ||
+ evsel->core.attr.exclude_hv || evsel->core.attr.exclude_idle ||
+ evsel->core.attr.exclude_host || evsel->core.attr.exclude_guest) {
+ return scnprintf(msg, size, "AMD IBS doesn't support privilege filtering. Try "
+ "again without the privilege modifiers (like 'k') at the end.");
+ }
+
+ return 0;
+}

tools/perf/builtin-daemon.c

View file
diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
index f5674d8..83954af 100644
--- a/tools/perf/builtin-daemon.c
+++ b/tools/perf/builtin-daemon.c
@@ -1524,7 +1524,7 @@ int cmd_daemon(int argc, const char **argv)
if (argc) {
if (!strcmp(argv[0], "start"))
ret = __cmd_start(&__daemon, daemon_options, argc, argv);
- if (!strcmp(argv[0], "signal"))
+ else if (!strcmp(argv[0], "signal"))
ret = __cmd_signal(&__daemon, daemon_options, argc, argv);
else if (!strcmp(argv[0], "stop"))
ret = __cmd_stop(&__daemon, daemon_options, argc, argv);

tools/perf/builtin-kallsyms.c

View file
diff --git a/tools/perf/builtin-kallsyms.c b/tools/perf/builtin-kallsyms.c
index 3751df7..7f75c5b 100644
--- a/tools/perf/builtin-kallsyms.c
+++ b/tools/perf/builtin-kallsyms.c
@@ -62,7 +62,6 @@ int cmd_kallsyms(int argc, const char **argv)
if (argc < 1)
usage_with_options(kallsyms_usage, options);
- symbol_conf.sort_by_name = true;
symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
if (symbol__init(NULL) < 0)
return -1;

tools/perf/builtin-lock.c

View file
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 8b505e1..c15386c 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -27,6 +27,7 @@
#include "util/map.h"
#include "util/util.h"
+#include <stdio.h>
#include <sys/types.h>
#include <sys/prctl.h>
#include <semaphore.h>
@@ -65,6 +66,8 @@ static int max_stack_depth = CONTENTION_STACK_DEPTH;
static int stack_skip = CONTENTION_STACK_SKIP;
static int print_nr_entries = INT_MAX / 2;
static LIST_HEAD(callstack_filters);
+static const char *output_name = NULL;
+static FILE *lock_output;
struct callstack_filter {
struct list_head list;
@@ -225,22 +228,28 @@ static void lock_stat_key_print_time(unsigned long long nsec, int len)
{ 0, NULL },
};
+ /* for CSV output */
+ if (len == 0) {
+ fprintf(lock_output, "%llu", nsec);
+ return;
+ }
+
for (int i = 0; table[i].unit; i++) {
if (nsec < table[i].base)
continue;
- pr_info("%*.2f %s", len - 3, nsec / table[i].base, table[i].unit);
+ fprintf(lock_output, "%*.2f %s", len - 3, nsec / table[i].base, table[i].unit);
return;
}
- pr_info("%*llu %s", len - 3, nsec, "ns");
+ fprintf(lock_output, "%*llu %s", len - 3, nsec, "ns");
}
#define PRINT_KEY(member) \
static void lock_stat_key_print_ ## member(struct lock_key *key, \
struct lock_stat *ls) \
{ \
- pr_info("%*llu", key->len, (unsigned long long)ls->member); \
+ fprintf(lock_output, "%*llu", key->len, (unsigned long long)ls->member);\
}
#define PRINT_TIME(member) \
@@ -1329,12 +1338,12 @@ static void print_bad_events(int bad, int total)
if (quiet || total == 0 || (broken == 0 && verbose <= 0))
return;
- pr_info("\n=== output for debug ===\n\n");
- pr_info("bad: %d, total: %d\n", bad, total);
- pr_info("bad rate: %.2f %%\n", (double)bad / (double)total * 100);
- pr_info("histogram of events caused bad sequence\n");
+ fprintf(lock_output, "\n=== output for debug ===\n\n");
+ fprintf(lock_output, "bad: %d, total: %d\n", bad, total);
+ fprintf(lock_output, "bad rate: %.2f %%\n", (double)bad / (double)total * 100);
+ fprintf(lock_output, "histogram of events caused bad sequence\n");
for (i = 0; i < BROKEN_MAX; i++)
- pr_info(" %10s: %d\n", name[i], bad_hist[i]);
+ fprintf(lock_output, " %10s: %d\n", name[i], bad_hist[i]);
}
/* TODO: various way to print, coloring, nano or milli sec */
@@ -1346,10 +1355,10 @@ static void print_result(void)
int bad, total, printed;
if (!quiet) {
- pr_info("%20s ", "Name");
+ fprintf(lock_output, "%20s ", "Name");
list_for_each_entry(key, &lock_keys, list)
- pr_info("%*s ", key->len, key->header);
- pr_info("\n\n");
+ fprintf(lock_output, "%*s ", key->len, key->header);
+ fprintf(lock_output, "\n\n");
}
bad = total = printed = 0;
@@ -1374,7 +1383,7 @@ static void print_result(void)
name = thread__comm_str(t);
}
- pr_info("%20s ", name);
+ fprintf(lock_output, "%20s ", name);
} else {
strncpy(cut_name, st->name, 16);
cut_name[16] = '.';
@@ -1382,14 +1391,14 @@ static void print_result(void)
cut_name[18] = '.';
cut_name[19] = '\0';
/* cut off name for saving output style */
- pr_info("%20s ", cut_name);
+ fprintf(lock_output, "%20s ", cut_name);
}
list_for_each_entry(key, &lock_keys, list) {
key->print(key, st);
- pr_info(" ");
+ fprintf(lock_output, " ");
}
- pr_info("\n");
+ fprintf(lock_output, "\n");
if (++printed >= print_nr_entries)
break;
@@ -1406,13 +1415,13 @@ static void dump_threads(void)
struct rb_node *node;
struct thread *t;
- pr_info("%10s: comm\n", "Thread ID");
+ fprintf(lock_output, "%10s: comm\n", "Thread ID");
node = rb_first(&thread_stats);
while (node) {
st = container_of(node, struct thread_stat, rb);
t = perf_session__findnew(session, st->tid);
- pr_info("%10d: %s\n", st->tid, thread__comm_str(t));
+ fprintf(lock_output, "%10d: %s\n", st->tid, thread__comm_str(t));
node = rb_next(node);
thread__put(t);
}
@@ -1438,7 +1447,7 @@ static void dump_map(void)
unsigned int i;
struct lock_stat *st;
- pr_info("Address of instance: name of class\n");
+ fprintf(lock_output, "Address of instance: name of class\n");
for (i = 0; i < LOCKHASH_SIZE; i++) {
hlist_for_each_entry(st, &lockhash_table[i], hash_entry) {
insert_to_result(st, compare_maps);
@@ -1446,7 +1455,7 @@ static void dump_map(void)
}
while ((st = pop_from_result()))
- pr_info(" %#llx: %s\n", (unsigned long long)st->addr, st->name);
+ fprintf(lock_output, " %#llx: %s\n", (unsigned long long)st->addr, st->name);
}
static int dump_info(void)
@@ -1626,58 +1635,242 @@ static void sort_contention_result(void)
sort_result();
}
-static void print_bpf_events(int total, struct lock_contention_fails *fails)
+static void print_header_stdio(void)
+{
+ struct lock_key *key;
+
+ list_for_each_entry(key, &lock_keys, list)
+ fprintf(lock_output, "%*s ", key->len, key->header);
+
+ switch (aggr_mode) {
+ case LOCK_AGGR_TASK:
+ fprintf(lock_output, " %10s %s\n\n", "pid",
+ show_lock_owner ? "owner" : "comm");
+ break;
+ case LOCK_AGGR_CALLER:
+ fprintf(lock_output, " %10s %s\n\n", "type", "caller");
+ break;
+ case LOCK_AGGR_ADDR:
+ fprintf(lock_output, " %16s %s\n\n", "address", "symbol");
+ break;
+ default:
+ break;
+ }
+}
+
+static void print_header_csv(const char *sep)
+{
+ struct lock_key *key;
+
+ fprintf(lock_output, "# output: ");
+ list_for_each_entry(key, &lock_keys, list)
+ fprintf(lock_output, "%s%s ", key->header, sep);
+
+ switch (aggr_mode) {
+ case LOCK_AGGR_TASK:
+ fprintf(lock_output, "%s%s %s\n", "pid", sep,
+ show_lock_owner ? "owner" : "comm");
+ break;
+ case LOCK_AGGR_CALLER:
+ fprintf(lock_output, "%s%s %s", "type", sep, "caller");
+ if (verbose > 0)
+ fprintf(lock_output, "%s %s", sep, "stacktrace");
+ fprintf(lock_output, "\n");
+ break;
+ case LOCK_AGGR_ADDR:
+ fprintf(lock_output, "%s%s %s%s %s\n", "address", sep, "symbol", sep, "type");
+ break;
+ default:
+ break;
+ }
+}
+
+static void print_header(void)
+{
+ if (!quiet) {
+ if (symbol_conf.field_sep)
+ print_header_csv(symbol_conf.field_sep);
+ else
+ print_header_stdio();
+ }
+}
+
+static void print_lock_stat_stdio(struct lock_contention *con, struct lock_stat *st)
+{
+ struct lock_key *key;
+ struct thread *t;
+ int pid;
+
+ list_for_each_entry(key, &lock_keys, list) {
+ key->print(key, st);
+ fprintf(lock_output, " ");
+ }
+
+ switch (aggr_mode) {
+ case LOCK_AGGR_CALLER:
+ fprintf(lock_output, " %10s %s\n", get_type_str(st->flags), st->name);
+ break;
+ case LOCK_AGGR_TASK:
+ pid = st->addr;
+ t = perf_session__findnew(session, pid);
+ fprintf(lock_output, " %10d %s\n",
+ pid, pid == -1 ? "Unknown" : thread__comm_str(t));
+ break;
+ case LOCK_AGGR_ADDR:
+ fprintf(lock_output, " %016llx %s (%s)\n", (unsigned long long)st->addr,
+ st->name, get_type_name(st->flags));
+ break;
+ default:
+ break;
+ }
+
+ if (aggr_mode == LOCK_AGGR_CALLER && verbose > 0) {
+ struct map *kmap;
+ struct symbol *sym;
+ char buf[128];
+ u64 ip;
+
+ for (int i = 0; i < max_stack_depth; i++) {
+ if (!st->callstack || !st->callstack[i])
+ break;
+
+ ip = st->callstack[i];
+ sym = machine__find_kernel_symbol(con->machine, ip, &kmap);
+ get_symbol_name_offset(kmap, sym, ip, buf, sizeof(buf));
+ fprintf(lock_output, "\t\t\t%#lx %s\n", (unsigned long)ip, buf);
+ }
+ }
+}
+
+static void print_lock_stat_csv(struct lock_contention *con, struct lock_stat *st,
+ const char *sep)
+{
+ struct lock_key *key;
+ struct thread *t;
+ int pid;
+
+ list_for_each_entry(key, &lock_keys, list) {
+ key->print(key, st);
+ fprintf(lock_output, "%s ", sep);
+ }
+
+ switch (aggr_mode) {
+ case LOCK_AGGR_CALLER:
+ fprintf(lock_output, "%s%s %s", get_type_str(st->flags), sep, st->name);
+ if (verbose <= 0)
+ fprintf(lock_output, "\n");
+ break;
+ case LOCK_AGGR_TASK:
+ pid = st->addr;
+ t = perf_session__findnew(session, pid);
+ fprintf(lock_output, "%d%s %s\n", pid, sep,
+ pid == -1 ? "Unknown" : thread__comm_str(t));
+ break;
+ case LOCK_AGGR_ADDR:
+ fprintf(lock_output, "%llx%s %s%s %s\n", (unsigned long long)st->addr, sep,
+ st->name, sep, get_type_name(st->flags));
+ break;
+ default:
+ break;
+ }
+
+ if (aggr_mode == LOCK_AGGR_CALLER && verbose > 0) {
+ struct map *kmap;
+ struct symbol *sym;
+ char buf[128];
+ u64 ip;
+
+ for (int i = 0; i < max_stack_depth; i++) {
+ if (!st->callstack || !st->callstack[i])
+ break;
+
+ ip = st->callstack[i];
+ sym = machine__find_kernel_symbol(con->machine, ip, &kmap);
+ get_symbol_name_offset(kmap, sym, ip, buf, sizeof(buf));
+ fprintf(lock_output, "%s %#lx %s", i ? ":" : sep, (unsigned long) ip, buf);
+ }
+ fprintf(lock_output, "\n");
+ }
+}
+
+static void print_lock_stat(struct lock_contention *con, struct lock_stat *st)
+{
+ if (symbol_conf.field_sep)
+ print_lock_stat_csv(con, st, symbol_conf.field_sep);
+ else
+ print_lock_stat_stdio(con, st);
+}
+
+static void print_footer_stdio(int total, int bad, struct lock_contention_fails *fails)
{
/* Output for debug, this have to be removed */
int broken = fails->task + fails->stack + fails->time + fails->data;
+ if (!use_bpf)
+ print_bad_events(bad, total);
+
if (quiet || total == 0 || (broken == 0 && verbose <= 0))
return;
total += broken;
- pr_info("\n=== output for debug ===\n\n");
- pr_info("bad: %d, total: %d\n", broken, total);
- pr_info("bad rate: %.2f %%\n", (double)broken / (double)total * 100);
+ fprintf(lock_output, "\n=== output for debug ===\n\n");
+ fprintf(lock_output, "bad: %d, total: %d\n", broken, total);
+ fprintf(lock_output, "bad rate: %.2f %%\n", 100.0 * broken / total);
- pr_info("histogram of failure reasons\n");
- pr_info(" %10s: %d\n", "task", fails->task);
- pr_info(" %10s: %d\n", "stack", fails->stack);
- pr_info(" %10s: %d\n", "time", fails->time);
- pr_info(" %10s: %d\n", "data", fails->data);
+ fprintf(lock_output, "histogram of failure reasons\n");
+ fprintf(lock_output, " %10s: %d\n", "task", fails->task);
+ fprintf(lock_output, " %10s: %d\n", "stack", fails->stack);
+ fprintf(lock_output, " %10s: %d\n", "time", fails->time);
+ fprintf(lock_output, " %10s: %d\n", "data", fails->data);
+}
+
+static void print_footer_csv(int total, int bad, struct lock_contention_fails *fails,
+ const char *sep)
+{
+ /* Output for debug, this have to be removed */
+ if (use_bpf)
+ bad = fails->task + fails->stack + fails->time + fails->data;
+
+ if (quiet || total == 0 || (bad == 0 && verbose <= 0))
+ return;
+
+ total += bad;
+ fprintf(lock_output, "# debug: total=%d%s bad=%d", total, sep, bad);
+
+ if (use_bpf) {
+ fprintf(lock_output, "%s bad_%s=%d", sep, "task", fails->task);
+ fprintf(lock_output, "%s bad_%s=%d", sep, "stack", fails->stack);
+ fprintf(lock_output, "%s bad_%s=%d", sep, "time", fails->time);
+ fprintf(lock_output, "%s bad_%s=%d", sep, "data", fails->data);
+ } else {
+ int i;
+ const char *name[4] = { "acquire", "acquired", "contended", "release" };
+
+ for (i = 0; i < BROKEN_MAX; i++)
+ fprintf(lock_output, "%s bad_%s=%d", sep, name[i], bad_hist[i]);
+ }

This diff is incomplete. Download the complete patch.

tools/perf/builtin-report.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/alderlake/adl-metrics.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/cascadelakex/clx-metrics.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/cascadelakex/frontend.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/cascadelakex/pipeline.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/cascadelakex/uncore-interconnect.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/cascadelakex/uncore-memory.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/icelake/cache.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/icelake/frontend.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/icelake/icl-metrics.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/icelake/pipeline.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/icelakex/frontend.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/icelakex/icx-metrics.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/icelakex/pipeline.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/icelakex/uncore-interconnect.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/mapfile.csv

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/meteorlake/cache.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/meteorlake/floating-point.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/meteorlake/frontend.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/meteorlake/memory.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/meteorlake/other.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/meteorlake/pipeline.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/meteorlake/uncore-cache.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/meteorlake/uncore-interconnect.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/meteorlake/uncore-memory.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/meteorlake/virtual-memory.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/rocketlake/cache.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/rocketlake/floating-point.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/rocketlake/frontend.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/rocketlake/memory.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/rocketlake/metricgroups.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/rocketlake/other.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/rocketlake/pipeline.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/rocketlake/rkl-metrics.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/rocketlake/uncore-interconnect.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/rocketlake/uncore-other.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/rocketlake/virtual-memory.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/sapphirerapids/pipeline.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/sapphirerapids/spr-metrics.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/sapphirerapids/uncore-cache.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/sapphirerapids/uncore-interconnect.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/skylake/frontend.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/skylake/pipeline.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/skylake/skl-metrics.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/skylakex/frontend.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/skylakex/pipeline.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/skylakex/skx-metrics.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/skylakex/uncore-interconnect.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/skylakex/uncore-memory.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/tigerlake/frontend.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/tigerlake/pipeline.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/arch/x86/tigerlake/tgl-metrics.json

View file

This diff is incomplete. Download the complete patch.

tools/perf/pmu-events/metric.py

View file

This diff is incomplete. Download the complete patch.

tools/perf/tests/builtin-test.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/tests/expr.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/tests/make

View file

This diff is incomplete. Download the complete patch.

tools/perf/tests/parse-events.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/tests/pe-file-parsing.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/tests/shell/lock_contention.sh

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/bpf_skel/.gitignore

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/bpf_skel/lock_contention.bpf.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/bpf_skel/vmlinux/vmlinux.h

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/dso.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/dso.h

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/event.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/evsel.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/evsel.h

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/expr.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/expr.h

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/expr.l

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/expr.y

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/llvm-utils.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/map.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/map.h

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/perf_event_attr_fprintf.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/pmu.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/pmu.h

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/pmus.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/probe-event.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/python.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/symbol.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/symbol.h

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/symbol_conf.h

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/symbol_fprintf.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/trace-event-info.c

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/trace-event.h

View file

This diff is incomplete. Download the complete patch.

tools/perf/util/unwind-libdw.c

View file

This diff is incomplete. Download the complete patch.