From dbee9ea8ede33166fa70ecc33af7d7721ef26280 Mon Sep 17 00:00:00 2001 From: Andrii Nakryiko Date: Fri, 17 Dec 2021 14:32:29 -0800 Subject: [PATCH] libbpf-tools: update llcstat for libbpf 1.0 Switch to libbpf 1.0 mode and adapt libbpf API usage accordingly. Signed-off-by: Andrii Nakryiko --- libbpf-tools/llcstat.bpf.c | 4 ++-- libbpf-tools/llcstat.c | 13 +++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/libbpf-tools/llcstat.bpf.c b/libbpf-tools/llcstat.bpf.c index fbd5b6c4..a36fc2df 100644 --- a/libbpf-tools/llcstat.bpf.c +++ b/libbpf-tools/llcstat.bpf.c @@ -36,13 +36,13 @@ int trace_event(__u64 sample_period, bool miss) return 0; } -SEC("perf_event/1") +SEC("perf_event") int on_cache_miss(struct bpf_perf_event_data *ctx) { return trace_event(ctx->sample_period, true); } -SEC("perf_event/2") +SEC("perf_event") int on_cache_ref(struct bpf_perf_event_data *ctx) { return trace_event(ctx->sample_period, false); diff --git a/libbpf-tools/llcstat.c b/libbpf-tools/llcstat.c index 13e9f0fb..89b49efe 100644 --- a/libbpf-tools/llcstat.c +++ b/libbpf-tools/llcstat.c @@ -106,10 +106,8 @@ static int open_and_attach_perf_event(__u64 config, int period, return -1; } links[i] = bpf_program__attach_perf_event(prog, fd); - if (libbpf_get_error(links[i])) { - fprintf(stderr, "failed to attach perf event on cpu: " - "%d\n", i); - links[i] = NULL; + if (!links[i]) { + fprintf(stderr, "failed to attach perf event on cpu: %d\n", i); close(fd); return -1; } @@ -185,14 +183,9 @@ int main(int argc, char **argv) if (err) return err; + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); libbpf_set_print(libbpf_print_fn); - err = bump_memlock_rlimit(); - if (err) { - fprintf(stderr, "failed to increase rlimit: %d\n", err); - return 1; - } - nr_cpus = libbpf_num_possible_cpus(); if (nr_cpus < 0) { fprintf(stderr, "failed to get # of possible cpus: '%s'!\n", -- 2.34.1