From patchwork Fri Oct 7 21:20: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: 77356 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp421352qge; Fri, 7 Oct 2016 14:21:05 -0700 (PDT) X-Received: by 10.233.221.65 with SMTP id r62mr23185015qkf.104.1475875265292; Fri, 07 Oct 2016 14:21:05 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p67si1171420qkf.113.2016.10.07.14.21.03; Fri, 07 Oct 2016 14:21:05 -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 EDE3660D61; Fri, 7 Oct 2016 21:21:02 +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_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 22EC260C8E; Fri, 7 Oct 2016 21:20:55 +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 798C860D3F; Fri, 7 Oct 2016 21:20:48 +0000 (UTC) Received: from mail-oi0-f42.google.com (mail-oi0-f42.google.com [209.85.218.42]) by lists.linaro.org (Postfix) with ESMTPS id 135DD60C8E for ; Fri, 7 Oct 2016 21:20:47 +0000 (UTC) Received: by mail-oi0-f42.google.com with SMTP id n132so71121621oih.1 for ; Fri, 07 Oct 2016 14:20:47 -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=18SMllY75fFxnCTpKDE5wrjV/cS/tuHBzjcJ7RDyDos=; b=QEgFXpzTw3og4qijIWYNHxpR2r7i/NqSMxxwWdQTK3mpNbzSDGtPH9P3c2cUpLFwYR xDyyINq7+IsP8GhoLbGwcTBTydOfmZmtdVGt8zUGaVNtxkSab5gKltyHCfm7/pM6Kx0i Xw9L9e+kYiCyM2kIPcqdbOe3x6ySyz8KFiufUanhDbG+pXNw0Iw1F8enidh4Z7wd3n0H 8Zr+sQxA6R7RCjmkYq/EPDCWKNjul/mMwApGcFYRZT3Iw6gZcmfClKM1UT6m1rDGYBWv tUDEJLzbntDbk0yKmCFIjj4PXj6hpfBPjeAQm2oc6Ia4fk7EfAZLrkcjZPiitZzKRCSc ak8A== X-Gm-Message-State: AA6/9Rk+2Pg3uLIVxL/zN7qFC/37kPWKJx623ka0oCU7J39e81LeRfLBGXdSOnGSbm9xAseeBao= X-Received: by 10.202.92.198 with SMTP id q189mr4094065oib.6.1475875246590; Fri, 07 Oct 2016 14:20:46 -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 h24sm811040otc.19.2016.10.07.14.20.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Oct 2016 14:20:46 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Fri, 7 Oct 2016 16:20:42 -0500 Message-Id: <1475875243-10929-2-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475875243-10929-1-git-send-email-bill.fischofer@linaro.org> References: <1475875243-10929-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH 1/2] 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 three 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_spliced() allows an application to determine whether a packet is a splice and if so how many individual packets are contained within it. Signed-off-by: Bill Fischofer --- include/odp/api/spec/packet.h | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) -- 2.7.4 diff --git a/include/odp/api/spec/packet.h b/include/odp/api/spec/packet.h index 4a14f2d..ed4ea86 100644 --- a/include/odp/api/spec/packet.h +++ b/include/odp/api/spec/packet.h @@ -844,6 +844,92 @@ 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 spliced + * + * @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_spliced(odp_packet_t pkt); + /* * * Copy