On Wed, Sep 23, 2020 at 6:45 PM Song Liu <songliubraving@xxxxxx> wrote: > > Add bpf_prog_test_run_opts() with support of new fields in bpf_attr.test, > namely, flags and cpu. Also extend _opts operations to support outputs via > opts. > > Signed-off-by: Song Liu <songliubraving@xxxxxx> > --- > tools/lib/bpf/bpf.c | 31 +++++++++++++++++++++++++++++++ > tools/lib/bpf/bpf.h | 26 ++++++++++++++++++++++++++ > tools/lib/bpf/libbpf.map | 1 + > tools/lib/bpf/libbpf_internal.h | 5 +++++ > 4 files changed, 63 insertions(+) > [...] > static int bpf_obj_get_next_id(__u32 start_id, __u32 *next_id, int cmd) > { > union bpf_attr attr; > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h > index 8c1ac4b42f908..4f13ec4323aff 100644 > --- a/tools/lib/bpf/bpf.h > +++ b/tools/lib/bpf/bpf.h > @@ -251,6 +251,32 @@ struct bpf_prog_bind_opts { > > LIBBPF_API int bpf_prog_bind_map(int prog_fd, int map_fd, > const struct bpf_prog_bind_opts *opts); > + > +struct bpf_test_run_opts { > + size_t sz; /* size of this struct for forward/backward compatibility */ > + int repeat; > + const void *data_in; > + __u32 data_size_in; > + void *data_out; /* optional */ > + __u32 data_size_out; /* in: max length of data_out > + * out: length of data_out > + */ > + __u32 retval; /* out: return code of the BPF program */ > + __u32 duration; /* out: average per repetition in ns */ > + const void *ctx_in; /* optional */ > + __u32 ctx_size_in; > + void *ctx_out; /* optional */ > + __u32 ctx_size_out; /* in: max length of ctx_out > + * out: length of cxt_out > + */ > + __u32 flags; > + __u32 cpu; > +}; lots of holes in there, let's reorder (it doesn't have to match the order in bpf_attr): size_t sz; /* size of this struct for forward/backward compatibility */ const void *data_in; void *data_out; __u32 data_size_in; __u32 data_size_out; const void *ctx_in; void *ctx_out; __u32 ctx_size_in; __u32 ctx_size_out; __u32 retval; int repeat; __u32 duration; __u32 flags; __u32 cpu; ? > +#define bpf_test_run_opts__last_field cpu > + > +LIBBPF_API int bpf_prog_test_run_opts(int prog_fd, > + struct bpf_test_run_opts *opts); > + > #ifdef __cplusplus > } /* extern "C" */ > #endif [...]