Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf trace beauty ioctl: Beautify DRM ioctl cmds

This time we try a new approach, using uapi/drm/ copies of drm.h and
i915_drm.h we auto generate the string tables, then include it in the
ioctl cmd beautifier.

This way either the DRM developers will add the new commands to the
tools/ copy, like is happening with other areas of tools/include/ (bpf.h
comes to mind), or we'll be notified when building perf that our copy
drifted.

Either way the time from a new command being added to when 'perf trace'
gets to know it is greatly shortened, for instance:

# strace -p 22401 -e ioctl
ioctl(8, DRM_IOCTL_I915_GEM_BUSY, 0x7ffc934f7600) = 0
ioctl(8, DRM_IOCTL_I915_GEM_SET_DOMAIN, 0x7ffc934f7550) = 0
ioctl(8, DRM_IOCTL_I915_GEM_SW_FINISH, 0x7ffc934f76e0) = 0
ioctl(8, DRM_IOCTL_I915_GEM_SW_FINISH, 0x7ffc934f7780) = 0
ioctl(8, _IOC(_IOC_READ|_IOC_WRITE, 0x64, 0x69, 0x40), 0x7ffc934f7700) = 0
ioctl(8, DRM_IOCTL_I915_GEM_SET_DOMAIN, 0x7ffc934f7780) = 0
ioctl(8, DRM_IOCTL_I915_GEM_MADVISE, 0x7ffc934f76f0) = 0
ioctl(8, DRM_IOCTL_I915_GEM_BUSY, 0x7ffc934f76c0) = 0
ioctl(8, DRM_IOCTL_I915_GEM_MADVISE, 0x7ffc934f76b0) = 0
ioctl(8, DRM_IOCTL_I915_GEM_SET_DOMAIN, 0x7ffc934f76d0) = 0
ioctl(8, DRM_IOCTL_MODE_ADDFB, 0x7ffc934f7880) = 0
ioctl(8, DRM_IOCTL_MODE_PAGE_FLIP, 0x7ffc934f77d0) = 0
^Cstrace: Process 22401 detached

versus:

# perf trace -p 22401 -e ioctl
1010.856 (0.006 ms): gnome-shell/22401 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_BUSY, arg: 0x7ffc934f7600) = 0
1010.865 (0.003 ms): gnome-shell/22401 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_SET_DOMAIN, arg: 0x7ffc934f7550) = 0
1010.872 (0.002 ms): gnome-shell/22401 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_SW_FINISH, arg: 0x7ffc934f76e0) = 0
1010.939 (0.015 ms): gnome-shell/22401 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_SW_FINISH, arg: 0x7ffc934f7780) = 0
1010.959 (0.085 ms): gnome-shell/22401 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_EXECBUFFER2, arg: 0x7ffc934f7700) = 0
1011.048 (0.003 ms): gnome-shell/22401 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_SET_DOMAIN, arg: 0x7ffc934f7780) = 0
1011.056 (0.002 ms): gnome-shell/22401 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_MADVISE, arg: 0x7ffc934f76f0) = 0
1011.060 (0.002 ms): gnome-shell/22401 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_BUSY, arg: 0x7ffc934f76c0) = 0
1011.064 (0.003 ms): gnome-shell/22401 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_MADVISE, arg: 0x7ffc934f76b0) = 0
1011.068 (0.002 ms): gnome-shell/22401 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_SET_DOMAIN, arg: 0x7ffc934f76d0) = 0
1011.074 (0.009 ms): gnome-shell/22401 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_MODE_ADDFB, arg: 0x7ffc934f7880 ) = 0
1011.096 (0.072 ms): gnome-shell/22401 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_MODE_PAGE_FLIP, arg: 0x7ffc934f77d0) = 0
^C[root@jouet linux]#

