-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a path for BPF-accelerated async signal emulation.
Starting in kernel 6.10 BPF filters can choose whether or not to trigger the SIGIO behavior for a perf event that becomes readable. We combine that with a hardware breakpoint and a BPF filter that matches the GPRs to produce an accelerated internal breakpoint type that can fast forward through loop iterations to deliver async signals. On one trace this reduced rr's replay overhead by 94%. This adds a runtime dependency on libbpf and a compile time dependency on clang --target bpf. rr also needs CAP_BPF and CAP_PERFMON to use this feature. Because of all of that, this isn't really suitable for wide use at this point and is instead a CMake feature usebpf. Set -Dusebpf=ON to test it.
- Loading branch information
Showing
8 changed files
with
226 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <linux/bpf.h> | ||
#include <linux/bpf_perf_event.h> | ||
#include <bpf/bpf_helpers.h> | ||
#include <stdint.h> | ||
|
||
const uint32_t REGISTER_COUNT = sizeof(struct pt_regs)/sizeof(uint64_t); | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_ARRAY); | ||
__uint(max_entries, REGISTER_COUNT); | ||
__uint(map_flags, BPF_F_MMAPABLE); | ||
__type(key, uint32_t); | ||
__type(value, uint64_t); | ||
} registers SEC(".maps"); | ||
|
||
SEC("perf_event") | ||
int match_registers(struct bpf_perf_event_data* event) { | ||
#define CHECK_REG(name) \ | ||
{ \ | ||
const uint32_t i = offsetof(struct pt_regs, name) / sizeof(uint64_t); \ | ||
uint64_t* reg = bpf_map_lookup_elem(®isters, &i); \ | ||
if (!reg) { \ | ||
return 1; \ | ||
} \ | ||
if (event->regs.name != *reg) { \ | ||
return 0; \ | ||
} \ | ||
} | ||
|
||
CHECK_REG(r15) | ||
CHECK_REG(r14) | ||
CHECK_REG(r13) | ||
CHECK_REG(r12) | ||
CHECK_REG(rbp) | ||
CHECK_REG(rbx) | ||
CHECK_REG(r11) | ||
CHECK_REG(r10) | ||
CHECK_REG(r9) | ||
CHECK_REG(r8) | ||
CHECK_REG(rax) | ||
CHECK_REG(rcx) | ||
CHECK_REG(rdx) | ||
CHECK_REG(rsi) | ||
CHECK_REG(rdi) | ||
CHECK_REG(rip) | ||
|
||
return 1; | ||
} | ||
|
||
char _license[] SEC("license") = "GPL"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters