From patchwork Fri Apr 22 18:11:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zoltan Kiss X-Patchwork-Id: 66493 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp865564qge; Fri, 22 Apr 2016 11:13:38 -0700 (PDT) X-Received: by 10.107.154.18 with SMTP id c18mr27226249ioe.169.1461348817965; Fri, 22 Apr 2016 11:13:37 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 40si6437306iog.112.2016.04.22.11.13.37; Fri, 22 Apr 2016 11:13:37 -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 21CAA68AFE; Fri, 22 Apr 2016 18:13:37 +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 4643C68821; Fri, 22 Apr 2016 18:13:06 +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 EF8F267453; Fri, 22 Apr 2016 18:13:01 +0000 (UTC) Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by lists.linaro.org (Postfix) with ESMTPS id B2ED76511D for ; Fri, 22 Apr 2016 18:12:59 +0000 (UTC) Received: by mail-wm0-f46.google.com with SMTP id v188so30294487wme.1 for ; Fri, 22 Apr 2016 11:12:59 -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=7rZyGBubtse+7yrfYd3lxIdAZi8oQ6bHtcVoZbXnRS4=; b=mtvaPk4fNhlcC23vx4yV2dHvJZRY48bpmNL1Bz7H4HBdfa76/3RHg1/tcj7iI/POlQ 3NjGZ2xcmyjQf6yoifkKkOmKtYNB4Li8bcFK/KjdPQ84Xa8HHuy8eS01GRsLxcp4QMHD v+fMvKrTWbVZ80NsO8mh9teOjXB09TwrnZO5il6zENnAdJi5bYLMn1KkvI+5J4spqHLM tLWlSlsXfJNZpoZKL45J8WOeyI06lj7rxBGcQRAKFOaYiObLUcpOUgDRtlHs18jeAgso pXZxze/QJqt/a/cLjhyqrhinHjuUPQxsX0AyNXlbqzXbmaSweubIlxjdPwhl5l9Ep6IO dYbg== X-Gm-Message-State: AOPr4FX57oMKkXkdCBlVRaiSKWvcyxnmZ442NQsFyqAp8VOuO0zLN5v/NEyFYt+G2JJqDDR30gM= X-Received: by 10.28.148.19 with SMTP id w19mr5230201wmd.10.1461348778610; Fri, 22 Apr 2016 11:12:58 -0700 (PDT) Received: from localhost.localdomain ([195.11.233.227]) by smtp.googlemail.com with ESMTPSA id d79sm4511784wmi.23.2016.04.22.11.12.57 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Apr 2016 11:12:57 -0700 (PDT) From: Zoltan Kiss To: lng-odp-dpdk@lists.linaro.org Date: Fri, 22 Apr 2016 19:11:53 +0100 Message-Id: <1461348713-28411-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: add --enable-inlines configure option 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 a fixed ABI, we need each function to be in the library file. But that hurts performance a bit, as small accessor functions couldn't be inlined. To have the ability to use both, this patch creates a new configure option, which enables the use of inline functions for users who want better performance. 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 --enable-inlines=yes is added to ./configure, they won't be compiled into the .so file, but the application has to add "#define INLINES" before including odp.h Signed-off-by: Zoltan Kiss --- configure.ac | 9 +++ platform/linux-dpdk/Makefile.am | 1 + platform/linux-dpdk/include/odp/api/packet.h | 59 +-------------- .../linux-dpdk/include/odp/api/packet_inlines.h | 86 ++++++++++++++++++++++ platform/linux-dpdk/odp_packet.c | 3 + 5 files changed, 102 insertions(+), 56 deletions(-) create mode 100644 platform/linux-dpdk/include/odp/api/packet_inlines.h diff --git a/configure.ac b/configure.ac index 99772a1..6b8fb76 100644 --- a/configure.ac +++ b/configure.ac @@ -173,6 +173,15 @@ AC_ARG_ENABLE([debug], ODP_CFLAGS="$ODP_CFLAGS -DODP_DEBUG=$ODP_DEBUG" ########################################################################## +# Enable/disable static inlines +########################################################################## +AC_ARG_ENABLE([inlines], + [ --enable-inlines allow inlines], + [if test "x$enableval" = "xyes"; then + ODP_CFLAGS="$ODP_CFLAGS -DINLINES" + fi]) + +########################################################################## # Save and set temporary compilation flags ########################################################################## OLD_LDFLAGS=$LDFLAGS diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index eadaf63..b8cba23 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -49,6 +49,7 @@ odpapiinclude_HEADERS = \ $(srcdir)/include/odp/api/init.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/packet.h b/platform/linux-dpdk/include/odp/api/packet.h index 7c0db32..e2ba78a 100644 --- a/platform/linux-dpdk/include/odp/api/packet.h +++ b/platform/linux-dpdk/include/odp/api/packet.h @@ -27,62 +27,9 @@ 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; -} - +#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..3d3ca81 --- /dev/null +++ b/platform/linux-dpdk/include/odp/api/packet_inlines.h @@ -0,0 +1,86 @@ +/* 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/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) {