Skip to contentSkip to conversation

New trace backend: ftrace

PATCH Applied Eiichi Tsukata 2 participants 4 messages Apr 11, 2013 – Apr 12, 2013

lore
Share & tools
lore
#0 lore raw

v2 cover New trace backend: ftrace

This patchset introduces a new tracing backend "ftrace".

Currently, QEMU tracing backends do not support userspace tracing with ftrace. Collecting QEMU trace data and kernel trace data simultaneouly is useful for latency analysis and debugging especially when using KVM.

With ftrace backend, you can easily collect QEMU-kernel merged trace data using existing ftrace event-based tracer. If you use KVM, you can effectively compare VM_EXIT and QEMU userspace handler.

To try it out, compile QEMU with tracing backend ftrace, then enable KVM events in ftrace:

    # echo 1 > /sys/kernel/debug/tracing/events/kvm/enable

After running qemu by root user, you can get the trace:

    # cat /sys/kernel/debug/tracing/trace

Example:
# tracer: nop
#
# entries-in-buffer/entries-written: 8434/345512 #P:4
#
# _-----=> irqs-off
# / _----=> need-resched

 #                            | / _---=> hardirq/softirq
 #                            || / _--=> preempt-depth
 #                            ||| /     delay
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION
 #              | |       |   ||||       |         |

<snip>
qemu-system-x86-31930 [000] d... 23580.595951: kvm_exit: reason IO_INSTRUCTION rip 0xc45d info 710048 0 qemu-system-x86-31930 [000] .... 23580.595954: kvm_emulate_insn: f0000:c45d:e4 71 (real) qemu-system-x86-31930 [000] .... 23580.595955: kvm_pio: pio_read at 0x71 size 1 count 1 qemu-system-x86-31930 [000] .... 23580.595956: kvm_userspace_exit: reason KVM_EXIT_IO (2) qemu-system-x86-31930 [000] ...1 23580.595959: tracing_mark_write: cpu_set_apic_base 00000000fee00900 qemu-system-x86-31930 [000] ...1 23580.595961: tracing_mark_write: cpu_in addr 0x71 value 0 qemu-system-x86-31930 [000] d... 23580.595964: kvm_entry: vcpu 0
<snip>

"tracing_mark_write: cpu_set_apic_base 00000000fee00900" and "tracing_mark_write: cpu_in addr 0x71 value 0" are QEMU trace data. Others are Kernel trace data.

Furthermore, the ftrace backend overhead is smaller than uprobe-based event tracer or SystemTap. My microbenchmark shows that ftrace tracing backend overhead is about 0.8us per tracepoint, whereas uprobe-based event tracer or SystemTap overhead is about 2.0us.

Changes in v2:
* fix Stefan's mail address.
* use snprintf return value not to waste trace buffer.

Eiichi Tsukata (2):
trace: Add ftrace tracing backend
trace: document ftrace backend

 configure                           |   8 +++
 docs/tracing.txt                    |  16 ++++++
 scripts/tracetool/backend/ftrace.py |  54 +++++++++++++++++++
 trace/Makefile.objs                 |   1 +
 trace/ftrace.c                      | 102 ++++++++++++++++++++++++++++++++++++
 trace/ftrace.h                      |  10 ++++
 6 files changed, 191 insertions(+)
 create mode 100644 scripts/tracetool/backend/ftrace.py
 create mode 100644 trace/ftrace.c
 create mode 100644 trace/ftrace.h
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH v2 1/2 trace: Add ftrace tracing backend

This patch adds a ftrace tracing backend which sends trace event to ftrace marker file. You can effectively compare qemu trace data and kernel(especially, kvm.ko when using KVM) trace data. The ftrace backend is restricted to Linux only.

To try out the ftrace backend:

 $ ./configure --trace-backend=ftrace
 $ make

if you use KVM, enable kvm events in ftrace:

 # sudo echo 1 > /sys/kernel/debug/tracing/events/kvm/enable

After running qemu by root user, you can get the trace:

 # cat /sys/kernel/debug/tracing/trace
---
 configure                           |   8 +++
 scripts/tracetool/backend/ftrace.py |  54 +++++++++++++++++++
 trace/Makefile.objs                 |   1 +
 trace/ftrace.c                      | 102 ++++++++++++++++++++++++++++++++++++
 trace/ftrace.h                      |  10 ++++
 5 files changed, 175 insertions(+)
 create mode 100644 scripts/tracetool/backend/ftrace.py
 create mode 100644 trace/ftrace.c
 create mode 100644 trace/ftrace.h
configure +8 -0
index f2af714..6cbed00 100755
@@ -3848,6 +3848,14 @@ if test "$trace_backend" = "dtrace"; then
     echo "CONFIG_TRACE_SYSTEMTAP=y" >> $config_host_mak
   fi
 fi
+if test "$trace_backend" = "ftrace"; then
+  if test "$linux" = "yes" ; then
+    echo "CONFIG_TRACE_FTRACE=y" >> $config_host_mak
+    trace_default=no
+  else
+    feature_not_found "ftrace(trace backend)"
+  fi
+fi
 echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
 if test "$trace_default" = "yes"; then
   echo "CONFIG_TRACE_DEFAULT=y" >> $config_host_mak
scripts/tracetool/backend/ftrace.py new file +54 -0

54 lines not on this page · raw message

