From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Tom Zanussi <tom.zanussi@linux.intel.com>,
linux-rt-users@vger.kernel.org,
linux-trace-users@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Clark Williams <williams@redhat.com>,
Jiri Olsa <jolsa@redhat.com>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Jonathan Corbet <corbet@lwn.net>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Namhyung Kim <namhyung@kernel.org>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subject: [PATCH 18/18] tracing/perf: Allow perf to use function based events
Date: Fri, 02 Feb 2018 18:05:16 -0500 [thread overview]
Message-ID: <20180202231019.721645441@goodmis.org> (raw)
In-Reply-To: 20180202230458.840252014@goodmis.org
[-- Attachment #1: 0018-tracing-perf-Allow-perf-to-use-function-based-events.patch --]
[-- Type: text/plain, Size: 6684 bytes --]
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Have perf use function based events.
# echo 'SyS_openat(int dfd, string buf, x32 flags, x32 mode)' > /sys/kernel/tracing/function_events
# perf record -e functions:SyS_openat grep task_forks /proc/kallsyms
# perf script
grep 913 [002] 5713.413239: functions:SyS_openat: entry_SYSCALL_64_fastpath->sys_openat(dfd=-100, buf=/proc/kallsyms, flags=100, mode=0)
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
Documentation/trace/function-based-events.rst | 3 +-
kernel/trace/trace_event_ftrace.c | 134 ++++++++++++++++++++------
2 files changed, 104 insertions(+), 33 deletions(-)
diff --git a/Documentation/trace/function-based-events.rst b/Documentation/trace/function-based-events.rst
index 3b341992b93d..6effde96d3d6 100644
--- a/Documentation/trace/function-based-events.rst
+++ b/Documentation/trace/function-based-events.rst
@@ -48,7 +48,8 @@ enable filter format hist id trigger
Even though the above function based event does not record much more
than the function tracer does, it does become a full fledge event.
-This can be used by the histogram infrastructure, and triggers.
+This can be used by the histogram infrastructure, triggers, and perf
+where one can attach eBPF programs to.
# cat events/functions/do_IRQ/format
name: do_IRQ
diff --git a/kernel/trace/trace_event_ftrace.c b/kernel/trace/trace_event_ftrace.c
index b5b719680686..b145639eac45 100644
--- a/kernel/trace/trace_event_ftrace.c
+++ b/kernel/trace/trace_event_ftrace.c
@@ -747,46 +747,33 @@ static int get_string(unsigned long addr, unsigned int idx,
return len;
}
-static void func_event_trace(struct trace_event_file *trace_file,
- struct func_event *func_event,
- unsigned long ip, unsigned long parent_ip,
- struct pt_regs *pt_regs)
+static int get_event_size(struct func_event *func_event, struct pt_regs *pt_regs,
+ long *args, int *nr_args)
{
- struct func_event_hdr *entry;
- struct trace_event_call *call = &func_event->call;
- struct ring_buffer_event *event;
- struct ring_buffer *buffer;
- struct func_arg *arg;
- long args[func_event->arg_cnt];
- long long val = 1;
- unsigned long irq_flags;
- int str_offset;
- int str_idx = 0;
- int nr_args = 0;
int size;
- int pc;
-
- if (trace_trigger_soft_disabled(trace_file))
- return;
-
- local_save_flags(irq_flags);
- pc = preempt_count();
- size = func_event->arg_offset + sizeof(*entry);
+ size = func_event->arg_offset + sizeof(struct func_event_hdr);
if (func_event->arg_cnt)
- nr_args = arch_get_func_args(pt_regs, 0, func_event->arg_cnt, args);
+ *nr_args = arch_get_func_args(pt_regs, 0, func_event->arg_cnt, args);
+ else
+ *nr_args = 0;
if (func_event->has_strings)
- size += calculate_strings(func_event, nr_args, args);
+ size += calculate_strings(func_event, *nr_args, args);
- event = trace_event_buffer_lock_reserve(&buffer, trace_file,
- call->event.type,
- size, irq_flags, pc);
- if (!event)
- return;
+ return size;
+}
+
+static void
+record_entry(struct func_event_hdr *entry, struct func_event *func_event,
+ unsigned long ip, unsigned long parent_ip, int nr_args, long *args)
+{
+ struct func_arg *arg;
+ long long val;
+ int str_offset;
+ int str_idx = 0;
- entry = ring_buffer_event_data(event);
entry->ip = ip;
entry->parent_ip = parent_ip;
@@ -809,11 +796,80 @@ static void func_event_trace(struct trace_event_file *trace_file,
} else
memcpy(&entry->data[arg->offset], &val, arg->size);
}
+}
+
+static void func_event_trace(struct trace_event_file *trace_file,
+ struct func_event *func_event,
+ unsigned long ip, unsigned long parent_ip,
+ struct pt_regs *pt_regs)
+{
+ struct func_event_hdr *entry;
+ struct trace_event_call *call = &func_event->call;
+ struct ring_buffer_event *event;
+ struct ring_buffer *buffer;
+ long args[func_event->arg_cnt];
+ unsigned long irq_flags;
+ int nr_args;
+ int size;
+ int pc;
+
+ if (trace_trigger_soft_disabled(trace_file))
+ return;
+
+ local_save_flags(irq_flags);
+ pc = preempt_count();
+
+ size = get_event_size(func_event, pt_regs, args, &nr_args);
+
+ event = trace_event_buffer_lock_reserve(&buffer, trace_file,
+ call->event.type,
+ size, irq_flags, pc);
+ if (!event)
+ return;
+ entry = ring_buffer_event_data(event);
+ record_entry(entry, func_event, ip, parent_ip, nr_args, args);
event_trigger_unlock_commit_regs(trace_file, buffer, event,
entry, irq_flags, pc, pt_regs);
}
+#ifdef CONFIG_PERF_EVENTS
+/* Kprobe profile handler */
+static void func_event_perf(struct func_event *func_event,
+ unsigned long ip, unsigned long parent_ip,
+ struct pt_regs *pt_regs)
+{
+ struct trace_event_call *call = &func_event->call;
+ struct func_event_hdr *entry;
+ struct hlist_head *head;
+ long args[func_event->arg_cnt];
+ int nr_args = 0;
+ int rctx;
+ int size;
+
+ if (bpf_prog_array_valid(call) && !trace_call_bpf(call, pt_regs))
+ return;
+
+ head = this_cpu_ptr(call->perf_events);
+ if (hlist_empty(head))
+ return;
+
+ size = get_event_size(func_event, pt_regs, args, &nr_args);
+
+ entry = perf_trace_buf_alloc(size, NULL, &rctx);
+ if (!entry)
+ return;
+
+ record_entry(entry, func_event, ip, parent_ip, nr_args, args);
+ perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, pt_regs,
+ head, NULL);
+}
+#else
+static inline void func_event_perf(struct func_event *func_event,
+ unsigned long ip, unsigned long parent_ip,
+ struct pt_regs *pt_regs) { }
+#endif
+
static void
func_event_call(unsigned long ip, unsigned long parent_ip,
struct ftrace_ops *op, struct pt_regs *pt_regs)
@@ -825,7 +881,10 @@ func_event_call(unsigned long ip, unsigned long parent_ip,
rcu_read_lock_sched();
list_for_each_entry_rcu(ff, &func_event->files, list) {
- func_event_trace(ff->file, func_event, ip, parent_ip, pt_regs);
+ if (ff->file)
+ func_event_trace(ff->file, func_event, ip, parent_ip, pt_regs);
+ else
+ func_event_perf(func_event, ip, parent_ip, pt_regs);
}
rcu_read_unlock_sched();
}
@@ -1041,6 +1100,17 @@ static int func_event_register(struct trace_event_call *event,
return enable_func_event(func_event, file);
case TRACE_REG_UNREGISTER:
return disable_func_event(func_event, file);
+#ifdef CONFIG_PERF_EVENTS
+ case TRACE_REG_PERF_REGISTER:
+ return enable_func_event(func_event, NULL);
+ case TRACE_REG_PERF_UNREGISTER:
+ return disable_func_event(func_event, NULL);
+ case TRACE_REG_PERF_OPEN:
+ case TRACE_REG_PERF_CLOSE:
+ case TRACE_REG_PERF_ADD:
+ case TRACE_REG_PERF_DEL:
+ return 0;
+#endif
default:
break;
}
--
2.15.1
next prev parent reply other threads:[~2018-02-02 23:05 UTC|newest]
Thread overview: 82+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-02 23:04 [PATCH 00/18] [ANNOUNCE] Dynamically created function based events Steven Rostedt
2018-02-02 23:04 ` [PATCH 01/18] tracing: Add " Steven Rostedt
2018-02-05 8:24 ` Jiri Olsa
2018-02-05 15:00 ` Steven Rostedt
2018-02-07 3:09 ` Steven Rostedt
2018-02-07 12:06 ` Jiri Olsa
2018-02-02 23:05 ` [PATCH 02/18] tracing: Add documentation for " Steven Rostedt
2018-02-02 23:05 ` [PATCH 03/18] tracing: Add simple arguments to " Steven Rostedt
2018-02-08 10:18 ` Namhyung Kim
2018-02-08 15:37 ` Steven Rostedt
2018-02-02 23:05 ` [PATCH 04/18] tracing/x86: Add arch_get_func_args() function Steven Rostedt
2018-02-05 16:33 ` Masami Hiramatsu
2018-02-05 17:06 ` Steven Rostedt
2018-02-08 5:28 ` Namhyung Kim
2018-02-08 15:29 ` Steven Rostedt
2018-02-02 23:05 ` [PATCH 05/18] tracing: Add hex print for dynamic ftrace based events Steven Rostedt
2018-02-02 23:05 ` [PATCH 06/18] tracing: Add indirect offset to args of " Steven Rostedt
2018-02-02 23:05 ` [PATCH 07/18] tracing: Add dereferencing multiple fields per arg Steven Rostedt
2018-02-02 23:05 ` [PATCH 08/18] tracing: Add "unsigned" to function based events Steven Rostedt
2018-02-02 23:05 ` [PATCH 09/18] tracing: Add indexing of arguments for " Steven Rostedt
2018-02-08 10:59 ` Namhyung Kim
2018-02-08 15:43 ` Steven Rostedt
2018-02-08 23:56 ` Namhyung Kim
2018-02-09 0:19 ` Steven Rostedt
2018-02-02 23:05 ` [PATCH 10/18] tracing: Make func_type enums for easier comparing of arg types Steven Rostedt
2018-02-02 23:05 ` [PATCH 11/18] tracing: Add symbol type to function based events Steven Rostedt
2018-02-08 11:03 ` Namhyung Kim
2018-02-08 15:48 ` Steven Rostedt
2018-02-02 23:05 ` [PATCH 12/18] tracing: Add accessing direct address from " Steven Rostedt
2018-02-09 0:34 ` Namhyung Kim
2018-02-09 1:10 ` Steven Rostedt
2018-02-09 22:07 ` Steven Rostedt
2018-02-12 2:06 ` Namhyung Kim
2018-02-12 15:47 ` Masami Hiramatsu
2018-02-12 16:47 ` Steven Rostedt
2018-02-02 23:05 ` [PATCH 13/18] tracing: Add array type to " Steven Rostedt
2018-02-03 13:56 ` Masami Hiramatsu
2018-02-03 15:29 ` Steven Rostedt
2018-02-04 3:50 ` Masami Hiramatsu
2018-02-09 1:17 ` Namhyung Kim
2018-02-09 1:54 ` Steven Rostedt
2018-02-02 23:05 ` [PATCH 14/18] tracing: Have char arrays be strings for " Steven Rostedt
2018-02-02 23:05 ` [PATCH 15/18] tracing: Add string type for dynamic strings in " Steven Rostedt
2018-02-09 3:15 ` Namhyung Kim
2018-02-09 3:31 ` Steven Rostedt
2018-02-02 23:05 ` [PATCH 16/18] tracing: Add NULL to skip args for " Steven Rostedt
2018-02-02 23:05 ` [PATCH 17/18] tracing: Add indirect to indirect access " Steven Rostedt
2018-02-09 5:13 ` Namhyung Kim
2018-02-09 15:47 ` Steven Rostedt
2018-02-09 17:18 ` Steven Rostedt
2018-02-12 2:15 ` Namhyung Kim
2018-02-12 17:23 ` Steven Rostedt
2018-02-13 9:27 ` Namhyung Kim
2018-02-13 15:28 ` Steven Rostedt
2018-02-02 23:05 ` Steven Rostedt [this message]
2018-02-03 13:38 ` [PATCH 00/18] [ANNOUNCE] Dynamically created " Masami Hiramatsu
2018-02-03 15:27 ` Steven Rostedt
2018-02-04 3:57 ` Masami Hiramatsu
2018-02-03 17:04 ` Mathieu Desnoyers
2018-02-03 19:02 ` Steven Rostedt
2018-02-03 20:52 ` Alexei Starovoitov
2018-02-03 21:08 ` Steven Rostedt
2018-02-03 21:30 ` Alexei Starovoitov
2018-02-04 2:37 ` Namhyung Kim
2018-02-04 15:50 ` Mathieu Desnoyers
2018-02-03 21:17 ` Steven Rostedt
2018-02-03 21:38 ` Alexei Starovoitov
2018-02-04 2:25 ` Namhyung Kim
2018-02-05 15:02 ` Steven Rostedt
2018-02-05 13:53 ` Juri Lelli
2018-02-05 15:07 ` Steven Rostedt
2018-02-03 21:43 ` Linus Torvalds
2018-02-04 15:30 ` Mathieu Desnoyers
2018-02-04 15:47 ` Steven Rostedt
2018-02-04 19:39 ` Linus Torvalds
2018-02-05 10:09 ` Peter Zijlstra
2018-02-05 15:10 ` Steven Rostedt
2018-02-05 15:14 ` Masami Hiramatsu
2018-02-03 18:52 ` Steven Rostedt
2018-02-05 10:23 ` Juri Lelli
2018-02-05 10:49 ` Daniel Bristot de Oliveira
2018-02-05 15:11 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180202231019.721645441@goodmis.org \
--to=rostedt@goodmis.org \
--cc=acme@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alexei.starovoitov@gmail.com \
--cc=bristot@redhat.com \
--cc=corbet@lwn.net \
--cc=jolsa@redhat.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=linux-trace-users@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=tom.zanussi@linux.intel.com \
--cc=torvalds@linux-foundation.org \
--cc=williams@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).