Skip to content

tools/dtrace: initial implementation of DTrace

Kris Van Hees bpf lkml netdev 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest0 of 1 patch 10 repliesIn review
  2. v11 patch 7 repliesSuperseded

Changes in v2 from the cover letter

- Use ring_buffer_read_head() and ring_buffer_write_tail() to avoid use of volatile.
- Handle perf events that wrap around the ring buffer boundary.
- Remove unnecessary PERF_EVENT_IOC_ENABLE.
- Remove -I$(srctree)/tools/perf from KBUILD_HOSTCFLAGS since it is not actually used.
- Use PT_REGS_PARM1(x), etc instead of my own macros. Adding PT_REGS_PARM6(x) in bpf_sample.c because we need to be able to support up to 6 arguments passed by registers.

Patches in v2 No applies recorded yet

The patch the cover letter announces is not in this archive.

Reviews trailers per patch

PatchDavid Mc LeanEugene Loh
SeriesR-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH V2 0/1] tools/dtrace: initial implementation of DTrace

This initial implementation of a tiny subset of DTrace functionality provides the following options:

dtrace [-lvV] [-b bufsz] -s script
-b set trace buffer size
-l list probes (only works with '-s script' for now) -s enable or list probes for the specified BPF program -V report DTrace API version

The patch comprises quite a bit of code due to DTrace requiring a few crucial components, even in its most basic form.

The code is structured around the command line interface implemented in dtrace.c. It provides option parsing and drives the three modes of operation that are currently implemented:

1. Report DTrace API version information. Report the version information and terminate.

2. List probes in BPF programs.
Initialize the list of probes that DTrace recognizes, load BPF programs, parse all BPF ELF section names, resolve them into known probes, and emit the probe names. Then terminate.

3. Load BPF programs and collect tracing data.
Initialize the list of probes that DTrace recognizes, load BPF programs and attach them to their corresponding probes, set up perf event output buffers, and start processing tracing data.

This implementation makes extensive use of BPF (handled by dt_bpf.c) and the perf event output ring buffer (handled by dt_buffer.c). DTrace-style probe handling (dt_probe.c) offers an interface to probes that hides the implementation details of the individual probe types by provider (dt_fbt.c and dt_syscall.c). Probe lookup by name uses a hashtable implementation (dt_hash.c). The dt_utils.c code populates a list of online CPU ids, so we know what CPUs we can obtain tracing data from.

Building the tool is trivial because its only dependency (libbpf) is in the kernel tree under tools/lib/bpf. A simple 'make' in the tools/dtrace directory suffices.

The 'dtrace' executable needs to run as root because BPF programs cannot be loaded by non-root users.

---
Changes in v2:
- Use ring_buffer_read_head() and ring_buffer_write_tail() to avoid use of volatile.
- Handle perf events that wrap around the ring buffer boundary.
- Remove unnecessary PERF_EVENT_IOC_ENABLE.
- Remove -I$(srctree)/tools/perf from KBUILD_HOSTCFLAGS since it is not actually used.
- Use PT_REGS_PARM1(x), etc instead of my own macros. Adding PT_REGS_PARM6(x) in bpf_sample.c because we need to be able to support up to 6 arguments passed by registers.

---
 MAINTAINERS                |   6 +
 tools/dtrace/Makefile      |  87 ++++++++++
 tools/dtrace/bpf_sample.c  | 146 ++++++++++++++++
 tools/dtrace/dt_bpf.c      | 185 ++++++++++++++++++++
 tools/dtrace/dt_buffer.c   | 338 +++++++++++++++++++++++++++++++++++++
 tools/dtrace/dt_fbt.c      | 201 ++++++++++++++++++++++
 tools/dtrace/dt_hash.c     | 211 +++++++++++++++++++++++
 tools/dtrace/dt_probe.c    | 230 +++++++++++++++++++++++++
 tools/dtrace/dt_syscall.c  | 179 ++++++++++++++++++++
 tools/dtrace/dt_utils.c    | 132 +++++++++++++++
 tools/dtrace/dtrace.c      | 249 +++++++++++++++++++++++++++
 tools/dtrace/dtrace.h      |  13 ++
 tools/dtrace/dtrace_impl.h | 101 +++++++++++
 13 files changed, 2078 insertions(+)
 create mode 100644 tools/dtrace/Makefile
 create mode 100644 tools/dtrace/bpf_sample.c
 create mode 100644 tools/dtrace/dt_bpf.c
 create mode 100644 tools/dtrace/dt_buffer.c
 create mode 100644 tools/dtrace/dt_fbt.c
 create mode 100644 tools/dtrace/dt_hash.c
 create mode 100644 tools/dtrace/dt_probe.c
 create mode 100644 tools/dtrace/dt_syscall.c
 create mode 100644 tools/dtrace/dt_utils.c
 create mode 100644 tools/dtrace/dtrace.c
 create mode 100644 tools/dtrace/dtrace.h
 create mode 100644 tools/dtrace/dtrace_impl.h
MAINTAINERS +6 -0
index cfa9ed89c031..410240732d55 100644
@@ -5485,6 +5485,12 @@ W:	https://linuxtv.org
 S:	Odd Fixes
 F:	drivers/media/pci/dt3155/
 
+DTRACE
+M:	Kris Van Hees <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	tools/dtrace/
+
 DVB_USB_AF9015 MEDIA DRIVER
 M:	Antti Palosaari <[email protected]>
 L:	[email protected]
tools/dtrace/Makefile new file +87 -0

87 lines not on this page · raw message

tools/dtrace/bpf_sample.c new file +146 -0

146 lines not on this page · raw message

tools/dtrace/dt_bpf.c new file +185 -0

185 lines not on this page · raw message

tools/dtrace/dt_buffer.c new file +338 -0

338 lines not on this page · raw message

tools/dtrace/dt_fbt.c new file +201 -0

201 lines not on this page · raw message

tools/dtrace/dt_hash.c new file +211 -0

211 lines not on this page · raw message

tools/dtrace/dt_probe.c new file +230 -0

230 lines not on this page · raw message

tools/dtrace/dt_syscall.c new file +179 -0

179 lines not on this page · raw message

tools/dtrace/dt_utils.c new file +132 -0

132 lines not on this page · raw message

tools/dtrace/dtrace.c new file +249 -0

249 lines not on this page · raw message

tools/dtrace/dtrace.h new file +13 -0
new file mode 100644
index 000000000000..c79398432d17
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ */
+#ifndef _UAPI_LINUX_DTRACE_H
+#define _UAPI_LINUX_DTRACE_H
+
+struct dt_bpf_context {
+	u32		probe_id;
+	u64		argv[10];
+};
+
+#endif /* _UAPI_LINUX_DTRACE_H */
tools/dtrace/dtrace_impl.h new file +101 -0

101 lines not on this page · raw message

Signature · 1 line
2.20.1