summaryrefslogtreecommitdiff
path: root/samples/bpf/spintest_user.c
diff options
context:
space:
mode:
authorDaniel T. Lee <danieltimlee@gmail.com>2023-08-18 12:01:19 +0300
committerAlexei Starovoitov <ast@kernel.org>2023-08-22 01:39:10 +0300
commit456d53554ca7e93d7e5e8eb7fe8c906d5ec6e7d0 (patch)
tree4fd7df7b9f5d0c1d6627867b16b32ef113e5188a /samples/bpf/spintest_user.c
parent8dc80551463197ec79ce0966ec2b5bd700042614 (diff)
downloadlinux-456d53554ca7e93d7e5e8eb7fe8c906d5ec6e7d0.tar.xz
samples/bpf: simplify spintest with kprobe.multi
With the introduction of kprobe.multi, it is now possible to attach multiple kprobes to a single BPF program without the need for multiple definitions. Additionally, this method supports wildcard-based matching, allowing for further simplification of BPF programs. In here, an asterisk (*) wildcard is used to map to all symbols relevant to spin_{lock|unlock}. Furthermore, since kprobe.multi handles symbol matching, this commit eliminates the need for the previous logic of reading the ksym table to verify the existence of symbols. Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com> Link: https://lore.kernel.org/r/20230818090119.477441-10-danieltimlee@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'samples/bpf/spintest_user.c')
-rw-r--r--samples/bpf/spintest_user.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/samples/bpf/spintest_user.c b/samples/bpf/spintest_user.c
index 8c77600776fb..55971edb1088 100644
--- a/samples/bpf/spintest_user.c
+++ b/samples/bpf/spintest_user.c
@@ -9,13 +9,12 @@
int main(int ac, char **argv)
{
- char filename[256], symbol[256];
struct bpf_object *obj = NULL;
struct bpf_link *links[20];
long key, next_key, value;
struct bpf_program *prog;
int map_fd, i, j = 0;
- const char *section;
+ char filename[256];
struct ksym *sym;
if (load_kallsyms()) {
@@ -44,20 +43,13 @@ int main(int ac, char **argv)
}
bpf_object__for_each_program(prog, obj) {
- section = bpf_program__section_name(prog);
- if (sscanf(section, "kprobe/%s", symbol) != 1)
- continue;
-
- /* Attach prog only when symbol exists */
- if (ksym_get_addr(symbol)) {
- links[j] = bpf_program__attach(prog);
- if (libbpf_get_error(links[j])) {
- fprintf(stderr, "bpf_program__attach failed\n");
- links[j] = NULL;
- goto cleanup;
- }
- j++;
+ links[j] = bpf_program__attach(prog);
+ if (libbpf_get_error(links[j])) {
+ fprintf(stderr, "bpf_program__attach failed\n");
+ links[j] = NULL;
+ goto cleanup;
}
+ j++;
}
for (i = 0; i < 5; i++) {