[PATCH 2/3] perf: Move exclude_kernel tracepoint check to init event

From: Jiri Olsa
Date: Thu Nov 26 2015 - 14:35:08 EST


We suppress events with attr::exclude_kernel set when
the event is generated, so following capture will
give no warning and produce no data:

$ sudo perf record -e sched:sched_switch:u ls
$ sudo /perf script | wc -l
0

Checking the attr::exclude_kernel at the event init
time and failing right away:

$ sudo perf record -e sched:sched_switch:u ls
Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (sched:sched_switch).
/bin/dmesg may provide additional information.
No CONFIG_PERF_EVENTS=y kernel support configured?

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
kernel/events/core.c | 5 -----
kernel/trace/trace_event_perf.c | 15 +++++++++++++++
2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 5854fcf7f05a..9fb9d5ef6825 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6938,11 +6938,6 @@ static int perf_tp_event_match(struct perf_event *event,
{
if (event->hw.state & PERF_HES_STOPPED)
return 0;
- /*
- * All tracepoints are from kernel-space.
- */
- if (event->attr.exclude_kernel)
- return 0;

if (!perf_tp_filter_match(event, data))
return 0;
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
index c41463af3298..637268855296 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -182,11 +182,26 @@ static void perf_trace_event_close(struct perf_event *p_event)
tp_event->class->reg(tp_event, TRACE_REG_PERF_CLOSE, p_event);
}

+static int perf_trace_event_attr(struct perf_event *event)
+{
+ /*
+ * All tracepoints are from kernel-space.
+ */
+ if (event->attr.exclude_kernel)
+ return -EINVAL;
+
+ return 0;
+}
+
static int perf_trace_event_init(struct trace_event_call *tp_event,
struct perf_event *p_event)
{
int ret;

+ ret = perf_trace_event_attr(p_event);
+ if (ret)
+ return ret;
+
ret = perf_trace_event_perm(tp_event, p_event);
if (ret)
return ret;
--
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/