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 <[email protected]> --- 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 <odp/api/packet_inlines.h> +#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 <odp/api/packet_inlines.h> +#endif odp_packet_t _odp_packet_from_buffer(odp_buffer_t buf) { -- 1.9.1 _______________________________________________ lng-odp mailing list [email protected] https://lists.linaro.org/mailman/listinfo/lng-odp
