Hi Luiz, ma, 2025-03-31 kello 11:59 -0400, Luiz Augusto von Dentz kirjoitti: > Hi Pauli, > > On Sun, Mar 30, 2025 at 8:16 AM Pauli Virtanen <pav@xxxxxx> wrote: > > > > Add some tests for BPF timestamping on Bluetooth sockets. > > > > These require additional tester kernel config, and at build time > > the vmlinux image. > > > > Add cgroup mount to test-runner. > > > > Add documentation to tester config for this. > > > > Add tests: > > > > ISO Send - TX BPF Timestamping > > --- > > > > Notes: > > This probably needs to wait for the corresponding kernel patch series to > > settle down. > > > > Makefile.tools | 29 ++++++ > > configure.ac | 36 ++++++- > > doc/test-runner.rst | 26 ++++- > > doc/tester.config | 5 + > > tools/iso-tester.c | 71 ++++++++++++- > > tools/test-runner.c | 1 + > > tools/tester.bpf.c | 92 +++++++++++++++++ > > tools/tester.bpf.h | 7 ++ > > Usually we only do one . for source files, so names shall probably be > tester-bpf.{c,h}. Ok. The .bpf.c convention was used used in some places. > > tools/tester.h | 244 ++++++++++++++++++++++++++++++++++++-------- > > 9 files changed, 463 insertions(+), 48 deletions(-) > > create mode 100644 tools/tester.bpf.c > > create mode 100644 tools/tester.bpf.h > > > > diff --git a/Makefile.tools b/Makefile.tools > > index e60c31b1d..a35af54fc 100644 > > --- a/Makefile.tools > > +++ b/Makefile.tools > > @@ -144,6 +144,7 @@ tools_l2cap_tester_SOURCES = tools/l2cap-tester.c tools/tester.h monitor/bt.h \ > > emulator/smp.c > > tools_l2cap_tester_LDADD = lib/libbluetooth-internal.la \ > > src/libshared-glib.la $(GLIB_LIBS) > > +tools_l2cap_tester_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS) > > > > tools_rfcomm_tester_SOURCES = tools/rfcomm-tester.c monitor/bt.h \ > > emulator/hciemu.h emulator/hciemu.c \ > > @@ -191,6 +192,7 @@ tools_sco_tester_SOURCES = tools/sco-tester.c tools/tester.h monitor/bt.h \ > > emulator/smp.c > > tools_sco_tester_LDADD = lib/libbluetooth-internal.la \ > > src/libshared-glib.la $(GLIB_LIBS) > > +tools_sco_tester_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS) > > > > tools_hci_tester_SOURCES = tools/hci-tester.c monitor/bt.h > > tools_hci_tester_LDADD = src/libshared-glib.la $(GLIB_LIBS) > > @@ -212,6 +214,7 @@ tools_iso_tester_SOURCES = tools/iso-tester.c tools/tester.h monitor/bt.h \ > > emulator/smp.c > > tools_iso_tester_LDADD = lib/libbluetooth-internal.la \ > > src/libshared-glib.la $(GLIB_LIBS) > > +tools_iso_tester_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS) > > > > tools_ioctl_tester_SOURCES = tools/ioctl-tester.c monitor/bt.h \ > > emulator/hciemu.h emulator/hciemu.c \ > > @@ -221,6 +224,32 @@ tools_ioctl_tester_SOURCES = tools/ioctl-tester.c monitor/bt.h \ > > emulator/smp.c > > tools_ioctl_tester_LDADD = lib/libbluetooth-internal.la \ > > src/libshared-glib.la $(GLIB_LIBS) > > + > > +if TESTING_BPF > > +tools/vmlinux.h: $(BPF_VMLINUX) > > + bpftool btf dump file $(BPF_VMLINUX) format c > $@.new > > + mv -f $@.new $@ > > + > > +tools/tester.bpf.o: $(srcdir)/tools/tester.bpf.c tools/vmlinux.h > > + $(CLANG_BPF) -Wall -Werror -Os -g --target=bpf -Itools -c -o $@ $< > > + > > +tools/tester.skel.h: tools/tester.bpf.o > > + bpftool gen skeleton $< > $@.new > > + mv -f $@.new $@ > > + > > +tools_sco_tester_SOURCES += $(builddir)/tools/tester.skel.h > > +tools_iso_tester_SOURCES += $(builddir)/tools/tester.skel.h > > +tools_l2cap_tester_SOURCES += $(builddir)/tools/tester.skel.h > > + > > +tools_sco_tester_CPPFLAGS += -I$(builddir)/tools $(LIBBPF_CFLAGS) > > +tools_iso_tester_CPPFLAGS += -I$(builddir)/tools $(LIBBPF_CFLAGS) > > +tools_l2cap_tester_CPPFLAGS += -I$(builddir)/tools $(LIBBPF_CFLAGS) > > + > > +tools_sco_tester_LDADD += $(LIBBPF_LIBS) > > +tools_iso_tester_LDADD += $(LIBBPF_LIBS) > > +tools_l2cap_tester_LDADD += $(LIBBPF_LIBS) > > +endif > > + > > endif > > > > if TOOLS > > diff --git a/configure.ac b/configure.ac > > index 0fa49f686..627b91e77 100644 > > --- a/configure.ac > > +++ b/configure.ac > > @@ -390,10 +390,38 @@ AC_ARG_ENABLE(testing, AS_HELP_STRING([--enable-testing], > > AM_CONDITIONAL(TESTING, test "${enable_testing}" = "yes") > > > > if (test "${enable_testing}" = "yes"); then > > - AC_CHECK_DECLS([SOF_TIMESTAMPING_TX_COMPLETION, SCM_TSTAMP_COMPLETION], > > - [], [], [[#include <time.h> > > - #include <linux/errqueue.h> > > - #include <linux/net_tstamp.h>]]) > > + AC_CHECK_DECLS([SOF_TIMESTAMPING_TX_COMPLETION, SCM_TSTAMP_COMPLETION], > > + [], [], [[#include <time.h> > > + #include <linux/errqueue.h> > > + #include <linux/net_tstamp.h>]]) > > +fi > > + > > +AC_ARG_ENABLE(testing-bpf, AS_HELP_STRING([--enable-testing-bpf[=PATH/TO/VMLINUX]], > > + [enable BPF testing tools]), > > + [enable_testing_bpf=yes; enable_testing_bpf_arg=${enableval}], > > + [enable_bpf=no]) > > +AM_CONDITIONAL(TESTING_BPF, test "${enable_testing_bpf}" = "yes") > > + > > +if (test "${enable_testing_bpf}" = "yes"); then > > + AC_ARG_VAR(CLANG_BPF, [CLANG compiler (for BPF)]) > > + AC_ARG_VAR(BPFTOOL, [bpftool]) > > + AC_ARG_VAR(BPF_VMLINUX, [vmlinux image to use for BPF testing]) > > + AC_PATH_PROG([CLANG_BPF], [clang], "no") > > + if (test "${CLANG_BPF}" == "no"); then > > + AC_MSG_ERROR([clang for BPF missing]) > > + fi > > + AC_PATH_PROG([BPFTOOL], [bpftool], "no") > > + if (test "${BPFTOOL}" == "no"); then > > + AC_MSG_ERROR([bpftool missing]) > > + fi > > + PKG_CHECK_MODULES(LIBBPF, libbpf >= 1.4, [], [AC_MSG_ERROR([libbpf missing])]) > > + if (test "${enable_testing_bpf_arg}" != "yes"); then > > + BPF_VMLINUX=${enable_testing_bpf_arg} > > + elif (test "${BPF_VMLINUX}" = ""); then > > + BPF_VMLINUX=/sys/kernel/btf/vmlinux > > + fi > > + AC_MSG_NOTICE([using BPF_VMLINUX=${BPF_VMLINUX} for BPF testing]) > > + AC_DEFINE(HAVE_BPF, 1, [Define to 1 if bpf testing is required]) > > fi > > > > AC_ARG_ENABLE(experimental, AS_HELP_STRING([--enable-experimental], > > diff --git a/doc/test-runner.rst b/doc/test-runner.rst > > index 423a9379c..549b2bcba 100644 > > --- a/doc/test-runner.rst > > +++ b/doc/test-runner.rst > > @@ -91,8 +91,8 @@ Bluetooth > > > > CONFIG_UHID=y > > > > -Lock debuging > > -------------- > > +Lock debugging > > +-------------- > > > > To catch locking related issues the following set of kernel config > > options may be useful: > > @@ -110,6 +110,19 @@ options may be useful: > > CONFIG_DEBUG_MUTEXES=y > > CONFIG_KASAN=y > > > > +BPF testing > > +----------- > > + > > +For BPF related tests: > > + > > +.. code-block:: > > + > > + CONFIG_BPF=y > > + CONFIG_BPF_JIT=y > > + CONFIG_CGROUPS=y > > + CONFIG_CGROUP_BPF=y > > + > > + > > EXAMPLES > > ======== > > > > @@ -127,6 +140,15 @@ Running a specific test of mgmt-tester > > > > $ tools/test-runner -k /pathto/bzImage -- tools/mgmt-tester -s "<name>" > > > > +Compiling and running BPF tests > > +------------------------------- > > + > > +.. code-block:: > > + > > + $ ./configure --enable-testing --enable-testing-bpf=/home/me/linux/vmlinux > > + $ make > > + $ tools/test-runner -k /home/me/linux/arch/x86_64/boot/bzImage -- tools/iso-tester -s BPF > > + > > Running bluetoothctl with emulated controller > > --------------------------------------------- > > > > diff --git a/doc/tester.config b/doc/tester.config > > index 099eddc79..548e4c629 100644 > > --- a/doc/tester.config > > +++ b/doc/tester.config > > @@ -57,3 +57,8 @@ CONFIG_PROVE_RCU=y > > CONFIG_LOCKDEP=y > > CONFIG_DEBUG_MUTEXES=y > > CONFIG_KASAN=y > > + > > +CONFIG_BPF=y > > +CONFIG_BPF_JIT=y > > +CONFIG_CGROUPS=y > > +CONFIG_CGROUP_BPF=y > > diff --git a/tools/iso-tester.c b/tools/iso-tester.c > > index 350775fdd..da164c771 100644 > > --- a/tools/iso-tester.c > > +++ b/tools/iso-tester.c > > @@ -517,6 +517,9 @@ struct iso_client_data { > > > > /* Disable BT_POLL_ERRQUEUE before enabling TX timestamping */ > > bool no_poll_errqueue; > > + > > + /* Enable BPF TX timestamping */ > > + bool bpf_timestamping; > > Let's keep it short, bpf_ts. Ok. [clip] > Btw, does BPF also use the error queue? Or better yet can we avoid > waiting up bluetoothd id the process/pipewire use the BPF mode to be > notified of packet completion? BPF timestamping does not use errqueue, so it avoids the wakeup problem. It's harder to deploy: - needs CAP_NET_ADMIN afaik, and to be attached to a cgroup - BPF part may need recompilation if kernel structs it uses change (maybe not that often since it's mostly skb_shared_info) Not so great for sound servers running as user. -- Pauli Virtanen