trace/Makefile.objs +1 -0
index a043072..3b88e49 100644
@@ -76,5 +76,6 @@ endif
 util-obj-$(CONFIG_TRACE_DEFAULT) += default.o
 util-obj-$(CONFIG_TRACE_SIMPLE) += simple.o
 util-obj-$(CONFIG_TRACE_STDERR) += stderr.o
+util-obj-$(CONFIG_TRACE_FTRACE) += ftrace.o
 util-obj-y += control.o
 util-obj-y += generated-tracers.o
trace/ftrace.c new file +102 -0

102 lines not on this page · raw message

trace/ftrace.h new file +10 -0
new file mode 100644
index 0000000..94cb8d5
@@ -0,0 +1,10 @@
+#ifndef TRACE_FTRACE_H
+#define TRACE_FTRACE_H
+
+#define MAX_TRACE_STRLEN 512
+#define _STR(x) #x
+#define STR(x) _STR(x)
+
+extern int trace_marker_fd;
+
+#endif /* ! TRACE_FTRACE_H */
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH v2 2/2 trace: document ftrace backend

In reply to Eiichi Tsukata

Add documentation of ftrace backend.

---
 docs/tracing.txt | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
docs/tracing.txt +16 -0
index cf53c17..60ff9c5 100644
@@ -175,6 +175,22 @@ unless you have specific needs for more advanced backends.
 The "simple" backend currently does not capture string arguments, it simply
 records the char* pointer value instead of the string that is pointed to.
 
+=== Ftrace ===
+
+The "ftrace" backend writes trace data to ftrace marker. This effectively
+sends trace events to ftrace ring buffer, and you can compare qemu trace
+data and kernel(especially kvm.ko when using KVM) trace data.
+
+if you use KVM, enable kvm events in ftrace:
+
+   # echo 1 > /sys/kernel/debug/tracing/events/kvm/enable
+
+After running qemu by root user, you can get the trace:
+
+   # cat /sys/kernel/debug/tracing/trace
+
+Restriction: "ftrace" backend is restricted to Linux only.
+
 ==== Monitor commands ====
 
 * trace-file on|off|flush|set <path>
Signature · 1 line
1.8.1.4
#3 lore raw
In reply to Eiichi Tsukata
Quoted 58 lines · Eiichi Tsukata

This patchset introduces a new tracing backend "ftrace".

Currently, QEMU tracing backends do not support userspace tracing with ftrace. Collecting QEMU trace data and kernel trace data simultaneouly is useful for latency analysis and debugging especially when using KVM.

With ftrace backend, you can easily collect QEMU-kernel merged trace data using existing ftrace event-based tracer. If you use KVM, you can effectively compare VM_EXIT and QEMU userspace handler.

To try it out, compile QEMU with tracing backend ftrace, then enable KVM events in ftrace:

    # echo 1 > /sys/kernel/debug/tracing/events/kvm/enable

After running qemu by root user, you can get the trace:

    # cat /sys/kernel/debug/tracing/trace

Example:
# tracer: nop
#
# entries-in-buffer/entries-written: 8434/345512 #P:4
#
# _-----=> irqs-off
# / _----=> need-resched

 #                            | / _---=> hardirq/softirq
 #                            || / _--=> preempt-depth
 #                            ||| /     delay
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION
 #              | |       |   ||||       |         |

<snip>
qemu-system-x86-31930 [000] d... 23580.595951: kvm_exit: reason IO_INSTRUCTION rip 0xc45d info 710048 0 qemu-system-x86-31930 [000] .... 23580.595954: kvm_emulate_insn: f0000:c45d:e4 71 (real) qemu-system-x86-31930 [000] .... 23580.595955: kvm_pio: pio_read at 0x71 size 1 count 1 qemu-system-x86-31930 [000] .... 23580.595956: kvm_userspace_exit: reason KVM_EXIT_IO (2) qemu-system-x86-31930 [000] ...1 23580.595959: tracing_mark_write: cpu_set_apic_base 00000000fee00900 qemu-system-x86-31930 [000] ...1 23580.595961: tracing_mark_write: cpu_in addr 0x71 value 0 qemu-system-x86-31930 [000] d... 23580.595964: kvm_entry: vcpu 0
<snip>

"tracing_mark_write: cpu_set_apic_base 00000000fee00900" and "tracing_mark_write: cpu_in addr 0x71 value 0" are QEMU trace data. Others are Kernel trace data.

Furthermore, the ftrace backend overhead is smaller than uprobe-based event tracer or SystemTap. My microbenchmark shows that ftrace tracing backend overhead is about 0.8us per tracepoint, whereas uprobe-based event tracer or SystemTap overhead is about 2.0us.

Changes in v2:
* fix Stefan's mail address.
* use snprintf return value not to waste trace buffer.

Eiichi Tsukata (2):
trace: Add ftrace tracing backend
trace: document ftrace backend

Quoted 15 lines
 configure                           |   8 +++
 docs/tracing.txt                    |  16 ++++++
 scripts/tracetool/backend/ftrace.py |  54 +++++++++++++++++++
 trace/Makefile.objs                 |   1 +
 trace/ftrace.c                      | 102 ++++++++++++++++++++++++++++++++++++
 trace/ftrace.h                      |  10 ++++
 6 files changed, 191 insertions(+)
 create mode 100644 scripts/tracetool/backend/ftrace.py
 create mode 100644 trace/ftrace.c
 create mode 100644 trace/ftrace.h
Signature · 1 line
1.8.1.4

Thanks, applied to my tracing tree:
https://github.com/stefanha/qemu/commits/tracing

Stefan