aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Fischofer <bill.fischofer@linaro.org>2017-03-04 17:39:16 +0100
committerMaxim Uvarov <maxim.uvarov@linaro.org>2017-08-02 17:50:43 +0300
commit8745330b32579ab66354f9d2043154f8ef326290 (patch)
treeb0702707901fbe0a6cf3b446057530da03eb9ece
parente0738b61c3257145c50d4751bcf4e20b5fc5f0ec (diff)
linux-generic: packet: add routines for manipulating reference counts
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org> Reviewed-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org> Reviewed-and-tested-by: Yi He <yi.he@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
-rw-r--r--platform/linux-generic/include/odp_packet_internal.h19
-rw-r--r--platform/linux-generic/odp_packet.c10
2 files changed, 29 insertions, 0 deletions
diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index 0542dd108..8c83966c5 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -254,6 +254,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 af8c442e7..988045e40 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 void packet_ref_inc(odp_packet_hdr_t *pkt_hdr)
+{
+ odp_atomic_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);