Fix: update ftrace probe for kernel 4.12
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 25 May 2017 20:56:52 +0000 (16:56 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 29 May 2017 17:52:48 +0000 (13:52 -0400)
Follow changes introduced by Linux upstream commits:
  ec19b85913486993d7d6f747beed1a711afd47d8
  bca6c8d0480a8aa5c86f8f416db96c71f6b79e29
  b5f081b563a6cdcb85a543df8c851951a8978275
  6e4443199e5354255e8a4c1e8e5cfc8ef064c3ce

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
probes/Kbuild
probes/lttng-ftrace.c
wrapper/ftrace.h

index 2f6c7c76828681cb6795354f4e084f9e3c6e75a2..fe869d050d403fd582ed96a88175d14f0e76a66f 100644 (file)
@@ -259,7 +259,21 @@ ifneq ($(CONFIG_KRETPROBES),)
 endif # CONFIG_KRETPROBES
 
 ifneq ($(CONFIG_DYNAMIC_FTRACE),)
-  obj-$(CONFIG_LTTNG) += lttng-ftrace.o
+  ftrace_dep = $(srctree)/kernel/trace/trace.h
+  ftrace_dep_check = $(wildcard $(ftrace_dep))
+  ftrace = $(shell \
+    if [ $(VERSION) -ge 5 -o \( $(VERSION) -eq 4 -a $(PATCHLEVEL) -ge 12 \) ] ; then \
+      if [ -z "$(ftrace_dep_check)" ] ; then \
+        echo "warn" ; \
+        exit ; \
+      fi; \
+      echo "lttng-ftrace.o" ; \
+    fi;)
+  ifeq ($(ftrace),warn)
+    $(warning Files $(ftrace_dep) not found. Probe "ftrace" is disabled. Use full kernel source tree to enable it.)
+    ftrace =
+  endif # $(ftrace),warn
+  obj-$(CONFIG_LTTNG) += $(ftrace)
 endif # CONFIG_DYNAMIC_FTRACE
 
 # vim:syntax=make
index d8523198e08db3edabe4276a1eb734ff7b1ce012..9ec326ee56d992ab57101cc3d424d93f18fb3278 100644 (file)
 #include <wrapper/vmalloc.h>
 #include <lttng-tracer.h>
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0))
+static
+void lttng_ftrace_handler(unsigned long ip, unsigned long parent_ip,
+               struct trace_array *tr, struct ftrace_probe_ops *ops,
+               void *data)
+{
+       struct lttng_event *event = data;
+       struct lttng_probe_ctx lttng_probe_ctx = {
+               .event = event,
+               .interruptible = !irqs_disabled(),
+       };
+       struct lttng_channel *chan = event->chan;
+       struct lib_ring_buffer_ctx ctx;
+       struct {
+               unsigned long ip;
+               unsigned long parent_ip;
+       } payload;
+       int ret;
+
+       if (unlikely(!ACCESS_ONCE(chan->session->active)))
+               return;
+       if (unlikely(!ACCESS_ONCE(chan->enabled)))
+               return;
+       if (unlikely(!ACCESS_ONCE(event->enabled)))
+               return;
+
+       lib_ring_buffer_ctx_init(&ctx, chan->chan, &lttng_probe_ctx,
+                                sizeof(payload), lttng_alignof(payload), -1);
+       ret = chan->ops->event_reserve(&ctx, event->id);
+       if (ret < 0)
+               return;
+       payload.ip = ip;
+       payload.parent_ip = parent_ip;
+       lib_ring_buffer_align_ctx(&ctx, lttng_alignof(payload));
+       chan->ops->event_write(&ctx, &payload, sizeof(payload));
+       chan->ops->event_commit(&ctx);
+       return;
+}
+#else
 static
 void lttng_ftrace_handler(unsigned long ip, unsigned long parent_ip, void **data)
 {
@@ -74,6 +113,7 @@ void lttng_ftrace_handler(unsigned long ip, unsigned long parent_ip, void **data
        chan->ops->event_commit(&ctx);
        return;
 }
+#endif
 
 /*
  * Create event description
index 5a964387b68ea67f4e53b7dbe2eaeb7faef30033..de618734e44ee4cf4e6f587291dad59f37825a07 100644 (file)
  */
 
 #include <linux/ftrace.h>
+#include <linux/version.h>
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0))
+#include <../kernel/trace/trace.h>
+#endif
 
 #ifdef CONFIG_KALLSYMS
 
This page took 0.036617 seconds and 4 git commands to generate.