[API-NEXT] linux-generic: packet: improve packet init efficiency

Message ID 20170216165216.10951-1-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Feb. 16, 2017, 4:52 p.m.
Atomic operations are relatively expensive because they involve implicit
memory synchronizations and pipeline flushes. During packet_init()
processing we know that there are no other references to this packet,
so avoid this overhead via a controlled breach of the atomic type to
set the initial reference count directly.

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

 platform/linux-generic/include/odp_packet_internal.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)



diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index 2db042e0..593f30dd 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -262,7 +262,12 @@  static inline uint32_t packet_ref_count(odp_packet_hdr_t *pkt_hdr)
 static inline void packet_ref_count_set(odp_packet_hdr_t *pkt_hdr, uint32_t n)
-	odp_atomic_init_u32(&pkt_hdr->ref_count, n);
+	/* Only used during init when there are no other possible
+	 * references to this pkt, so avoid the "atomic" overhead by
+	 * a controlled breach of the atomic type here. This saves
+	 * over 10% of the pathlength in routines like packet_alloc().
+	 */
+	pkt_hdr->ref_count.v = n;
 static inline void packet_set_len(odp_packet_hdr_t *pkt_hdr, uint32_t len)