Message ID | 20191209135522.16576-6-bjorn.topel@gmail.com |
---|---|
State | Changes Requested |
Delegated to: | BPF Maintainers |
Headers | show |
Series | Introduce the BPF dispatcher | expand |
On Mon, 9 Dec 2019 14:55:21 +0100 Björn Töpel <bjorn.topel@gmail.com> wrote: > From: Björn Töpel <bjorn.topel@intel.com> > > The xdp_perf is a dummy XDP test, only used to measure the the cost of > jumping into a XDP program. I really like this idea of performance measuring XDP-core in isolation. This is the ultimate zoom-in micro-benchmarking. I see a use-case for this, where I will measure the XDP-core first, and then run same XDP prog (e.g. XDP_DROP) on a NIC driver, then I can deduct/isolate the driver-code and hardware overhead. We/I can also use it to optimize e.g. REDIRECT code-core (although redir might not actually work). IMHO it would be valuable to have bpf_prog_load() also measure the perf-HW counters for 'cycles' and 'instructions', as in your case the performance optimization was to improve the instructions-per-cycle (which you showed via perf stat in cover letter). If you send a V4 please describe how to use this prog to measure the cost, as you describe in cover letter. from selftests/bpf run: # test_progs -v -t xdp_perf (This is a nitpick, so only do this if something request a V4) > Signed-off-by: Björn Töpel <bjorn.topel@intel.com> > --- > .../selftests/bpf/prog_tests/xdp_perf.c | 25 +++++++++++++++++++ > 1 file changed, 25 insertions(+) > create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_perf.c > > diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_perf.c b/tools/testing/selftests/bpf/prog_tests/xdp_perf.c > new file mode 100644 > index 000000000000..7185bee16fe4 > --- /dev/null > +++ b/tools/testing/selftests/bpf/prog_tests/xdp_perf.c > @@ -0,0 +1,25 @@ > +// SPDX-License-Identifier: GPL-2.0 > +#include <test_progs.h> > + > +void test_xdp_perf(void) > +{ > + const char *file = "./xdp_dummy.o"; > + __u32 duration, retval, size; > + struct bpf_object *obj; > + char in[128], out[128]; > + int err, prog_fd; > + > + err = bpf_prog_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd); > + if (CHECK_FAIL(err)) > + return; > + > + err = bpf_prog_test_run(prog_fd, 1000000, &in[0], 128, > + out, &size, &retval, &duration); > + > + CHECK(err || retval != XDP_PASS || size != 128, > + "xdp-perf", > + "err %d errno %d retval %d size %d\n", > + err, errno, retval, size); > + > + bpf_object__close(obj); > +}
On Tue, 10 Dec 2019 at 12:05, Jesper Dangaard Brouer <brouer@redhat.com> wrote: > > On Mon, 9 Dec 2019 14:55:21 +0100 > Björn Töpel <bjorn.topel@gmail.com> wrote: > > > From: Björn Töpel <bjorn.topel@intel.com> > > > > The xdp_perf is a dummy XDP test, only used to measure the the cost of > > jumping into a XDP program. > > I really like this idea of performance measuring XDP-core in isolation. > This is the ultimate zoom-in micro-benchmarking. I see a use-case for > this, where I will measure the XDP-core first, and then run same XDP > prog (e.g. XDP_DROP) on a NIC driver, then I can deduct/isolate the > driver-code and hardware overhead. We/I can also use it to optimize > e.g. REDIRECT code-core (although redir might not actually work). > > IMHO it would be valuable to have bpf_prog_load() also measure the > perf-HW counters for 'cycles' and 'instructions', as in your case the > performance optimization was to improve the instructions-per-cycle > (which you showed via perf stat in cover letter). > > > If you send a V4 please describe how to use this prog to measure the > cost, as you describe in cover letter. > > from selftests/bpf run: > # test_progs -v -t xdp_perf > > (This is a nitpick, so only do this if something request a V4) > I'll definitely do a v4! Thanks for the input/comments! I'll address them in the next rev! Cheers, Björn > > > Signed-off-by: Björn Töpel <bjorn.topel@intel.com> > > --- > > .../selftests/bpf/prog_tests/xdp_perf.c | 25 +++++++++++++++++++ > > 1 file changed, 25 insertions(+) > > create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_perf.c > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_perf.c b/tools/testing/selftests/bpf/prog_tests/xdp_perf.c > > new file mode 100644 > > index 000000000000..7185bee16fe4 > > --- /dev/null > > +++ b/tools/testing/selftests/bpf/prog_tests/xdp_perf.c > > @@ -0,0 +1,25 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +#include <test_progs.h> > > + > > +void test_xdp_perf(void) > > +{ > > + const char *file = "./xdp_dummy.o"; > > + __u32 duration, retval, size; > > + struct bpf_object *obj; > > + char in[128], out[128]; > > + int err, prog_fd; > > + > > + err = bpf_prog_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd); > > + if (CHECK_FAIL(err)) > > + return; > > + > > + err = bpf_prog_test_run(prog_fd, 1000000, &in[0], 128, > > + out, &size, &retval, &duration); > > + > > + CHECK(err || retval != XDP_PASS || size != 128, > > + "xdp-perf", > > + "err %d errno %d retval %d size %d\n", > > + err, errno, retval, size); > > + > > + bpf_object__close(obj); > > +} > > > > -- > Best regards, > Jesper Dangaard Brouer > MSc.CS, Principal Kernel Engineer at Red Hat > LinkedIn: http://www.linkedin.com/in/brouer > > -- > Best regards, > Jesper Dangaard Brouer > MSc.CS, Principal Kernel Engineer at Red Hat > LinkedIn: http://www.linkedin.com/in/brouer >
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_perf.c b/tools/testing/selftests/bpf/prog_tests/xdp_perf.c new file mode 100644 index 000000000000..7185bee16fe4 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/xdp_perf.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <test_progs.h> + +void test_xdp_perf(void) +{ + const char *file = "./xdp_dummy.o"; + __u32 duration, retval, size; + struct bpf_object *obj; + char in[128], out[128]; + int err, prog_fd; + + err = bpf_prog_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd); + if (CHECK_FAIL(err)) + return; + + err = bpf_prog_test_run(prog_fd, 1000000, &in[0], 128, + out, &size, &retval, &duration); + + CHECK(err || retval != XDP_PASS || size != 128, + "xdp-perf", + "err %d errno %d retval %d size %d\n", + err, errno, retval, size); + + bpf_object__close(obj); +}