Skip to content

Commit

Permalink
libbpf-tools: fix readahead, support v5.10+ kernel
Browse files Browse the repository at this point in the history
Signed-off-by: Wenbo Zhang <[email protected]>
  • Loading branch information
ethercflow authored and yonghong-song committed Feb 6, 2021
1 parent 3df26a5 commit a976940
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
8 changes: 4 additions & 4 deletions libbpf-tools/readahead.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ struct {

static struct hist hist;

SEC("fentry/__do_page_cache_readahead")
int BPF_PROG(do_page_cache_readahead)
SEC("fentry/do_page_cache_ra")
int BPF_PROG(do_page_cache_ra)
{
u32 pid = bpf_get_current_pid_tgid();
u64 one = 1;
Expand All @@ -53,8 +53,8 @@ int BPF_PROG(page_cache_alloc_ret, gfp_t gfp, struct page *ret)
return 0;
}

SEC("fexit/__do_page_cache_readahead")
int BPF_PROG(do_page_cache_readahead_ret)
SEC("fexit/do_page_cache_ra")
int BPF_PROG(do_page_cache_ra_ret)
{
u32 pid = bpf_get_current_pid_tgid();

Expand Down
39 changes: 37 additions & 2 deletions libbpf-tools/readahead.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ static void sig_handler(int sig)
exiting = true;
}

static int readahead__set_attach_target(struct bpf_program *prog)
{
int err;

err = bpf_program__set_attach_target(prog, 0, "do_page_cache_ra");
if (!err)
return 0;

err = bpf_program__set_attach_target(prog, 0,
"__do_page_cache_readahead");
if (!err)
return 0;

fprintf(stderr, "failed to set attach target to %s: %s\n",
bpf_program__section_name(prog), strerror(-err));
return err;
}

int main(int argc, char **argv)
{
static const struct argp argp = {
Expand All @@ -95,12 +113,29 @@ int main(int argc, char **argv)
return 1;
}

obj = readahead_bpf__open_and_load();
obj = readahead_bpf__open();
if (!obj) {
fprintf(stderr, "failed to open and/or load BPF ojbect\n");
fprintf(stderr, "failed to open BPF object\n");
return 1;
}

/*
* Starting from v5.10-rc1 (8238287), __do_page_cache_readahead has
* renamed to do_page_cache_ra. So we specify the function dynamically.
*/
err = readahead__set_attach_target(obj->progs.do_page_cache_ra);
if (err)
goto cleanup;
err = readahead__set_attach_target(obj->progs.do_page_cache_ra_ret);
if (err)
goto cleanup;

err = readahead_bpf__load(obj);
if (err) {
fprintf(stderr, "failed to load BPF object\n");
goto cleanup;
}

err = readahead_bpf__attach(obj);
if (err) {
fprintf(stderr, "failed to attach BPF programs\n");
Expand Down

0 comments on commit a976940

Please sign in to comment.