diff mbox

[API-NEXT,PATCHv4,1/5] api: packet: add support for packet splices and references

Message ID 1476114646-9874-2-git-send-email-bill.fischofer@linaro.org
State Superseded
Headers show

Commit Message

Bill Fischofer Oct. 10, 2016, 3:50 p.m. UTC
Introduce four new APIs that support efficient sharing of portions of
packets.

odp_packet_splice() creates a reference to a base packet by splicing a
supplied header packet onto it at a specified offset. If multiple splices
are created then each shares the base packet that was spliced.

odp_packet_ref() creates a reference to a base packet by splicing a
zero-length header onto it at a specified offset. This allows an
application to "hold onto" a pointer to a packet so that it will not be
freed until all references to it are freed.

odp_packet_is_a_splice() allows an application to determine whether a
packet is a splice and if so how many individual packets are contained
within it.

odp_packet_is_spliced() allows an application to determine whether a packet
has a splice on it and if so how many splices are based on it.

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

---
 include/odp/api/spec/packet.h | 103 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

-- 
2.7.4
diff mbox

Patch

diff --git a/include/odp/api/spec/packet.h b/include/odp/api/spec/packet.h
index 4a14f2d..8e147a3 100644
--- a/include/odp/api/spec/packet.h
+++ b/include/odp/api/spec/packet.h
@@ -844,6 +844,109 @@  int odp_packet_concat(odp_packet_t *dst, odp_packet_t src);
  */
 int odp_packet_split(odp_packet_t *pkt, uint32_t len, odp_packet_t *tail);
 
+/**
+ * Splice a packet
+ *
+ * Create a new packet by splicing a header onto an existing packet. The
+ * spliced packet consists of the header followed by a shared reference to the
+ * base packet receiving the splice starting at a designated offset. If
+ * multiple splices are created on the same base packet, it is the
+ * application's responsibility to coordinate any changes to the shared
+ * segment(s) of the splice, otherwise results are undefined.
+ *
+ * @param hdr    Handle of the header packet to be spliced onto the base packet
+ *
+ * @param pkt    Handle of the base packet that is to receive the splice
+ *
+ * @param offset Byte offset within the base packet at which the splice is
+ *               to be made.
+ *
+ * @return       Handle of the spliced packet. This may or may not be the
+ *               same as the input hdr packet. The caller should use this
+ *               for any future references to the splice. The original hdr
+ *               packet no longer has any independent existence.
+ *
+ * @retval ODP_PACKET_INVALID If the splice failed. In this case both hdr
+ *                            and pkt are unchanged.
+ *
+ * @note The base pkt remains valid after the completion of the splice,
+ *       however changes that affect its length may yield unpredictable
+ *       results when viewed through the returned splice handle. For best
+ *       portability and predictable behavior, applications should regard the
+ *       base packet as read only following a successful splice, with the
+ *       exception of tailroom manipulation (which still requires application
+ *       coordination if multiple splices exist on the same base packet whose
+ *       tail is being pushed or pulled).
+ *
+ * @note Either packet input to this routine may itself be a splice, however
+ *       individual implementations may impose limits on how deeply splices
+ *       may be nested and fail the attempted splice if those limits are
+ *       exceeded.
+ *
+ * @note The packets used to create a splice may reside in different pools,
+ *       however individual implementations may require that both reside in
+ *       the same pool and fail the attempted splice if this restriction is
+ *       not observed. Upon return odp_packet_pool() returns the pool id of
+ *       the header packet.
+ *
+ * @note Once successfully spliced, the base packet may be freed via
+ *       odp_packet_free(), however the storage used to represent it will not
+ *       be released until all splices based on it have themselves been freed.
+ */
+odp_packet_t odp_packet_splice(odp_packet_t hdr,
+			       odp_packet_t pkt, uint32_t offset);
+
+/**
+ * Create a reference to a packet
+ *
+ * Create a (shared) reference to a base packet starting at a specified
+ * byte offset. A reference is simply a splice with a zero-length header.
+ *
+ * @param pkt    Handle of the base packet for which a reference is to be
+ *               created.
+ * @param offset Byte offset in the base packet at which shared reference is
+ *               to begin.
+ *
+ * @return                    Handle of the reference packet
+ * @retval ODP_PACKET_INVALID Operation failed. Base packet remains unchanged.
+ *
+ * @note The zero-length header used to create a packet reference is always
+ *       drawn from the same pool as the base packet.
+ *
+ * @note Because references are a type of splice, any bytes pushed onto the
+ *       head of a reference (via odp_packet_push_head() or
+ *       odp_packet_extend_head() are unique to this reference and are not
+ *       seen by any other reference to the same base packet.
+ */
+odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t offset);
+
+/**
+ * Tests if a packet is a splice
+ *
+ * A packet is a splice if it was created by odp_packet_splice() or
+ * odp_packet_ref(). Note that a splice may be a simple splice or a
+ * compound splice (a splice created from another splice).
+ *
+ * @param pkt Packet Handle
+ *
+ * @retval 0 Packet is not a splice
+ * @retval >0 Packet is a splice containing N individual packets
+ */
+int odp_packet_is_a_splice(odp_packet_t pkt);
+
+/**
+ * Tests if a packet is spliced
+ *
+ * A packet is spliced if a splice was created on it by odp_packet_splice()
+ * or odp_packet_ref().
+ *
+ * @param pkt Packet Handle
+ *
+ * @retval 0 Packet is not spliced
+ * @retval >0 Packet has N splices based on it
+ */
+int odp_packet_is_spliced(odp_packet_t pkt);
+
 /*
  *
  * Copy