From patchwork Wed May 25 14:13:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zoltan Kiss X-Patchwork-Id: 68607 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1239650qge; Wed, 25 May 2016 07:14:28 -0700 (PDT) X-Received: by 10.200.50.162 with SMTP id z31mr3630371qta.7.1464185668488; Wed, 25 May 2016 07:14:28 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id i9si8108575qti.111.2016.05.25.07.14.28; Wed, 25 May 2016 07:14:28 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 1AEA5617DE; Wed, 25 May 2016 14:14:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id C6445616C2; Wed, 25 May 2016 14:13:54 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id D130E6160E; Wed, 25 May 2016 14:13:50 +0000 (UTC) Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by lists.linaro.org (Postfix) with ESMTPS id B40B961605 for ; Wed, 25 May 2016 14:13:47 +0000 (UTC) Received: by mail-wm0-f45.google.com with SMTP id n129so64669505wmn.1 for ; Wed, 25 May 2016 07:13:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=NXvNTFDyoDoSDQDfnwxOjkoouzcMYnFWWNSwrYXx2QY=; b=htsh2FFznbmdMXVEWZgIY8tOQeVO7UgiYfVrA0ayo0jkG7PPWdLMs2MZAr26C29RAd wnSS1y/9N1f7sIhhFn7iqo952kCsLigfiDCYoUNBadd+ePouyG9ss4uQ9PJW/ctew+i/ 5iHn6kSNxUXmD9/SXFlw8+e86XjIeHR9feoTc7dJ8XdMr0m8s119+Q7P8vmo2Byv2ll+ 7g8zz7Wg9U0V20H1+i4GhMLIf08Ykib0/lDFpmLaHY9siGutpN7m4xf1H5Qj0TNFroBL C/8rfb+3lvEXuLisCeGcZXvpqvyBWriB2qEPVuS6d0hWpO1ODj2DxEgtlpwpFGOOB5ge xqPg== X-Gm-Message-State: ALyK8tLzH2gSOn5lSe9rcDYr80CZSQYws4fNGCyyR8+M+aeV/bLO4l0CqFKNrrvKQ+sppIagLJs= X-Received: by 10.28.29.147 with SMTP id d141mr3875744wmd.91.1464185626624; Wed, 25 May 2016 07:13:46 -0700 (PDT) Received: from localhost.localdomain ([195.11.233.227]) by smtp.googlemail.com with ESMTPSA id c185sm24588209wme.9.2016.05.25.07.13.45 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 May 2016 07:13:45 -0700 (PDT) From: Zoltan Kiss To: lng-odp-dpdk@lists.linaro.org Date: Wed, 25 May 2016 15:13:05 +0100 Message-Id: <1464185585-24454-1-git-send-email-zoltan.kiss@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Cc: petri.savolainen@nokia.com, lng-odp@lists.linaro.org Subject: [lng-odp] [RFC PATCH] linux-dpdk: Enable inlines if dynamic library is not used X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" In order to have proper packaging and dynamic linking we need a fixed ABI. For that, each function has to be in the library file. But that hurts performance a bit, as small accessor functions couldn't be inlined, despite it's a viable option with static linking. This patch lets the platform automatically decide what should be done. ./configure generates inlines.h based on whether --enable-shared=yes was added or not. If yes, it enables the INLINES macro. The accessors are moved to a packet_inlines.h file, by default it is included from odp_packet.c, and they appear as fully fledged functions. If INLINES defined, the accessors appear as static inline functions in the header, and the application can directly inline them. Signed-off-by: Zoltan Kiss --- .gitignore | 1 + configure.ac | 7 ++ platform/linux-dpdk/Makefile.am | 2 + platform/linux-dpdk/include/odp/api/inlines.h.in | 27 +++++++ platform/linux-dpdk/include/odp/api/packet.h | 60 +-------------- .../linux-dpdk/include/odp/api/packet_inlines.h | 87 ++++++++++++++++++++++ platform/linux-dpdk/m4/configure.m4 | 3 +- platform/linux-dpdk/odp_packet.c | 3 + 8 files changed, 133 insertions(+), 57 deletions(-) create mode 100644 platform/linux-dpdk/include/odp/api/inlines.h.in create mode 100644 platform/linux-dpdk/include/odp/api/packet_inlines.h diff --git a/.gitignore b/.gitignore index 2b1da19..4040e2b 100644 --- a/.gitignore +++ b/.gitignore @@ -40,5 +40,6 @@ ltmain.sh m4/*.m4 missing pkgconfig/libodp*.pc +platform/linux-dpdk/include/odp/api/inlines.h tags test-driver diff --git a/configure.ac b/configure.ac index 99772a1..199a6e2 100644 --- a/configure.ac +++ b/configure.ac @@ -141,6 +141,13 @@ AM_CONDITIONAL([test_helper], [test x$test_helper = xyes ]) AM_CONDITIONAL([HAVE_DOXYGEN], [test "x${DOXYGEN}" = "xdoxygen"]) AM_CONDITIONAL([user_guide], [test "x${user_guides}" = "xyes" ]) AM_CONDITIONAL([HAVE_MSCGEN], [test "x${MSCGEN}" = "xmscgen"]) +if test x$enable_shared != xyes; +then + INLINES="INLINES" +else + INLINES="__NOTHING" +fi +AC_SUBST(INLINES) ########################################################################## # Setup doxygen documentation diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index eadaf63..49ad877 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -47,8 +47,10 @@ odpapiinclude_HEADERS = \ $(srcdir)/include/odp/api/hash.h \ $(srcdir)/include/odp/api/hints.h \ $(srcdir)/include/odp/api/init.h \ + $(srcdir)/include/odp/api/inlines.h \ $(srcdir)/include/odp/api/packet_flags.h \ $(srcdir)/include/odp/api/packet.h \ + $(srcdir)/include/odp/api/packet_inlines.h \ $(srcdir)/include/odp/api/packet_io.h \ $(srcdir)/include/odp/api/pool.h \ $(srcdir)/include/odp/api/queue.h \ diff --git a/platform/linux-dpdk/include/odp/api/inlines.h.in b/platform/linux-dpdk/include/odp/api/inlines.h.in new file mode 100644 index 0000000..1e8bac8 --- /dev/null +++ b/platform/linux-dpdk/include/odp/api/inlines.h.in @@ -0,0 +1,27 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP packet inline functions + */ + +#ifndef ODP_PLAT_INLINES_H_ +#define ODP_PLAT_INLINES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define @INLINES@ + +#ifdef __cplusplus +} +#endif + + +#endif /* ODP_PLAT_INLINES_H_ */ diff --git a/platform/linux-dpdk/include/odp/api/packet.h b/platform/linux-dpdk/include/odp/api/packet.h index 7c0db32..0fb31e3 100644 --- a/platform/linux-dpdk/include/odp/api/packet.h +++ b/platform/linux-dpdk/include/odp/api/packet.h @@ -27,62 +27,10 @@ extern "C" { /** @ingroup odp_packet * @{ */ - -extern const unsigned int buf_addr_offset; -extern const unsigned int data_off_offset; -extern const unsigned int pkt_len_offset; -extern const unsigned int seg_len_offset; -extern const unsigned int udata_len_offset; -extern const unsigned int udata_offset; -extern const unsigned int rss_offset; -extern const unsigned int ol_flags_offset; -extern const uint64_t rss_flag; - -/* - * NOTE: These functions are inlined because they are on a performance hot path. - * As we can't force the application to directly include DPDK headers we have to - * export these fields through constants calculated compile time in - * odp_packet.c, where we can see the DPDK definitions. - * - */ -static inline uint32_t odp_packet_len(odp_packet_t pkt) -{ - return *(uint32_t *)(void *)((char *)pkt + pkt_len_offset); -} - -static inline uint32_t odp_packet_seg_len(odp_packet_t pkt) -{ - return *(uint16_t *)(void *)((char *)pkt + seg_len_offset); -} - -static inline void *odp_packet_user_area(odp_packet_t pkt) -{ - return (void *)((char *)pkt + udata_offset); -} - -static inline uint32_t odp_packet_user_area_size(odp_packet_t pkt) -{ - return *(uint32_t *)(void *)((char *)pkt + udata_len_offset); -} - -static inline void *odp_packet_data(odp_packet_t pkt) -{ - char** buf_addr = (char **)(void *)((char *)pkt + buf_addr_offset); - uint16_t data_off = *(uint16_t *)(void *)((char *)pkt + data_off_offset); - return (void *)(*buf_addr + data_off); -} - -static inline uint32_t odp_packet_flow_hash(odp_packet_t pkt) -{ - return *(uint32_t *)(void *)((char *)pkt + rss_offset); -} - -static inline void odp_packet_flow_hash_set(odp_packet_t pkt, uint32_t flow_hash) -{ - *(uint32_t *)(void *)((char *)pkt + rss_offset) = flow_hash; - *(uint64_t *)(void *)((char *)pkt + ol_flags_offset) |= rss_flag; -} - +#include +#ifdef INLINES +#include +#endif /** * @} */ diff --git a/platform/linux-dpdk/include/odp/api/packet_inlines.h b/platform/linux-dpdk/include/odp/api/packet_inlines.h new file mode 100644 index 0000000..569090b --- /dev/null +++ b/platform/linux-dpdk/include/odp/api/packet_inlines.h @@ -0,0 +1,87 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP packet inline functions + */ + +#ifndef ODP_PLAT_PACKET_INLINES_H_ +#define ODP_PLAT_PACKET_INLINES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef INLINES +#define _STATIC static inline + +extern const unsigned int buf_addr_offset; +extern const unsigned int data_off_offset; +extern const unsigned int pkt_len_offset; +extern const unsigned int seg_len_offset; +extern const unsigned int udata_len_offset; +extern const unsigned int udata_offset; +extern const unsigned int rss_offset; +extern const unsigned int ol_flags_offset; +extern const uint64_t rss_flag; + +#else +#define _STATIC +#endif + +/* + * NOTE: These functions are inlined because they are on a performance hot path. + * As we can't force the application to directly include DPDK headers we have to + * export these fields through constants calculated compile time in + * odp_packet.c, where we can see the DPDK definitions. + * + */ +_STATIC uint32_t odp_packet_len(odp_packet_t pkt) +{ + return *(uint32_t *)(void *)((char *)pkt + pkt_len_offset); +} + +_STATIC uint32_t odp_packet_seg_len(odp_packet_t pkt) +{ + return *(uint16_t *)(void *)((char *)pkt + seg_len_offset); +} + +_STATIC void *odp_packet_user_area(odp_packet_t pkt) +{ + return (void *)((char *)pkt + udata_offset); +} + +_STATIC uint32_t odp_packet_user_area_size(odp_packet_t pkt) +{ + return *(uint32_t *)(void *)((char *)pkt + udata_len_offset); +} + +_STATIC void *odp_packet_data(odp_packet_t pkt) +{ + char **buf_addr = (char **)(void *)((char *)pkt + buf_addr_offset); + uint16_t data_off = *(uint16_t *)(void *)((char *)pkt + data_off_offset); + + return (void *)(*buf_addr + data_off); +} + +_STATIC uint32_t odp_packet_flow_hash(odp_packet_t pkt) +{ + return *(uint32_t *)(void *)((char *)pkt + rss_offset); +} + +_STATIC void odp_packet_flow_hash_set(odp_packet_t pkt, uint32_t flow_hash) +{ + *(uint32_t *)(void *)((char *)pkt + rss_offset) = flow_hash; + *(uint64_t *)(void *)((char *)pkt + ol_flags_offset) |= rss_flag; +} + +#ifdef __cplusplus +} +#endif + +#endif /* ODP_PLAT_PACKET_INLINES_H_ */ diff --git a/platform/linux-dpdk/m4/configure.m4 b/platform/linux-dpdk/m4/configure.m4 index fab0f6a..7c5ccbc 100644 --- a/platform/linux-dpdk/m4/configure.m4 +++ b/platform/linux-dpdk/m4/configure.m4 @@ -47,4 +47,5 @@ m4_include([platform/linux-dpdk/m4/odp_openssl.m4]) AC_CONFIG_FILES([platform/linux-dpdk/Makefile platform/linux-dpdk/test/Makefile - platform/linux-dpdk/test/pktio/Makefile]) + platform/linux-dpdk/test/pktio/Makefile + platform/linux-dpdk/include/odp/api/inlines.h]) diff --git a/platform/linux-dpdk/odp_packet.c b/platform/linux-dpdk/odp_packet.c index e031b09..456ced6 100644 --- a/platform/linux-dpdk/odp_packet.c +++ b/platform/linux-dpdk/odp_packet.c @@ -60,6 +60,9 @@ _ODP_STATIC_ASSERT(sizeof(dummy.hash.rss) == sizeof(uint32_t), _ODP_STATIC_ASSERT(sizeof(dummy.ol_flags) == sizeof(uint64_t), "ol_flags should be uint64_t"); +#ifndef INLINES +#include +#endif odp_packet_t _odp_packet_from_buffer(odp_buffer_t buf) {