Cc: Adrian Hunter <adrian.hunter@intel.com>
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-mly2d7v9kf28rso81dijbixq@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+40 -3
+14 -2
tools/perf/Makefile.perf
··· 381 381 382 382 SHELL = $(SHELL_PATH) 383 383 384 + drm_ioctl_outdir := $(OUTPUT)trace/beauty/generated/ioctl 385 + drm_ioctl_array := $(drm_ioctl_outdir)/drm_ioctl_array.c 386 + drm_hdr_dir := $(srctree)/tools/include/uapi/drm 387 + drm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/drm_ioctl.sh 388 + 389 + # Create output directory if not already present 390 + _dummy := $(shell [ -d '$(drm_ioctl_outdir)' ] || mkdir -p '$(drm_ioctl_outdir)') 391 + 392 + $(drm_ioctl_array): $(drm_hdr_dir)/drm.h $(drm_hdr_dir)/i915_drm.h $(drm_ioctl_tbl) 393 + $(Q)$(SHELL) '$(drm_ioctl_tbl)' $(drm_hdr_dir) > $@ 394 + 384 395 all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS) 385 396 386 397 $(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS) $(LIBTRACEEVENT_DYNAMIC_LIST) ··· 486 475 __build-dir = $(subst $(OUTPUT),,$(dir $@)) 487 476 build-dir = $(if $(__build-dir),$(__build-dir),.) 488 477 489 - prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders 478 + prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders $(drm_ioctl_array) 490 479 491 480 $(OUTPUT)%.o: %.c prepare FORCE 492 481 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@ ··· 751 740 $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \ 752 741 $(OUTPUT)util/intel-pt-decoder/inat-tables.c \ 753 742 $(OUTPUT)tests/llvm-src-{base,kbuild,prologue,relocation}.c \ 754 - $(OUTPUT)pmu-events/pmu-events.c 743 + $(OUTPUT)pmu-events/pmu-events.c \ 744 + $(OUTPUT)$(drm_ioctl_array) 755 745 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean 756 746 $(python-clean) 757 747
+13
tools/perf/trace/beauty/drm_ioctl.sh
··· 1 + #!/bin/sh 2 + 3 + drm_header_dir=$1 4 + printf "#ifndef DRM_COMMAND_BASE\n" 5 + grep "#define DRM_COMMAND_BASE" $drm_header_dir/drm.h 6 + printf "#endif\n" 7 + 8 + printf "static const char *drm_ioctl_cmds[] = {\n" 9 + grep "^#define DRM_IOCTL.*DRM_IO" $drm_header_dir/drm.h | \ 10 + sed -r 's/^#define +DRM_IOCTL_([A-Z0-9_]+)[ ]+DRM_IO[A-Z]* *\( *(0x[[:xdigit:]]+),*.*/ [\2] = "\1",/g' 11 + grep "^#define DRM_I915_[A-Z_0-9]\+[ ]\+0x" $drm_header_dir/i915_drm.h | \ 12 + sed -r 's/^#define +DRM_I915_([A-Z0-9_]+)[ ]+(0x[[:xdigit:]]+)/\t[DRM_COMMAND_BASE + \2] = "I915_\1",/g' 13 + printf "};\n"
+13 -1
tools/perf/trace/beauty/ioctl.c
··· 44 44 return scnprintf(bf, size, "(%#x, %#x)", 'T', nr); 45 45 } 46 46 47 + static size_t ioctl__scnprintf_drm_cmd(int nr, char *bf, size_t size) 48 + { 49 + #include "trace/beauty/generated/ioctl/drm_ioctl_array.c" 50 + static DEFINE_STRARRAY(drm_ioctl_cmds); 51 + 52 + if (nr < strarray__drm_ioctl_cmds.nr_entries && strarray__drm_ioctl_cmds.entries[nr] != NULL) 53 + return scnprintf(bf, size, "DRM_%s", strarray__drm_ioctl_cmds.entries[nr]); 54 + 55 + return scnprintf(bf, size, "(%#x, %#x)", 'd', nr); 56 + } 57 + 47 58 static size_t ioctl__scnprintf_cmd(unsigned long cmd, char *bf, size_t size) 48 59 { 49 60 int dir = _IOC_DIR(cmd), ··· 66 55 int type; 67 56 size_t (*scnprintf)(int nr, char *bf, size_t size); 68 57 } ioctl_types[] = { /* Must be ordered by type */ 69 - { .type = 'T', .scnprintf = ioctl__scnprintf_tty_cmd, } 58 + { .type = 'T', .scnprintf = ioctl__scnprintf_tty_cmd, }, 59 + ['d' - 'T'] = { .type = 'd', .scnprintf = ioctl__scnprintf_drm_cmd, } 70 60 }; 71 61 const int nr_types = ARRAY_SIZE(ioctl_types); 72 62