From: Michael Jeanson Date: Thu, 25 May 2017 20:56:52 +0000 (-0400) Subject: Fix: update ftrace probe for kernel 4.12 X-Git-Tag: v2.9.3~3 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2b31a1ab5e6fed4984496c571a4c264f0d2e644d;p=lttng-modules.git Fix: update ftrace probe for kernel 4.12 Follow changes introduced by Linux upstream commits: ec19b85913486993d7d6f747beed1a711afd47d8 bca6c8d0480a8aa5c86f8f416db96c71f6b79e29 b5f081b563a6cdcb85a543df8c851951a8978275 6e4443199e5354255e8a4c1e8e5cfc8ef064c3ce Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/probes/Kbuild b/probes/Kbuild index 2f6c7c76..fe869d05 100644 --- a/probes/Kbuild +++ b/probes/Kbuild @@ -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 diff --git a/probes/lttng-ftrace.c b/probes/lttng-ftrace.c index d8523198..9ec326ee 100644 --- a/probes/lttng-ftrace.c +++ b/probes/lttng-ftrace.c @@ -39,6 +39,45 @@ #include #include +#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, <tng_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 diff --git a/wrapper/ftrace.h b/wrapper/ftrace.h index 5a964387..de618734 100644 --- a/wrapper/ftrace.h +++ b/wrapper/ftrace.h @@ -26,6 +26,10 @@ */ #include +#include +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0)) +#include <../kernel/trace/trace.h> +#endif #ifdef CONFIG_KALLSYMS