From patchwork Sun Oct 9 21:58:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 77415 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp986870qge; Sun, 9 Oct 2016 14:59:17 -0700 (PDT) X-Received: by 10.55.215.151 with SMTP id t23mr27388400qkt.199.1476050357459; Sun, 09 Oct 2016 14:59:17 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 16si14775113qkd.95.2016.10.09.14.59.17; Sun, 09 Oct 2016 14:59:17 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 0BCAB60E93; Sun, 9 Oct 2016 21:59:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 2D7F760E85; Sun, 9 Oct 2016 21:58:39 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id EC6AC60E7F; Sun, 9 Oct 2016 21:58:33 +0000 (UTC) Received: from mail-oi0-f52.google.com (mail-oi0-f52.google.com [209.85.218.52]) by lists.linaro.org (Postfix) with ESMTPS id 9D66860E7F for ; Sun, 9 Oct 2016 21:58:32 +0000 (UTC) Received: by mail-oi0-f52.google.com with SMTP id n132so110012293oih.1 for ; Sun, 09 Oct 2016 14:58:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6vqujT13Xpi/fpUWQ3tOz40Wm9UhsAjy8NdEf8jm4nY=; b=dGIFJ1tfcOEPsTiZqrko0MWPe5rQgRmgcSRgWeGyWLrY6XtPLygNN+H1a+jKHpyK0G HCrJ3YhziYz5wtsPk/J6TUySITxMai+LPEn3Uoo3nLxrGlaISyMrjgvnKNmDFJUWC+O9 8WEMPQLBgIPGeHK9yDw1VktLnp/au1TY78Fyvgnaw2H8ki2p0NgAptFBSyLNByugDb95 0zC1j+CWNwSH9BilPLURr50MJ55QpTUvD7yX+5PHTM5iGUDWz1mu3BCUM6ZR6/rwAokl 6T40k/Kty+6OqwpZH5PQKVPbyexz8pA/piA1qCP/ZkPnDXXhEvMJwlpQ/4GOhGLS7N5t 8GeA== X-Gm-Message-State: AA6/9RnqD3PI1ivpDyVmM61guZhJ33whKLjB7v2HBFmksKn5GDfXjkexmdPug7O5tWbYGXSPArY= X-Received: by 10.202.187.215 with SMTP id l206mr22627085oif.173.1476050312007; Sun, 09 Oct 2016 14:58:32 -0700 (PDT) Received: from localhost.localdomain (cpe-70-121-83-241.austin.res.rr.com. [70.121.83.241]) by smtp.gmail.com with ESMTPSA id o8sm9786082oia.28.2016.10.09.14.58.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 09 Oct 2016 14:58:31 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sun, 9 Oct 2016 16:58:24 -0500 Message-Id: <1476050308-15181-2-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476050308-15181-1-git-send-email-bill.fischofer@linaro.org> References: <1476050308-15181-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv3 1/5] api: packet: add support for packet splices and references X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" 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 --- include/odp/api/spec/packet.h | 103 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) -- 2.7.4 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