aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoltan Kiss <zoltan.kiss@linaro.org>2015-02-26 18:25:29 +0000
committerVenkatesh Vivekanandan <venkatesh.vivekanandan@linaro.org>2015-02-27 14:48:17 +0530
commit0c9164ee5fa8bb52943e766378e708f870c476ea (patch)
tree76f0f3fe4875e06c5dfeea02f4a960469caed7e9
parent6b100a64246c8519e5b0af44047bd344e286c1d9 (diff)
api: Make odp_packet_len inline
This function is in some very hot paths, often called for every packet. Simply the overhead of the function call could be quite big, inlineing can provide up to 10% performance gain. Unfortunately we can't show in the API the internals, so at compile time we calculate the offset for the packet length. Signed-off-by: Zoltan Kiss <zoltan.kiss@linaro.org>
-rw-r--r--platform/linux-dpdk/Makefile.am1
-rw-r--r--platform/linux-dpdk/include/api/odp_packet.h12
-rw-r--r--platform/linux-dpdk/include/api/odp_packet_inlines.h39
-rw-r--r--platform/linux-dpdk/odp_packet.c7
4 files changed, 48 insertions, 11 deletions
diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am
index dab7cc43e..1a74d2f77 100644
--- a/platform/linux-dpdk/Makefile.am
+++ b/platform/linux-dpdk/Makefile.am
@@ -39,6 +39,7 @@ include_HEADERS = \
$(top_srcdir)/platform/linux-generic/include/api/odp_init.h \
$(top_srcdir)/platform/linux-generic/include/api/odp_packet_flags.h \
$(srcdir)/include/api/odp_packet.h \
+ $(srcdir)/include/api/odp_packet_inlines.h \
$(top_srcdir)/platform/linux-generic/include/api/odp_packet_io.h \
$(top_srcdir)/platform/linux-generic/include/api/odp_queue.h \
$(top_srcdir)/platform/linux-generic/include/api/odp_rwlock.h \
diff --git a/platform/linux-dpdk/include/api/odp_packet.h b/platform/linux-dpdk/include/api/odp_packet.h
index 8a1d9175c..5d4b7f7d3 100644
--- a/platform/linux-dpdk/include/api/odp_packet.h
+++ b/platform/linux-dpdk/include/api/odp_packet.h
@@ -20,6 +20,7 @@ extern "C" {
#include <odp_buffer.h>
#include <odp_platform_types.h>
+#include <odp_packet_inlines.h>
/** @defgroup odp_packet ODP PACKET
* Operations on a packet.
@@ -182,17 +183,6 @@ void *odp_packet_data(odp_packet_t pkt);
uint32_t odp_packet_seg_len(odp_packet_t pkt);
/**
- * Packet data length
- *
- * Returns sum of data lengths over all packet segments.
- *
- * @param pkt Packet handle
- *
- * @return Packet data length
- */
-uint32_t odp_packet_len(odp_packet_t pkt);
-
-/**
* Packet headroom length
*
* Returns the current packet level headroom length.
diff --git a/platform/linux-dpdk/include/api/odp_packet_inlines.h b/platform/linux-dpdk/include/api/odp_packet_inlines.h
new file mode 100644
index 000000000..26c08e82f
--- /dev/null
+++ b/platform/linux-dpdk/include/api/odp_packet_inlines.h
@@ -0,0 +1,39 @@
+/*
+ * odp_packet_inlines.h
+ *
+ * Created on: 2 Feb 2015
+ * Author: kz
+ */
+
+#ifndef ODP_PACKET_INLINES_H_
+#define ODP_PACKET_INLINES_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* This is the offset for packet length inside odp_packet_t. It is defined in
+ * odp_packet.c
+ */
+extern const unsigned int pkt_len_offset;
+
+/**
+ * Packet data length
+ *
+ * Returns sum of data lengths over all packet segments.
+ *
+ * @param pkt Packet handle
+ *
+ * @return Packet data length
+ */
+static inline uint32_t odp_packet_len(odp_packet_t pkt)
+{
+ uint32_t accessor = (uint32_t)(((char *)pkt)[pkt_len_offset]);
+ return accessor;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ODP_PACKET_INLINES_H_ */
diff --git a/platform/linux-dpdk/odp_packet.c b/platform/linux-dpdk/odp_packet.c
index f55a698ac..f9168808f 100644
--- a/platform/linux-dpdk/odp_packet.c
+++ b/platform/linux-dpdk/odp_packet.c
@@ -15,6 +15,13 @@
#include <string.h>
#include <stdio.h>
+#include <stddef.h>
+
+/* This is the offset for packet length inside odp_packet_t. */
+const unsigned int pkt_len_offset = offsetof(odp_packet_hdr_t, buf_hdr) +
+ offsetof(struct odp_buffer_hdr_t, mb) +
+ offsetof(struct rte_mbuf, pkt) +
+ offsetof(struct rte_pktmbuf, pkt_len);
static inline uint8_t parse_ipv4(odp_packet_hdr_t *pkt_hdr,
odph_ipv4hdr_t *ipv4, size_t *offset_out);