From patchwork Mon Oct 10 15:50:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 77440 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp1248247qge; Mon, 10 Oct 2016 08:51:32 -0700 (PDT) X-Received: by 10.36.200.85 with SMTP id w82mr11284764itf.29.1476114692045; Mon, 10 Oct 2016 08:51:32 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d30si37585533ioj.199.2016.10.10.08.51.31; Mon, 10 Oct 2016 08:51:32 -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 726D160F15; Mon, 10 Oct 2016 15:51:31 +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_DNSWL_NONE, RCVD_IN_MSPIKE_H2 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 DC76160E8C; Mon, 10 Oct 2016 15:50:59 +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 D160660F19; Mon, 10 Oct 2016 15:50:53 +0000 (UTC) Received: from mail-oi0-f44.google.com (mail-oi0-f44.google.com [209.85.218.44]) by lists.linaro.org (Postfix) with ESMTPS id 527376094E for ; Mon, 10 Oct 2016 15:50:50 +0000 (UTC) Received: by mail-oi0-f44.google.com with SMTP id d132so131886386oib.2 for ; Mon, 10 Oct 2016 08:50:50 -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=W5rwChNS2oJ6UDnwvAzZtF4HBTIqqkrZmFkw6H0Y9F1YA1xkVJsu/L3LSbuXYAYDoO 5e+J40QIFjtIzm8DBmHx/xn8a9K676aJbaIMOJ82Ti5C3XpGkwxUlH0bMWN3FB4xUi1X //EIEA3c9MtBZlonyzHF3+/6XfS4jRi4wLzd55WNjWR0slhT7ob/9CMNlwVkg1F30RpX 4oAt7JA/a4ztiBjHdkpDq2WCVVg8tNV7UoBWisyVDl9Gk1H+BkpIwIzKx5y6IpK8yLBJ nddU+s9RoNRAA9QJPv0sLPrGOMC27gjX4th65i9l5VE6U21cjcQSIRALLUNCJjmNUzew s3TA== X-Gm-Message-State: AA6/9Rmg0klnIieBRigvzVwRb0EF13a8m8d/gMWWJp/aEFSkpWNRXiv5I3zqWDHsIt+/nTTYMLQ= X-Received: by 10.202.188.134 with SMTP id m128mr26295600oif.85.1476114649476; Mon, 10 Oct 2016 08:50:49 -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 1sm1740700otb.2.2016.10.10.08.50.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Oct 2016 08:50:49 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Mon, 10 Oct 2016 10:50:42 -0500 Message-Id: <1476114646-9874-2-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476114646-9874-1-git-send-email-bill.fischofer@linaro.org> References: <1476114646-9874-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv4 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