-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Perf event array map kernel-side implementation #4144
base: main
Are you sure you want to change the base?
Conversation
7623a4f
to
10d4f86
Compare
d5f2cea
to
a5f9711
Compare
Moving to draft until the ring buffer refactoring is merged in #4204 |
This is currently blocked on #4204, as it uses the new ring buffer for wait-free reserve (at dispatch) in the per-cpu rings. Most of the refactoring to use the new ring buffer has been done, but after the new ring buffer implementation is merged I'll update+publish this again. |
6513f71
to
547a6e1
Compare
- Makes header support mandatory for programs and extensions. - Completes context header support for netebpfext - Adds context header support to all test/mock bpf program contexts.
I split the context header support requirement out into #4267. After that passes all CICD tests I'll rebase this PR split into two commits - context header support then perf event array impl. |
@@ -101,17 +101,17 @@ structure from provided data and context buffers. | |||
context structure and populates the returned data and context buffers. | |||
* `required_irql`: IRQL at which the eBPF program is invoked by bpf_prog_test_run_opts. | |||
* `capabilities`: 32-bit integer describing the optional capabilities / features supported by the extension. | |||
* `supports_context_header`: Flag indicating extension supports adding a context header at the start of each context passed to the eBPF program. | |||
* `supports_context_header`: Required flag indicating extension supports adding a context header at the start of each context passed to the eBPF program. This flag must be set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The context header changes have been split out into PR #4267
This comment is to ensure 4267 merges before this PR (this PR contains the context header changes as the first commit).
libs/runtime/ebpf_perf_event_array.h
Outdated
@@ -0,0 +1,147 @@ | |||
// Copyright (c) eBPF for Windows contributors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this as a separate module? Why not merge all of this into ebpf_core_perf_event_array_map_t
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was easier to thoroughly test with the layers separated. I agree that the consolidation makes more sense at this point.
The perf event array on linux is significantly different at the mmap level (though very similar at libbpf callback level we currently expose), but with the refactoring to make perf event array an array of ebpf_ring_buffer_t for now it doesn't make sense to add a new set of files for it.
The PR has been updated to remove ebpf_perf_event_array.c/h
@@ -302,6 +319,32 @@ _ring_next_consumer_record(_In_ ebpf_ring_buffer_t* ring, _When_(return != NULL, | |||
return NULL; | |||
} | |||
|
|||
_Must_inspect_result_ ebpf_result_t | |||
ebpf_ring_buffer_initialize_ring( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is both a create and a initialize function, ideally create should allocate memory, and initialize should populate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create
allocates memory for an ebpf_ring_buffer_t
and initializes it.
- the ring buffer map uses this (as it did before) to create the
ebpf_ring_buffer_t
that the core ring buffer map object points to
initialize
initializes an ebpf_ring_buffer_t
struct in-place (including allocating the memory ring).
- perf event array map uses this to initialize the
ebpf_ring_buffer_t
that is inside theebpf_core_perf_ring_t
libs/runtime/ebpf_perf_event_array.c
Outdated
} | ||
|
||
_Must_inspect_result_ ebpf_result_t | ||
ebpf_perf_event_array_output_simple( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this wrapper function really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libs/execution_context/ebpf_core.c
Outdated
goto Exit; | ||
} | ||
result = | ||
ebpf_perf_event_output_simple(map, (uint32_t)EBPF_MAP_FLAG_CURRENT_CPU, (uint8_t*)request->data, data_length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simply call ebpf_perf_event_output
with ctx = NULL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is invalid to call perf_event_output (the helper) without ctx, so I added a separate function to simply write a single data blob to a perf event array.
The difference between the two functions is now larger and more obvious -- mainly that output_simple can skip most of the argument handling and doesn't require ctx/flags.
Do you still think I should remove this (and then allow and check for null ctx for ebpf_perf_event_output)?
uint32_t cpu_id; | ||
ebpf_perf_event_array_map_async_query_result_t* async_query_result; | ||
void* async_context; | ||
} ebpf_core_perf_event_array_map_async_query_context_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this can be reconciled with ebpf_core_ring_buffer_map_async_query_context_t
in a subsequent pull request.
ebpf_map_create(&map_name, &map_definition, (uintptr_t)ebpf_handle_invalid, &local_map) == EBPF_SUCCESS); | ||
map.reset(local_map); | ||
} | ||
// TODO (before merge): implementme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment to track porting the necessary platform unit tests over to execution context unit tests using the new ebpf_maps based definition (vs. the old ebpf_perf_event_array based implementation).
Description
Implements the kernel side of perf event array maps.
This includes the core and kernel changes for #658, with part of the user-side API skeleton.
Testing
Includes platform and execution context tests.
Documentation
Documented in code and PerfEventArray.md.
Installation
N/A