diff mbox series

[API-NEXT,v1,7/14] linux-gen: add support for using system-wide DPDK

Message ID 1513008012-9231-8-git-send-email-odpbot@yandex.ru
State New
Headers show
Series None | expand

Commit Message

Github ODP bot Dec. 11, 2017, 4 p.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Support using distro-installed DPDK for Pkt I/O. Distributions (like
Ubuntu, Debian, etc) start providing DPDK packages. It is wise to enable
users to use distro-provided DPDK version rather than requiring to
always compile it from sources.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

Reviewed-and-tested-by: Matias Elo <matias.elo@nokia.com>
---
/** Email created from pull request 335 (muvarov:devel/api-next_master_merge)
 ** https://github.com/Linaro/odp/pull/335
 ** Patch: https://github.com/Linaro/odp/pull/335.patch
 ** Base sha: 630d8422564ebf4991b468cb38a29e9483fc2ec2
 ** Merge commit sha: 2de2af9eca01b713e51c66fee7a5c7e535502f85
 **/
 m4/odp_dpdk.m4                        | 43 ++++++++++++++++++++++++++++-------
 platform/linux-generic/m4/odp_dpdk.m4 | 28 +++++++++++++++++++----
 2 files changed, 58 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/m4/odp_dpdk.m4 b/m4/odp_dpdk.m4
index 636170a7f..05e60cc06 100644
--- a/m4/odp_dpdk.m4
+++ b/m4/odp_dpdk.m4
@@ -16,6 +16,31 @@  AS_VAR_APPEND([DPDK_PMDS], [--no-whole-archive])
 AC_SUBST([DPDK_PMDS])
 ])
 
+# _ODP_DPDK_CHECK_LIB(LDFLAGS, [LIBS], [EXTRA_LIBS])
+# ----------------------------------
+# Check if one can use -ldpdk with provided set of libs
+AC_DEFUN([_ODP_DPDK_CHECK_LIB], [dnl
+##########################################################################
+# Save and set temporary compilation flags
+##########################################################################
+OLD_LDFLAGS=$LDFLAGS
+OLD_LIBS=$LIBS
+LDFLAGS="$1 $LDFLAGS"
+LIBS="$LIBS -ldpdk $2"
+
+AC_MSG_CHECKING([for rte_eal_init in -ldpdk $2])
+AC_LINK_IFELSE([AC_LANG_CALL([], [rte_eal_init])],
+	       [AC_MSG_RESULT([yes])
+	        DPDK_LIBS="$1 -ldpdk $3 $2"],
+	       [AC_MSG_RESULT([no])])
+
+##########################################################################
+# Restore old saved variables
+##########################################################################
+LDFLAGS=$OLD_LDFLAGS
+LIBS=$OLD_LIBS
+])
+
 # ODP_DPDK_CHECK(CPPFLAGS, LDFLAGS, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
 # -----------------------------------------------------------------------
 # Check for DPDK availability
@@ -23,10 +48,7 @@  AC_DEFUN([ODP_DPDK_CHECK], [dnl
 ##########################################################################
 # Save and set temporary compilation flags
 ##########################################################################
-OLD_LDFLAGS=$LDFLAGS
-OLD_LIBS=$LIBS
 OLD_CPPFLAGS=$CPPFLAGS
-LDFLAGS="$2 $LDFLAGS"
 CPPFLAGS="$1 $CPPFLAGS"
 
 dpdk_check_ok=yes
@@ -34,16 +56,21 @@  dpdk_check_ok=yes
 AC_CHECK_HEADERS([rte_config.h], [],
 		 [dpdk_check_ok=no])
 
-AC_CHECK_LIB([dpdk], [rte_eal_init], [],
-	     [dpdk_check_ok=no], [-ldl -lpthread -lnuma])
+DPDK_LIBS=""
+_ODP_DPDK_CHECK_LIB([$2])
+AS_IF([test "x$DPDK_LIBS" = "x"],
+      [_ODP_DPDK_CHECK_LIB([$2], [-ldl -lpthread], [-lm])])
+AS_IF([test "x$DPDK_LIBS" = "x"],
+      [_ODP_DPDK_CHECK_LIB([$2], [-ldl -lpthread -lnuma], [-lm])])
+AS_IF([test "x$DPDK_LIBS" = "x"],
+      [dpdk_check_ok=no])
 AS_IF([test "x$dpdk_check_ok" != "xno"],
-      [m4_default([$3], [:])],
+      [AC_SUBST([DPDK_LIBS])
+       m4_default([$3], [:])],
       [m4_default([$4], [:])])
 
 ##########################################################################
 # Restore old saved variables
 ##########################################################################
-LDFLAGS=$OLD_LDFLAGS
-LIBS=$OLD_LIBS
 CPPFLAGS=$OLD_CPPFLAGS
 ])
