Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions include/bpftune/libbpftune.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,39 +205,33 @@ void bpftuner_tunables_fini(struct bpftuner *tuner);
} \
} while (0)

#define _bpftuner_bpf_load(tuner_name, tuner, optionals) ({ \
#define bpftuner_bpf_load(tuner_name, tuner, optionals) ({ \
int __err; \
\
__err = __bpftuner_bpf_load(tuner, optionals); \
__err = __bpftuner_bpf_load(tuner, NULL); \
if (__err && optionals != NULL) { \
bpftuner_bpf_fini(tuner); \
__err = bpftuner_bpf_open(tuner_name, tuner); \
if (!__err) \
__err = __bpftuner_bpf_load(tuner, optionals); \
} \
if (__err) \
bpftuner_bpf_destroy(tuner_name, tuner); \
__err; \
})

#define bpftuner_bpf_load(tuner_name, tuner) \
_bpftuner_bpf_load(tuner_name, tuner, NULL)

#define bpftuner_bpf_attach(tuner_name, tuner, optionals) ({ \
#define bpftuner_bpf_attach(tuner_name, tuner) ({ \
int __err = __bpftuner_bpf_attach(tuner); \
\
if (__err && optionals != NULL) { \
bpftuner_bpf_fini(tuner); \
__err = bpftuner_bpf_open(tuner_name, tuner); \
if (!__err) \
__err = _bpftuner_bpf_load(tuner_name, tuner, optionals); \
if (!__err) \
__err = __bpftuner_bpf_attach(tuner); \
} \
__err; \
})

#define bpftuner_bpf_init(tuner_name, tuner, optionals) ({ \
int __err = bpftuner_bpf_open(tuner_name, tuner); \
\
if (!__err) \
__err = bpftuner_bpf_load(tuner_name, tuner); \
__err = bpftuner_bpf_load(tuner_name, tuner, optionals); \
if (!__err) \
bpftuner_bpf_attach(tuner_name, tuner, optionals); \
bpftuner_bpf_attach(tuner_name, tuner); \
__err; \
})

Expand Down
5 changes: 5 additions & 0 deletions sample_tuner/sample_tuner.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ BPF_FENTRY(proc_dostring_coredump, struct ctl_table *table, int write,
tuner_id, scenario_id, ret);
return 0;
}

BPF_FENTRY(this_function_does_not_exist, void *arg)
{
return 0;
}
5 changes: 4 additions & 1 deletion sample_tuner/sample_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

int init(struct bpftuner *tuner)
{
return bpftuner_bpf_init(sample, tuner, NULL);
const char *optionals[] = { "entry__this_function_does_not_exist",
NULL };

return bpftuner_bpf_init(sample, tuner, optionals);
}

void fini(struct bpftuner *tuner)
Expand Down
2 changes: 2 additions & 0 deletions src/libbpftune.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ int __bpftuner_bpf_load(struct bpftuner *tuner, const char **optionals)
for (i = 0; optionals[i] != NULL; i++) {
struct bpf_program *prog;

bpftune_log(LOG_DEBUG, "looking for optional prog '%s'\n",
optionals[i]);
prog = bpf_object__find_program_by_name(tuner->obj,
optionals[i]);
if (prog) {
Expand Down
4 changes: 2 additions & 2 deletions src/net_buffer_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ int init(struct bpftuner *tuner)
err = bpftuner_bpf_open(net_buffer, tuner);
if (err)
return err;
err = bpftuner_bpf_load(net_buffer, tuner);
err = bpftuner_bpf_load(net_buffer, tuner, NULL);
if (err)
return err;
bpftuner_bpf_var_set(net_buffer, tuner, flow_limit_cpu_bitmap,
cpu_bitmap);
err = bpftuner_bpf_attach(net_buffer, tuner, NULL);
err = bpftuner_bpf_attach(net_buffer, tuner);
if (err)
return err;

Expand Down
4 changes: 2 additions & 2 deletions src/netns_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ int init(struct bpftuner *tuner)
err = bpftuner_bpf_open(netns, tuner);
if (err)
return err;
err = bpftuner_bpf_load(netns, tuner);
err = bpftuner_bpf_load(netns, tuner, optionals);
if (err)
return err;
err = bpftuner_bpf_attach(netns, tuner, optionals);
err = bpftuner_bpf_attach(netns, tuner);
if (err)
return err;

Expand Down
6 changes: 3 additions & 3 deletions src/tcp_buffer_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ long nr_free_buffer_pages(bool initial)
int init(struct bpftuner *tuner)
{
/* on some platforms, this function is inlined */
const char *optionals[] = { "tcp_sndbuf_expand", NULL };
const char *optionals[] = { "entry__tcp_sndbuf_expand", NULL };
int pagesize;
int err;

err = bpftuner_bpf_open(tcp_buffer, tuner);
if (err)
return err;
err = bpftuner_bpf_load(tcp_buffer, tuner);
err = bpftuner_bpf_load(tcp_buffer, tuner, optionals);
if (err)
return err;

Expand All @@ -164,7 +164,7 @@ int init(struct bpftuner *tuner)
ilog2(SK_MEM_QUANTUM));
bpftuner_bpf_var_set(tcp_buffer, tuner, nr_free_buffer_pages,
nr_free_buffer_pages(true));
err = bpftuner_bpf_attach(tcp_buffer, tuner, optionals);
err = bpftuner_bpf_attach(tcp_buffer, tuner);
if (err)
return err;
return bpftuner_tunables_init(tuner, TCP_BUFFER_NUM_TUNABLES, descs,
Expand Down