diff mbox series

[v1,7/11] linux-gen: packet: inline conversions between packet and event

Message ID 1517328009-16379-8-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [v1,1/11] linux-gen: packet: use inlined flow hash set | expand

Commit Message

Github ODP bot Jan. 30, 2018, 4 p.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Inline implementation of packet_from_event and packet_to_event
functions.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 437 (psavol:master-packet-optim)
 ** https://github.com/Linaro/odp/pull/437
 ** Patch: https://github.com/Linaro/odp/pull/437.patch
 ** Base sha: b95ccd3db6eeb7358a877541747e06354429acdd
 ** Merge commit sha: ab7875c186fe80cfe103c5be5634b0eda312aed4
 **/
 include/odp/api/abi-default/buffer.h               |  2 +-
 include/odp/api/abi-default/event.h                |  2 +-
 include/odp/api/abi-default/packet.h               |  2 +-
 .../linux-generic/include-abi/odp/api/abi/buffer.h |  2 +-
 .../linux-generic/include-abi/odp/api/abi/event.h  |  2 +-
 .../include/odp/api/plat/packet_inlines.h          | 29 ++++++++++++
 .../include/odp/api/plat/packet_inlines_api.h      | 21 +++++++++
 platform/linux-generic/odp_packet.c                | 51 ++++------------------
 8 files changed, 63 insertions(+), 48 deletions(-)
diff mbox series

Patch

diff --git a/include/odp/api/abi-default/buffer.h b/include/odp/api/abi-default/buffer.h
index d8bfc9131..980528ba7 100644
--- a/include/odp/api/abi-default/buffer.h
+++ b/include/odp/api/abi-default/buffer.h
@@ -20,7 +20,7 @@  typedef struct { char dummy; /**< @internal Dummy */ } _odp_abi_buffer_t;
 
 typedef _odp_abi_buffer_t *odp_buffer_t;
 
-#define ODP_BUFFER_INVALID   ((odp_buffer_t)NULL)
+#define ODP_BUFFER_INVALID   ((odp_buffer_t)0)
 
 /**
  * @}
diff --git a/include/odp/api/abi-default/event.h b/include/odp/api/abi-default/event.h
index b52a1a222..0ed6dd094 100644
--- a/include/odp/api/abi-default/event.h
+++ b/include/odp/api/abi-default/event.h
@@ -22,7 +22,7 @@  typedef struct { char dummy; /**< @internal Dummy */ } _odp_abi_event_t;
 
 typedef _odp_abi_event_t *odp_event_t;
 
