diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-10-31 10:32:23 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-10-31 15:17:04 -0400 |
commit | 1de3038d0082a1c2edd7a7b1b3381e38f42af0e7 (patch) | |
tree | cd1d73f2ec6acac59293b7c3b0fac7df464b07fc | |
parent | 0a2f7540abc08e32f89ff273506eeeeb6910794f (diff) |
perf trace beauty kcmp: Beautify arguments
For some unknown reason there is no entry in tracefs's syscalls for
kcmp, i.e. no tracefs/events/syscalls/sys_{enter,exit}_kcmp, so we need
to provide a data dictionary for the fields.
To beautify the 'type' argument we automatically generate a strarray
from tools/include/uapi/kcmp.h, the idx1 and idx2 args, nowadays used
only if type == KCMP_FILE, are masked for all the other types and a
lookup is made for the thread and fd to show the path, if possible,
getting it from the probe:vfs_getname if in place or from procfs, races
allowing.
A system wide strace like tracing session, with callchains shows just
one user so far in this fedora 25 machine:
# perf trace --max-stack 5 -e kcmp
<SNIP>
1502914.400 ( 0.001 ms): systemd/1 kcmp(pid1: 1 (systemd), pid2: 1 (systemd), type: FILE, idx1: 271<socket:[4723475]>, idx2: 25<socket:[4788686]>) = -1 ENOSYS Function not implemented
syscall (/usr/lib64/libc-2.25.so)
same_fd (/usr/lib/systemd/libsystemd-shared-233.so)
service_add_fd_store (/usr/lib/systemd/systemd)
service_notify_message.lto_priv.127 (/usr/lib/systemd/systemd)
1502914.407 ( 0.001 ms): systemd/1 kcmp(pid1: 1 (systemd), pid2: 1 (systemd), type: FILE, idx1: 270<socket:[4726396]>, idx2: 25<socket:[4788686]>) = -1 ENOSYS Function not implemented
syscall (/usr/lib64/libc-2.25.so)
same_fd (/usr/lib/systemd/libsystemd-shared-233.so)
service_add_fd_store (/usr/lib/systemd/systemd)
service_notify_message.lto_priv.127 (/usr/lib/systemd/systemd)
<SNIP>
The backtraces seem to agree this is really kcmp(), but this system
doesn't have the sys_kcmp(), bummer:
# uname -a
Linux jouet 4.14.0-rc3+ #1 SMP Fri Oct 13 12:21:12 -03 2017 x86_64 x86_64 x86_64 GNU/Linux
# grep kcmp /proc/kallsyms
ffffffffb60b8890 W sys_kcmp
$ grep CONFIG_CHECKPOINT_RESTORE ../build/v4.14.0-rc3+/.config
# CONFIG_CHECKPOINT_RESTORE is not set
$
So systemd uses it, good fedora kernel config has it:
$ grep CONFIG_CHECKPOINT_RESTORE /boot/config-4.13.4-200.fc26.x86_64
CONFIG_CHECKPOINT_RESTORE=y
[acme@jouet linux]$
/me goes to rebuild a kernel...
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andrey Vagin <avagin@openvz.org>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-gz5fca968viw8m7hryjqvrln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/Makefile.perf | 9 | ||||
-rw-r--r-- | tools/perf/builtin-trace.c | 6 | ||||
-rw-r--r-- | tools/perf/trace/beauty/Build | 1 | ||||
-rw-r--r-- | tools/perf/trace/beauty/beauty.h | 6 | ||||
-rw-r--r-- | tools/perf/trace/beauty/kcmp.c | 44 | ||||
-rwxr-xr-x | tools/perf/trace/beauty/kcmp_type.sh | 10 |
6 files changed, 76 insertions, 0 deletions
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index c872ca607b39..68cf1360a3f3 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf | |||
@@ -420,6 +420,13 @@ sndrv_pcm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/sndrv_pcm_ioctl.sh | |||
420 | $(sndrv_pcm_ioctl_array): $(sndrv_pcm_hdr_dir)/asound.h $(sndrv_pcm_ioctl_tbl) | 420 | $(sndrv_pcm_ioctl_array): $(sndrv_pcm_hdr_dir)/asound.h $(sndrv_pcm_ioctl_tbl) |
421 | $(Q)$(SHELL) '$(sndrv_pcm_ioctl_tbl)' $(sndrv_pcm_hdr_dir) > $@ | 421 | $(Q)$(SHELL) '$(sndrv_pcm_ioctl_tbl)' $(sndrv_pcm_hdr_dir) > $@ |
422 | 422 | ||
423 | kcmp_type_array := $(beauty_outdir)/kcmp_type_array.c | ||
424 | kcmp_hdr_dir := $(srctree)/tools/include/uapi/linux/ | ||
425 | kcmp_type_tbl := $(srctree)/tools/perf/trace/beauty/kcmp_type.sh | ||
426 | |||
427 | $(kcmp_type_array): $(kcmp_hdr_dir)/kcmp.h $(kcmp_type_tbl) | ||
428 | $(Q)$(SHELL) '$(kcmp_type_tbl)' $(kcmp_hdr_dir) > $@ | ||
429 | |||
423 | kvm_ioctl_array := $(beauty_ioctl_outdir)/kvm_ioctl_array.c | 430 | kvm_ioctl_array := $(beauty_ioctl_outdir)/kvm_ioctl_array.c |
424 | kvm_hdr_dir := $(srctree)/tools/include/uapi/linux | 431 | kvm_hdr_dir := $(srctree)/tools/include/uapi/linux |
425 | kvm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/kvm_ioctl.sh | 432 | kvm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/kvm_ioctl.sh |
@@ -553,6 +560,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders $(drm_ioc | |||
553 | $(pkey_alloc_access_rights_array) \ | 560 | $(pkey_alloc_access_rights_array) \ |
554 | $(sndrv_pcm_ioctl_array) \ | 561 | $(sndrv_pcm_ioctl_array) \ |
555 | $(sndrv_ctl_ioctl_array) \ | 562 | $(sndrv_ctl_ioctl_array) \ |
563 | $(kcmp_type_array) \ | ||
556 | $(kvm_ioctl_array) \ | 564 | $(kvm_ioctl_array) \ |
557 | $(vhost_virtio_ioctl_array) \ | 565 | $(vhost_virtio_ioctl_array) \ |
558 | $(madvise_behavior_array) \ | 566 | $(madvise_behavior_array) \ |
@@ -836,6 +844,7 @@ clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clea | |||
836 | $(OUTPUT)$(sndrv_ctl_ioctl_array) \ | 844 | $(OUTPUT)$(sndrv_ctl_ioctl_array) \ |
837 | $(OUTPUT)$(sndrv_pcm_ioctl_array) \ | 845 | $(OUTPUT)$(sndrv_pcm_ioctl_array) \ |
838 | $(OUTPUT)$(kvm_ioctl_array) \ | 846 | $(OUTPUT)$(kvm_ioctl_array) \ |
847 | $(OUTPUT)$(kcmp_type_array) \ | ||
839 | $(OUTPUT)$(vhost_virtio_ioctl_array) \ | 848 | $(OUTPUT)$(vhost_virtio_ioctl_array) \ |
840 | $(OUTPUT)$(perf_ioctl_array) \ | 849 | $(OUTPUT)$(perf_ioctl_array) \ |
841 | $(OUTPUT)$(prctl_option_array) | 850 | $(OUTPUT)$(prctl_option_array) |
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 0c1461416ef1..505b871fdc82 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -633,6 +633,12 @@ static struct syscall_fmt { | |||
633 | #else | 633 | #else |
634 | [2] = { .scnprintf = SCA_HEX, /* arg */ }, }, }, | 634 | [2] = { .scnprintf = SCA_HEX, /* arg */ }, }, }, |
635 | #endif | 635 | #endif |
636 | { .name = "kcmp", .nr_args = 5, | ||
637 | .arg = { [0] = { .name = "pid1", .scnprintf = SCA_PID, }, | ||
638 | [1] = { .name = "pid2", .scnprintf = SCA_PID, }, | ||
639 | [2] = { .name = "type", .scnprintf = SCA_KCMP_TYPE, }, | ||
640 | [3] = { .name = "idx1", .scnprintf = SCA_KCMP_IDX, }, | ||
641 | [4] = { .name = "idx2", .scnprintf = SCA_KCMP_IDX, }, }, }, | ||
636 | { .name = "keyctl", | 642 | { .name = "keyctl", |
637 | .arg = { [0] = STRARRAY(option, keyctl_options), }, }, | 643 | .arg = { [0] = STRARRAY(option, keyctl_options), }, }, |
638 | { .name = "kill", | 644 | { .name = "kill", |
diff --git a/tools/perf/trace/beauty/Build b/tools/perf/trace/beauty/Build index 2f68b76ec39b..066bbf0f4a74 100644 --- a/tools/perf/trace/beauty/Build +++ b/tools/perf/trace/beauty/Build | |||
@@ -3,6 +3,7 @@ libperf-y += fcntl.o | |||
3 | ifeq ($(SRCARCH),$(filter $(SRCARCH),x86)) | 3 | ifeq ($(SRCARCH),$(filter $(SRCARCH),x86)) |
4 | libperf-y += ioctl.o | 4 | libperf-y += ioctl.o |
5 | endif | 5 | endif |
6 | libperf-y += kcmp.o | ||
6 | libperf-y += pkey_alloc.o | 7 | libperf-y += pkey_alloc.o |
7 | libperf-y += prctl.o | 8 | libperf-y += prctl.o |
8 | libperf-y += statx.o | 9 | libperf-y += statx.o |
diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h index 365bb6fecc1c..3f067bdab84f 100644 --- a/tools/perf/trace/beauty/beauty.h +++ b/tools/perf/trace/beauty/beauty.h | |||
@@ -81,6 +81,12 @@ size_t syscall_arg__scnprintf_fcntl_arg(char *bf, size_t size, struct syscall_ar | |||
81 | size_t syscall_arg__scnprintf_ioctl_cmd(char *bf, size_t size, struct syscall_arg *arg); | 81 | size_t syscall_arg__scnprintf_ioctl_cmd(char *bf, size_t size, struct syscall_arg *arg); |
82 | #define SCA_IOCTL_CMD syscall_arg__scnprintf_ioctl_cmd | 82 | #define SCA_IOCTL_CMD syscall_arg__scnprintf_ioctl_cmd |
83 | 83 | ||
84 | size_t syscall_arg__scnprintf_kcmp_type(char *bf, size_t size, struct syscall_arg *arg); | ||
85 | #define SCA_KCMP_TYPE syscall_arg__scnprintf_kcmp_type | ||
86 | |||
87 | size_t syscall_arg__scnprintf_kcmp_idx(char *bf, size_t size, struct syscall_arg *arg); | ||
88 | #define SCA_KCMP_IDX syscall_arg__scnprintf_kcmp_idx | ||
89 | |||
84 | size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg); | 90 | size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg); |
85 | #define SCA_PKEY_ALLOC_ACCESS_RIGHTS syscall_arg__scnprintf_pkey_alloc_access_rights | 91 | #define SCA_PKEY_ALLOC_ACCESS_RIGHTS syscall_arg__scnprintf_pkey_alloc_access_rights |
86 | 92 | ||
diff --git a/tools/perf/trace/beauty/kcmp.c b/tools/perf/trace/beauty/kcmp.c new file mode 100644 index 000000000000..f62040eb9d5c --- /dev/null +++ b/tools/perf/trace/beauty/kcmp.c | |||
@@ -0,0 +1,44 @@ | |||
1 | /* | ||
2 | * trace/beauty/kcmp.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 <machine.h> | ||
13 | #include <uapi/linux/kcmp.h> | ||
14 | |||
15 | #include "trace/beauty/generated/kcmp_type_array.c" | ||
16 | |||
17 | size_t syscall_arg__scnprintf_kcmp_idx(char *bf, size_t size, struct syscall_arg *arg) | ||
18 | { | ||
19 | unsigned long fd = arg->val; | ||
20 | int type = syscall_arg__val(arg, 2); | ||
21 | pid_t pid; | ||
22 | |||
23 | if (type != KCMP_FILE) | ||
24 | return syscall_arg__scnprintf_long(bf, size, arg); | ||
25 | |||
26 | pid = syscall_arg__val(arg, arg->idx == 3 ? 0 : 1); /* idx1 -> pid1, idx2 -> pid2 */ | ||
27 | return pid__scnprintf_fd(arg->trace, pid, fd, bf, size); | ||
28 | } | ||
29 | |||
30 | static size_t kcmp__scnprintf_type(int type, char *bf, size_t size) | ||
31 | { | ||
32 | static DEFINE_STRARRAY(kcmp_types); | ||
33 | return strarray__scnprintf(&strarray__kcmp_types, bf, size, "%d", type); | ||
34 | } | ||
35 | |||
36 | size_t syscall_arg__scnprintf_kcmp_type(char *bf, size_t size, struct syscall_arg *arg) | ||
37 | { | ||
38 | unsigned long type = arg->val; | ||
39 | |||
40 | if (type != KCMP_FILE) | ||
41 | arg->mask |= (1 << 3) | (1 << 4); /* Ignore idx1 and idx2 */ | ||
42 | |||
43 | return kcmp__scnprintf_type(type, bf, size); | ||
44 | } | ||
diff --git a/tools/perf/trace/beauty/kcmp_type.sh b/tools/perf/trace/beauty/kcmp_type.sh new file mode 100755 index 000000000000..40d063b8c082 --- /dev/null +++ b/tools/perf/trace/beauty/kcmp_type.sh | |||
@@ -0,0 +1,10 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | header_dir=$1 | ||
4 | |||
5 | printf "static const char *kcmp_types[] = {\n" | ||
6 | regex='^[[:space:]]+(KCMP_(\w+)),' | ||
7 | egrep $regex ${header_dir}/kcmp.h | grep -v KCMP_TYPES, | \ | ||
8 | sed -r "s/$regex/\1 \2/g" | \ | ||
9 | xargs printf "\t[%s]\t= \"%s\",\n" | ||
10 | printf "};\n" | ||