From: Libor Peltan Date: Tue, 17 Dec 2019 16:02:57 +0000 (+0100) Subject: xdp: conditional compilation of xdp support X-Git-Tag: embedded_lmdb~35^2~85 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc758178f1707bd7d8b8dac3fa20f58a1dff0e41;p=thirdparty%2Fknot-dns.git xdp: conditional compilation of xdp support --- diff --git a/configure.ac b/configure.ac index aa5f6c5419..ccaa7ce0bd 100644 --- a/configure.ac +++ b/configure.ac @@ -196,6 +196,34 @@ AS_CASE([$enable_recvmmsg], AS_IF([test "$enable_recvmmsg" = yes],[ AC_DEFINE([ENABLE_RECVMMSG], [1], [Use recvmmsg().])]) +AC_ARG_ENABLE([xdp], + AS_HELP_STRING([--enable-xdp=auto|yes|no], [enable eXpress Data Path, requires libBPF [default=auto]]), + [], [enable_xdp=auto]) + +AS_CASE([$enable_xdp], + [auto],[PKG_CHECK_MODULES([libbpf],[libbpf >= 0.0.2],[enable_xdp=yes],[enable_xdp=no])], + [yes],[PKG_CHECK_MODULES([libbpf],[libbpf >= 0.0.2],[enable_xdp=yes])], + [no],[], + [*],[AC_MSG_ERROR([Invalid value of --enable-xdp.])] +) + +AS_IF([test "$enable_xdp" = "yes"],[ + save_CFLAGS=$CFLAGS + save_LIBS=$LIBS + CFLAGS="$CFLAGS $libbpf_CFLAGS" + LIBS="$LIBS $libbpf_LIBS" + + AC_CHECK_FUNC([bpf_prog_load],[],[AC_MSG_ERROR([bpf_prog_load not available])]) + AC_CHECK_FUNC([bpf_set_link_xdp_fd],[],[AC_MSG_ERROR([bpf_set_link_xdp_fd not available])]) + + CFLAGS=$save_CFLAGS + LIBS=$save_LIBS + + AC_DEFINE([ENABLE_XDP], [1], [Use eXpress Data Path.]) +]) + +AM_CONDITIONAL([ENABLE_XDP], [test "$enable_xdp" = "yes"]) + # Reuseport support AS_CASE([$host_os], [freebsd*], [reuseport_opt=SO_REUSEPORT_LB], @@ -713,6 +741,7 @@ result_msg_base=" Knot DNS $VERSION Use recvmmsg: ${enable_recvmmsg} Use SO_REUSEPORT(_LB): ${enable_reuseport} + Use XDP: ${enable_xdp} Memory allocator: ${with_memory_allocator} Fast zone parser: ${enable_fastparser} Utilities with IDN: ${with_libidn} diff --git a/src/knot/conf/tools.c b/src/knot/conf/tools.c index 833ccc9959..276987c94e 100644 --- a/src/knot/conf/tools.c +++ b/src/knot/conf/tools.c @@ -312,6 +312,13 @@ int check_server( CHECK_LEGACY_NAME(C_SRV, C_MAX_IPV4_UDP_PAYLOAD, C_UDP_MAX_PAYLOAD_IPV4); CHECK_LEGACY_NAME(C_SRV, C_MAX_IPV6_UDP_PAYLOAD, C_UDP_MAX_PAYLOAD_IPV6); +#ifndef ENABLE_XDP + if (conf_xdp_threads_txn(args->extra->conf, args->extra->txn) > 0) { + args->err_str = "not compiled with XDP support"; + return KNOT_EINVAL; + } +#endif + return KNOT_EOK; } diff --git a/src/knot/server/server.c b/src/knot/server/server.c index 3c2b66a448..a039c6f87f 100644 --- a/src/knot/server/server.c +++ b/src/knot/server/server.c @@ -22,7 +22,9 @@ #include #include "libknot/errcode.h" +#ifdef ENABLE_XDP #include "libknot/xdp/af_xdp.h" +#endif #include "libknot/yparser/ypschema.h" #include "knot/common/log.h" #include "knot/common/stats.h" @@ -65,7 +67,9 @@ static void server_deinit_iface(iface_t *iface) } if (iface->fd_xdp > -1) { +#ifdef ENABLE_XDP knot_xsk_deinit(); +#endif } /* Free TCP handler. */ @@ -294,12 +298,16 @@ static iface_t *server_init_iface(struct sockaddr_storage *addr, new_if->fd_xdp = -1; if (use_xdp) { - int ret = knot_xsk_init("enp0s8", "/bpf-kernel.o", NULL); // FIXME +#ifndef ENABLE_XDP + assert(0); +#else + int ret = knot_xsk_init("enp1s0f1", "/bpf-kernel.o", NULL); // FIXME if (ret != KNOT_EOK) { log_warning("failed to init XDP (%s)", knot_strerror(ret)); } else { new_if->fd_xdp = knot_xsk_get_poll_fd(); } +#endif } diff --git a/src/knot/server/udp-handler.c b/src/knot/server/udp-handler.c index a0a205ce2f..d83f480fd8 100644 --- a/src/knot/server/udp-handler.c +++ b/src/knot/server/udp-handler.c @@ -38,8 +38,9 @@ #include "knot/query/layer.h" #include "knot/server/server.h" #include "knot/server/udp-handler.h" - +#ifdef ENABLE_XDP #include "libknot/xdp/af_xdp.h" +#endif /* ENABLE_XDP */ /* Buffer identifiers. */ enum { @@ -358,6 +359,8 @@ static udp_api_t udp_recvmmsg_api = { }; #endif /* ENABLE_RECVMMSG */ +#ifdef ENABLE_XDP + struct xdp_recvmmsg { knot_xsk_msg_t msgs_rx[XDP_BATCHLEN]; knot_xsk_msg_t msgs_tx[XDP_BATCHLEN]; @@ -444,6 +447,7 @@ static udp_api_t xdp_recvmmsg_api = { xdp_recvmmsg_handle, xdp_recvmmsg_send }; +#endif /* ENABLE_XDP */ /*! \brief Get interface UDP descriptor for a given thread. */ static int iface_udp_fd(const iface_t *iface, int thread_id, bool use_xdp) @@ -515,7 +519,11 @@ int udp_master(dthread_t *thread) iohandler_t *handler = (iohandler_t *)thread->data; udp_api_t *api = NULL; if (handler->use_xdp) { +#ifndef ENABLE_XDP + assert(0); +#else api = &xdp_recvmmsg_api; +#endif } else { #ifdef ENABLE_RECVMMSG api = &udp_recvmmsg_api; diff --git a/src/libknot/Makefile.inc b/src/libknot/Makefile.inc index 8fe9cf4280..827ed92b17 100644 --- a/src/libknot/Makefile.inc +++ b/src/libknot/Makefile.inc @@ -1,9 +1,9 @@ lib_LTLIBRARIES += libknot.la pkgconfig_DATA += libknot.pc -libknot_la_CPPFLAGS = $(AM_CPPFLAGS) $(CFLAG_VISIBILITY) $(lmdb_CFLAGS) +libknot_la_CPPFLAGS = $(AM_CPPFLAGS) $(CFLAG_VISIBILITY) $(lmdb_CFLAGS) $(libbpf_CFLAGS) libknot_la_LDFLAGS = $(AM_LDFLAGS) $(libknot_VERSION_INFO) $(LDFLAG_EXCLUDE_LIBS) -libknot_la_LIBADD = libcontrib.la libdnssec.la $(math_LIBS) $(lmdb_LIBS) +libknot_la_LIBADD = libcontrib.la libdnssec.la $(math_LIBS) $(lmdb_LIBS) $(libbpf_LIBS) include_libknotdir = $(includedir) nobase_include_libknot_HEADERS = \ @@ -72,11 +72,15 @@ libknot_la_SOURCES = \ libknot/rrtype/tsig.c \ libknot/tsig-op.c \ libknot/tsig.c \ - libknot/xdp/af_xdp.c \ - libknot/xdp/bpf-kernel.c \ - libknot/xdp/bpf-user.c \ libknot/yparser/yparser.c \ libknot/yparser/ypbody.c \ libknot/yparser/ypformat.c \ libknot/yparser/ypschema.c \ libknot/yparser/yptrafo.c + +if ENABLE_XDP +libknot_la_SOURCES += \ + libknot/xdp/af_xdp.c \ + libknot/xdp/bpf-kernel.c \ + libknot/xdp/bpf-user.c +endif ENABLE_XDP diff --git a/src/utils/Makefile.inc b/src/utils/Makefile.inc index e6765d91df..8c1424ddca 100644 --- a/src/utils/Makefile.inc +++ b/src/utils/Makefile.inc @@ -66,7 +66,7 @@ kdig_LDADD = libknotus.la khost_CPPFLAGS = $(AM_CPPFLAGS) $(gnutls_CFLAGS) khost_LDADD = libknotus.la knsec3hash_CPPFLAGS = $(AM_CPPFLAGS) -knsec3hash_LDADD = libcontrib.la libdnssec.la libknot.la +knsec3hash_LDADD = libcontrib.la libdnssec.la libknot.la $(libbpf_LIBS) knsupdate_CPPFLAGS = $(AM_CPPFLAGS) $(gnutls_CFLAGS) knsupdate_LDADD = libknotus.la libzscanner.la diff --git a/tests/knot/test_confio.c b/tests/knot/test_confio.c index 8e2c06c0ab..aec2ae12f5 100644 --- a/tests/knot/test_confio.c +++ b/tests/knot/test_confio.c @@ -909,6 +909,7 @@ static void test_conf_io_list(void) "server.tcp-max-clients\n" "server.tcp-reuseport\n" "server.udp-workers\n" + "server.xdp-workers\n" "server.tcp-workers\n" "server.background-workers\n" "server.udp-max-payload\n"