aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHengqi Chen <chenhengqi@outlook.com>2021-12-11 16:27:11 +0800
committeryonghong-song <ys114321@gmail.com>2022-03-12 10:58:23 -0800
commit194e69082733f7256ff9f0b84d3ae90176c2e757 (patch)
tree1fcaa46c577064b14d4282bab47414d1bf2e54dc
parent2f4f22c502ccb68fee87409cf8a70f798202a51f (diff)
downloadbcc-194e69082733f7256ff9f0b84d3ae90176c2e757.tar.gz
libbpf-tools: Fix cachestat with kernel 5.15
The tool cachestat is broken on kernel 5.15 due to kernel function renaming. Fix the tool by detecting symbol existence. See #3687 and #3692. Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
-rw-r--r--libbpf-tools/cachestat.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/libbpf-tools/cachestat.c b/libbpf-tools/cachestat.c
index 05785251..95d98208 100644
--- a/libbpf-tools/cachestat.c
+++ b/libbpf-tools/cachestat.c
@@ -142,12 +142,31 @@ int main(int argc, char **argv)
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
libbpf_set_print(libbpf_print_fn);
- obj = cachestat_bpf__open_and_load();
+ obj = cachestat_bpf__open();
if (!obj) {
- fprintf(stderr, "failed to open and/or load BPF object\n");
+ fprintf(stderr, "failed to open BPF object\n");
return 1;
}
+ /**
+ * account_page_dirtied was renamed to folio_account_dirtied
+ * in kernel commit 203a31516616 ("mm/writeback: Add __folio_mark_dirty()")
+ */
+ if (fentry_exists("folio_account_dirtied", NULL)) {
+ err = bpf_program__set_attach_target(obj->progs.account_page_dirtied, 0,
+ "folio_account_dirtied");
+ if (err) {
+ fprintf(stderr, "failed to set attach target\n");
+ goto cleanup;
+ }
+ }
+
+ err = cachestat_bpf__load(obj);
+ if (err) {
+ fprintf(stderr, "failed to load BPF object\n");
+ goto cleanup;
+ }
+
if (!obj->bss) {
fprintf(stderr, "Memory-mapping BPF maps is supported starting from Linux 5.7, please upgrade.\n");
goto cleanup;