diff mbox series

[API-NEXT,v1,5/6] linux-gen: packet: initialize user ptr to NULL

Message ID 1516100408-8246-6-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v1,1/6] linux-gen: packet: single user ptr field | expand

Commit Message

Github ODP bot Jan. 16, 2018, 11 a.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Use a flag to record if user pointer has been set. This
avoids resetting the pointer in every alloc.

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

---
/** Email created from pull request 392 (psavol:next-user-ptr-init-rebase)
 ** https://github.com/Linaro/odp/pull/392
 ** Patch: https://github.com/Linaro/odp/pull/392.patch
 ** Base sha: f6dab2bfa90ef5d3146cb76f86bc8782666f0f3e
 ** Merge commit sha: 7244f46bcf5e4a0fce4048e306f224f31e9a4d2f
 **/
 .../linux-generic/include/odp/api/plat/packet_inlines.h     |  7 +++++++
 platform/linux-generic/include/odp/api/plat/packet_types.h  | 12 +++++++++---
 platform/linux-generic/odp_packet.c                         | 13 +++++++++++--
 3 files changed, 27 insertions(+), 5 deletions(-)
diff mbox series

Patch

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 b00b9c923..64c12377b 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h
@@ -98,6 +98,13 @@  static inline int _odp_packet_num_segs(odp_packet_t pkt)
 /** @internal Inline function @param pkt @return */
 static inline void *_odp_packet_user_ptr(odp_packet_t pkt)
 {
+	_odp_packet_flags_t flags;
+
+	flags.all_flags = _odp_pkt_get(pkt, uint32_t, flags);
+
+	if (flags.user_ptr_set == 0)
+		return NULL;
+
 	return _odp_pkt_get(pkt, void *, user_ptr);
 }
 
diff --git a/platform/linux-generic/include/odp/api/plat/packet_types.h b/platform/linux-generic/include/odp/api/plat/packet_types.h
index 14810e585..6691b04ae 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_types.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_types.h
@@ -91,6 +91,7 @@  typedef struct _odp_packet_inline_offset_t {
 	uint16_t flow_hash;
 	uint16_t timestamp;
 	uint16_t input_flags;
+	uint16_t flags;
 
 } _odp_packet_inline_offset_t;
 
@@ -156,7 +157,12 @@  typedef union {
 	uint32_t all_flags;
 
 	struct {
-		uint32_t reserved1:     12;
+		uint32_t reserved1:     11;
+
+	/*
+	 * Init flags
+	 */
+		uint32_t user_ptr_set:   1; /* User has set a non-NULL value */
 
 	/*
 	 * Packet output flags
@@ -182,8 +188,8 @@  typedef union {
 
 	/* Flag groups */
 	struct {
-		uint32_t reserved2:     12;
-		uint32_t other:         12; /* All other flags */
+		uint32_t reserved2:     11;
+		uint32_t other:         13; /* All other flags */
 		uint32_t error:          8; /* All error flags */
 	} all;
 
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 965a86d54..2f747c6b5 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -42,7 +42,8 @@  const _odp_packet_inline_offset_t _odp_packet_inline ODP_ALIGNED_CACHE = {
 	.l4_offset      = offsetof(odp_packet_hdr_t, p.l4_offset),
 	.flow_hash      = offsetof(odp_packet_hdr_t, flow_hash),
 	.timestamp      = offsetof(odp_packet_hdr_t, timestamp),
-	.input_flags    = offsetof(odp_packet_hdr_t, p.input_flags)
+	.input_flags    = offsetof(odp_packet_hdr_t, p.input_flags),
+	.flags          = offsetof(odp_packet_hdr_t, p.flags)
 
 };
 
@@ -1259,7 +1260,15 @@  int odp_packet_input_index(odp_packet_t pkt)
 
 void odp_packet_user_ptr_set(odp_packet_t pkt, const void *ptr)
 {
-	packet_hdr(pkt)->buf_hdr.user_ptr = ptr;
+	odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
+
+	if (odp_unlikely(ptr == NULL)) {
+		pkt_hdr->p.flags.user_ptr_set = 0;
+		return;
+	}
+
+	pkt_hdr->buf_hdr.user_ptr     = ptr;
+	pkt_hdr->p.flags.user_ptr_set = 1;
 }
 
 int odp_packet_l2_offset_set(odp_packet_t pkt, uint32_t offset)