diff --git a/platform/linux-generic/m4/odp_dpdk.m4 b/platform/linux-generic/m4/odp_dpdk.m4
index 91f76e2de..471bbcd51 100644
--- a/platform/linux-generic/m4/odp_dpdk.m4
+++ b/platform/linux-generic/m4/odp_dpdk.m4
@@ -2,12 +2,27 @@ 
 # Enable DPDK support
 ##########################################################################
 pktio_dpdk_support=no
+
+AC_ARG_ENABLE([dpdk],
+	      [AS_HELP_STRING([--enable-dpdk], [enable DPDK support for Packet I/O])],
+	      [pktio_dpdk_support=$enableval
+	       DPDK_PATH=system])
+
 AC_ARG_WITH([dpdk-path],
 [AS_HELP_STRING([--with-dpdk-path=DIR], [path to dpdk build directory])],
     [DPDK_PATH="$withval"
-    DPDK_CPPFLAGS="-isystem $DPDK_PATH/include"
-    DPDK_LDFLAGS="-L$DPDK_PATH/lib"
-    pktio_dpdk_support=yes],[])
+     pktio_dpdk_support=yes],[])
+
+AS_IF([test "x$DPDK_PATH" = "xsystem"],
+      [DPDK_CPPFLAGS="-isystem/usr/include/dpdk"
+       DPDK_LDFLAGS=""
+       DPDK_PMD_PATH="`$CC --print-file-name=librte_pmd_null.a`"
+       DPDK_PMD_PATH="`dirname "$DPDK_PMD_PATH"`"
+       AS_IF([test "x$DPDK_PMD_PATH" = "x"],
+	     [AC_MSG_FAILURE([Could not locate system DPDK PMD directory])])],
+      [DPDK_CPPFLAGS="-isystem $DPDK_PATH/include"
+       DPDK_LDFLAGS="-L$DPDK_PATH/lib"
+       DPDK_PMD_PATH="$DPDK_PATH/lib"])
 
 ##########################################################################
 # Enable zero-copy DPDK pktio
@@ -30,14 +45,17 @@  then
     ODP_DPDK_CHECK([$DPDK_CPPFLAGS], [$DPDK_LDFLAGS], [],
                    [AC_MSG_FAILURE([can't find DPDK])])
 
-    ODP_DPDK_PMDS([$DPDK_PATH/lib])
+    ODP_DPDK_PMDS([$DPDK_PMD_PATH])
 
     AC_DEFINE([ODP_PKTIO_DPDK], [1],
 	      [Define to 1 to enable DPDK packet I/O support])
     AC_DEFINE_UNQUOTED([ODP_DPDK_ZERO_COPY], [$zero_copy],
 	      [Define to 1 to enable DPDK zero copy support])
 
-    DPDK_LIBS="$DPDK_LDFLAGS -ldpdk -lpthread -ldl -lpcap -lm -lnuma"
+    if test -r "$DPDK_PMD_PATH/librte_pmd_pcap.a" &&
+       ! test -r "$DPDK_PMD_PATH/librte_pmd_pcap.so" ; then
+        DPDK_LIBS="$DPDK_LIBS -lpcap"
+    fi
     AC_SUBST([DPDK_CPPFLAGS])
     AC_SUBST([DPDK_LIBS])
 else