diff mbox series

[v3,3/10] linux-generic: packet: add routines for manipulating reference counts

Message ID 1500573607-18783-4-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [v3,1/10] linux-generic: packet: restructure inline routines to use macros | expand

Commit Message

Github ODP bot July 20, 2017, 6 p.m. UTC
From: Bill Fischofer <bill.fischofer@linaro.org>


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

---
/** Email created from pull request 82 (Bill-Fischofer-Linaro:pktrefs)
 ** https://github.com/Linaro/odp/pull/82
 ** Patch: https://github.com/Linaro/odp/pull/82.patch
 ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec
 ** Merge commit sha: 01d093d362af5a52e079c622a99ae3495f68b64c
 **/
 platform/linux-generic/include/odp_packet_internal.h | 19 +++++++++++++++++++
 platform/linux-generic/odp_packet.c                  | 10 ++++++++++
 2 files changed, 29 insertions(+)
diff mbox series

Patch

diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index 9c013d8f..396d8cb5 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -248,6 +248,25 @@  static inline uint32_t packet_len(odp_packet_hdr_t *pkt_hdr)
 	return pkt_hdr->frame_len;
 }
 
+static inline uint32_t packet_ref_count(odp_packet_hdr_t *pkt_hdr)
+{
+	/* Breach the atomic type to do a peek at the ref count. This
+	 * is used to bypass atomic operations if ref_count == 1 for
+	 * performance reasons.
+	 */
+	return pkt_hdr->ref_count.v;
+}
+
+static inline void packet_ref_count_set(odp_packet_hdr_t *pkt_hdr, uint32_t 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)
 {
 	pkt_hdr->frame_len = len;
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index af8c442e..38879a7f 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -61,6 +61,16 @@  static inline odp_buffer_t buffer_handle(odp_packet_hdr_t *pkt_hdr)
 	return (odp_buffer_t)pkt_hdr;
 }
 
+static inline uint32_t packet_ref_inc(odp_packet_hdr_t *pkt_hdr)
+{
+	return odp_atomic_fetch_inc_u32(&pkt_hdr->ref_count);
+}
+
+static inline uint32_t packet_ref_dec(odp_packet_hdr_t *pkt_hdr)
+{
+	return odp_atomic_fetch_dec_u32(&pkt_hdr->ref_count);
+}
+
 static inline odp_packet_hdr_t *buf_to_packet_hdr(odp_buffer_t buf)
 {
 	return (odp_packet_hdr_t *)buf_hdl_to_hdr(buf);