-#define ODP_EVENT_INVALID  ((odp_event_t)NULL)
+#define ODP_EVENT_INVALID  ((odp_event_t)0)
 
 typedef enum odp_event_type_t {
 	ODP_EVENT_BUFFER       = 1,
diff --git a/include/odp/api/abi-default/packet.h b/include/odp/api/abi-default/packet.h
index 15cf081bf..086c4d3bd 100644
--- a/include/odp/api/abi-default/packet.h
+++ b/include/odp/api/abi-default/packet.h
@@ -26,7 +26,7 @@  typedef struct { char dummy; /**< *internal Dummy */ } _odp_abi_packet_seg_t;
 typedef _odp_abi_packet_t *odp_packet_t;
 typedef _odp_abi_packet_seg_t *odp_packet_seg_t;
 
-#define ODP_PACKET_INVALID        ((odp_packet_t)0xffffffff)
+#define ODP_PACKET_INVALID        ((odp_packet_t)0)
 #define ODP_PACKET_SEG_INVALID    ((odp_packet_seg_t)0xffffffff)
 #define ODP_PACKET_OFFSET_INVALID 0xffff
 
diff --git a/platform/linux-generic/include-abi/odp/api/abi/buffer.h b/platform/linux-generic/include-abi/odp/api/abi/buffer.h
index 90b6653a6..879c88afa 100644
--- a/platform/linux-generic/include-abi/odp/api/abi/buffer.h
+++ b/platform/linux-generic/include-abi/odp/api/abi/buffer.h
@@ -26,7 +26,7 @@  extern "C" {
 
 typedef ODP_HANDLE_T(odp_buffer_t);
 
-#define ODP_BUFFER_INVALID _odp_cast_scalar(odp_buffer_t, NULL)
+#define ODP_BUFFER_INVALID _odp_cast_scalar(odp_buffer_t, 0)
 
 /**
  * @}
diff --git a/platform/linux-generic/include-abi/odp/api/abi/event.h b/platform/linux-generic/include-abi/odp/api/abi/event.h
index 802e431f3..49dde956c 100644
--- a/platform/linux-generic/include-abi/odp/api/abi/event.h
+++ b/platform/linux-generic/include-abi/odp/api/abi/event.h
@@ -26,7 +26,7 @@  extern "C" {
 
 typedef ODP_HANDLE_T(odp_event_t);
 
-#define ODP_EVENT_INVALID _odp_cast_scalar(odp_event_t, NULL)
+#define ODP_EVENT_INVALID _odp_cast_scalar(odp_event_t, 0)
 
 typedef enum odp_event_type_t {
 	ODP_EVENT_BUFFER       = 1,
diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines.h b/platform/linux-generic/include/odp/api/plat/packet_inlines.h
index 4c0f88aa2..dc7d464f2 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h
@@ -263,6 +263,35 @@  static inline int _odp_packet_copy_to_mem(odp_packet_t pkt, uint32_t offset,
 	return 0;
 }
 
+static inline odp_packet_t _odp_packet_from_event(odp_event_t ev)
+{
+	return (odp_packet_t)ev;
+}
+
+static inline odp_event_t _odp_packet_to_event(odp_packet_t pkt)
+{
+	return (odp_event_t)pkt;
+}
+
+static inline void _odp_packet_from_event_multi(odp_packet_t pkt[],
+						const odp_event_t ev[],
+						int num)
+{
+	int i;
+
+	for (i = 0; i < num; i++)
+		pkt[i] = _odp_packet_from_event(ev[i]);
+}
+
+static inline void _odp_packet_to_event_multi(const odp_packet_t pkt[],
+					      odp_event_t ev[], int num)
+{
+	int i;
+
+	for (i = 0; i < num; i++)
+		ev[i] = _odp_packet_to_event(pkt[i]);
+}
+
 /** @endcond */
 
 #endif
diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h b/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h
index 9b31c923f..95adec66f 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h
@@ -152,4 +152,25 @@  _ODP_INLINE int odp_packet_copy_to_mem(odp_packet_t pkt, uint32_t offset,
 	return _odp_packet_copy_to_mem(pkt, offset, len, dst);
 }
 
+_ODP_INLINE odp_packet_t odp_packet_from_event(odp_event_t ev)
+{
+	return _odp_packet_from_event(ev);
+}
+
+_ODP_INLINE odp_event_t odp_packet_to_event(odp_packet_t pkt)
+{
+	return _odp_packet_to_event(pkt);
+}
+
+_ODP_INLINE void odp_packet_from_event_multi(odp_packet_t pkt[],
+					     const odp_event_t ev[], int num)
+{
+	return _odp_packet_from_event_multi(pkt, ev, num);
+}
+
+_ODP_INLINE void odp_packet_to_event_multi(const odp_packet_t pkt[],
+					   odp_event_t ev[], int num)
+{
+	return _odp_packet_to_event_multi(pkt, ev, num);
+}
 #endif
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 043e4cb5c..488dcbddf 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -49,15 +49,14 @@  const _odp_packet_inline_offset_t ODP_ALIGNED_CACHE _odp_packet_inline = {
 
 #include <odp/visibility_end.h>
 
-static inline odp_buffer_t buffer_handle(odp_packet_hdr_t *pkt_hdr)
-{
-	return (odp_buffer_t)pkt_hdr;
-}
-
-static inline odp_packet_hdr_t *buf_to_packet_hdr(odp_buffer_t buf)
-{
-	return (odp_packet_hdr_t *)buf_hdl_to_hdr(buf);
-}
+/* Check that invalid values are the same. Some versions of Clang have trouble
+ * with the strong type casting, and complain that these invalid values are not
+ * integral constants. */
+#ifndef __clang__
+ODP_STATIC_ASSERT(ODP_PACKET_INVALID == 0, "Packet invalid not 0");
+ODP_STATIC_ASSERT(ODP_BUFFER_INVALID == 0, "Buffer invalid not 0");
+ODP_STATIC_ASSERT(ODP_EVENT_INVALID  == 0, "Event invalid not 0");
+#endif
 
 odp_packet_t _odp_packet_from_buf_hdr(odp_buffer_hdr_t *buf_hdr)
 {
@@ -998,40 +997,6 @@  int odp_packet_reset(odp_packet_t pkt, uint32_t len)
 	return 0;
 }
 
-odp_packet_t odp_packet_from_event(odp_event_t ev)
-{
-	if (odp_unlikely(ev == ODP_EVENT_INVALID))
-		return ODP_PACKET_INVALID;
-
-	return (odp_packet_t)buf_to_packet_hdr((odp_buffer_t)ev);
-}
-
-odp_event_t odp_packet_to_event(odp_packet_t pkt)
-{
-	if (odp_unlikely(pkt == ODP_PACKET_INVALID))
-		return ODP_EVENT_INVALID;
-
-	return (odp_event_t)buffer_handle(packet_hdr(pkt));
-}
-
-void odp_packet_from_event_multi(odp_packet_t pkt[], const odp_event_t ev[],
-				 int num)
-{
-	int i;
-
-	for (i = 0; i < num; i++)
-		pkt[i] = odp_packet_from_event(ev[i]);
-}
-
-void odp_packet_to_event_multi(const odp_packet_t pkt[], odp_event_t ev[],
-			       int num)
-{
-	int i;
-
-	for (i = 0; i < num; i++)
-		ev[i] = odp_packet_to_event(pkt[i]);
-}
-
 int odp_event_filter_packet(const odp_event_t event[],
 			    odp_packet_t packet[],
 			    odp_event_t remain[], int num)