diff mbox

[net-next,1/2] perf, bpf: add support for HW_CACHE and RAW events

Message ID 20170522224840.810121-2-ast@fb.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Alexei Starovoitov May 22, 2017, 10:48 p.m. UTC
From: Teng Qin <qinteng@fb.com>

This commit adds support for attach BPF program to RAW and HW_CACHE type
events, and support for read HW_CACHE type event counters in BPF
program. Existing code logic already supports them, so this commit is
just update Enum value checks.

Signed-off-by: Teng Qin <qinteng@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
---
 kernel/bpf/arraymap.c    | 1 +
 kernel/events/core.c     | 4 +++-
 kernel/trace/bpf_trace.c | 1 +
 3 files changed, 5 insertions(+), 1 deletion(-)

Comments

Peter Zijlstra May 23, 2017, 7:42 a.m. UTC | #1
On Mon, May 22, 2017 at 03:48:39PM -0700, Alexei Starovoitov wrote:
> From: Teng Qin <qinteng@fb.com>
> 
> This commit adds support for attach BPF program to RAW and HW_CACHE type
> events, and support for read HW_CACHE type event counters in BPF
> program. Existing code logic already supports them, so this commit is
> just update Enum value checks.

So what I'm missing is why they were not supported previously, and what
changed to allow it now.
Alexei Starovoitov May 23, 2017, 2:38 p.m. UTC | #2
On 5/23/17 12:42 AM, Peter Zijlstra wrote:
> On Mon, May 22, 2017 at 03:48:39PM -0700, Alexei Starovoitov wrote:
>> From: Teng Qin <qinteng@fb.com>
>>
>> This commit adds support for attach BPF program to RAW and HW_CACHE type
>> events, and support for read HW_CACHE type event counters in BPF
>> program. Existing code logic already supports them, so this commit is
>> just update Enum value checks.
>
> So what I'm missing is why they were not supported previously, and what
> changed to allow it now.

that code path simply wasn't tested previously. Nothing changed on
bpf side and on perf side.
Why it wasn't added on day one? There was no demand. Now people
use bpf more and more and few folks got confused that these types
of perf events were not supported, hence we're adding it.
diff mbox

Patch

diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index 5e00b2333c26..f32affe8c335 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -473,6 +473,7 @@  static void *perf_event_fd_array_get_ptr(struct bpf_map *map,
 			goto err_out;
 		/* fall-through */
 	case PERF_TYPE_RAW:
+	case PERF_TYPE_HW_CACHE:
 	case PERF_TYPE_HARDWARE:
 		ee = bpf_event_entry_gen(perf_file, map_file);
 		if (ee)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 6e75a5c9412d..1b68cb751c03 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8038,7 +8038,9 @@  static int perf_event_set_bpf_prog(struct perf_event *event, u32 prog_fd)
 	struct bpf_prog *prog;
 
 	if (event->attr.type == PERF_TYPE_HARDWARE ||
-	    event->attr.type == PERF_TYPE_SOFTWARE)
+	    event->attr.type == PERF_TYPE_SOFTWARE ||
+	    event->attr.type == PERF_TYPE_HW_CACHE ||
+	    event->attr.type == PERF_TYPE_RAW)
 		return perf_event_set_bpf_handler(event, prog_fd);
 
 	if (event->attr.type != PERF_TYPE_TRACEPOINT)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 460a031c77e5..5cbda7962a32 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -249,6 +249,7 @@  BPF_CALL_2(bpf_perf_event_read, struct bpf_map *, map, u64, flags)
 
 	event = ee->event;
 	if (unlikely(event->attr.type != PERF_TYPE_HARDWARE &&
+		     event->attr.type != PERF_TYPE_HW_CACHE &&
 		     event->attr.type != PERF_TYPE_RAW))
 		return -EINVAL;