From patchwork Sun Oct 30 23:19:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 80102 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp2186835qge; Sun, 30 Oct 2016 16:19:27 -0700 (PDT) X-Received: by 10.200.55.213 with SMTP id e21mr20906408qtc.106.1477869566967; Sun, 30 Oct 2016 16:19:26 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id q58si4933255qta.108.2016.10.30.16.19.26; Sun, 30 Oct 2016 16:19:26 -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 1177860F04; Sun, 30 Oct 2016 23:19:26 +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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 246EF60C7B; Sun, 30 Oct 2016 23:19:19 +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 B46C060EAB; Sun, 30 Oct 2016 23:19:15 +0000 (UTC) Received: from mail-oi0-f46.google.com (mail-oi0-f46.google.com [209.85.218.46]) by lists.linaro.org (Postfix) with ESMTPS id 3309960ACA for ; Sun, 30 Oct 2016 23:19:14 +0000 (UTC) Received: by mail-oi0-f46.google.com with SMTP id y2so193197667oie.0 for ; Sun, 30 Oct 2016 16:19:14 -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; bh=VnjmgM4vhuEsDwOsllgxtFBk+3iYVq8LF8GOIG6YvLE=; b=Jwhf+d/w/0DfixWGQG+4sIrWFqJAb+NdZghdimblpU6C9qpTLi2AOsK15gt173exA/ W+6M+1yAB/hSTrOgzuhGyU1omBTEk5YqJ6C5Be2g7cV9LfOCCEWjaDAFMtkv9126flMC nrpnIhO7QjHvJBUH+LrlsKVxjzmluKUhnee9t/7DAwQj7L/vbaW3QTYHuy1eQbNgzBz5 UTrMeq30j4xfVFIxFR01W7uz+22VJHkg/EWgh8Dd9nziYSi3dWHjdRumcrLw+1xEzHqU RywK2OLXVeRyMTPGaP/5HnO5+37bhYmmiUD96YmwJNS/hqJrhIsWEAWPelA3DeEY+Qq7 RcsQ== X-Gm-Message-State: ABUngveXJ/Qf1zKY0FrPC6XMulu473FbUSil6YDwWrbhTpf91kJyBtiH5cHESLEldoHIAuvVXTI= X-Received: by 10.157.38.151 with SMTP id l23mr17641891otb.97.1477869553453; Sun, 30 Oct 2016 16:19:13 -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 a65sm821425oih.6.2016.10.30.16.19.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Oct 2016 16:19:12 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sun, 30 Oct 2016 18:19:05 -0500 Message-Id: <1477869549-6938-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH 1/5] api: packet: add support for packet 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_ref_static() creates an alias for a base packet odp_packet_ref() creates a reference to a base packet odp_packet_ref_pkt() creates a reference to a base packet from a supplied header packet In addition, three other APIs simplify working with references odp_packet_is_ref() says whether a packet is a reference odp_packet_has_ref() says whether a packet has had a reference made to it odp_packet_unshared_len() gives the length of the prefix bytes that are unique to this reference. These are the only bytes of the packet that may be modified safely. Signed-off-by: Bill Fischofer --- include/odp/api/spec/packet.h | 168 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) -- 2.7.4 diff --git a/include/odp/api/spec/packet.h b/include/odp/api/spec/packet.h index 4a14f2d..45935e7 100644 --- a/include/odp/api/spec/packet.h +++ b/include/odp/api/spec/packet.h @@ -255,6 +255,23 @@ uint32_t odp_packet_seg_len(odp_packet_t pkt); uint32_t odp_packet_len(odp_packet_t pkt); /** + * Packet unshared data len + * + * Returns the sum of data lengths over all unshared packet segments. These + * are the only bytes that should be modified by the caller. The rest of the + * packet should be treated as read-only. + * + * This routine will return 0 if odp_packet_has_ref() != 0 and will be the + * same as odp_packet_len() if odp_packet_has_ref() == 0 and + * odp_packet_is_ref() == 0. + * + * @param pkt Packet handle + * + * @return Packet unshared data length + */ +uint32_t odp_packet_unshared_len(odp_packet_t pkt); + +/** * Packet headroom length * * Returns the current packet level headroom length. @@ -846,6 +863,157 @@ int odp_packet_split(odp_packet_t *pkt, uint32_t len, odp_packet_t *tail); /* * + * References + * ******************************************************** + * + */ + +/** + * Create a static reference to a packet + * + * A static reference is used to obtain an additional handle for referring to + * a packet so that the storage behind it is not freed until all references to + * the packet are freed. This can be used, for example, to support efficient + * retransmission processing. + * + * The intent of a static reference is that both the base packet and the + * returned reference will be treated as read-only after this call. Results + * are unpredictable if this restriction is not observed. + * + * Static references have restrictions but may have performance advantages on + * some platforms if the caller does not intend to modify the reference + * packet. If modification is needed (e.g., to prefix a unique header onto the + * packet) then odp_packet_ref() or odp_packet_ref_pkt() should be used. + * + * @param pkt Handle of the base packet for which a static reference is + * to be created. + * + * @return Handle of the static reference packet + * @retval ODP_PACKET_INVALID Operation failed. Base packet remains unchanged. + */ +odp_packet_t odp_packet_ref_static(odp_packet_t pkt); + +/** + * Create a reference to a packet + * + * Create a dynamic reference to a base packet starting at a specified byte + * offset. This reference may be used as an argument to header manipulation + * APIs to prefix a unique header onto the shared base. The storage associated + * with the base packet is not freed until all references to it are freed, + * which permits easy multicasting or retransmission processing to be + * performed. Following a successful call, the base packet should be treated + * as read-only. Results are unpredictable if this restriction is not + * observed. + * + * This operation prepends a zero-length header onto the base packet beginning + * at the specified offset. This header is always drawn from the same pool as + * the base packet. + * + * Because references are unique packets, 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 the base packet or by any other + * reference to the same base packet. + * + * The base packet used as input to this routine may itself by a reference to + * some other base packet. Implementations MAY restrict the ability to create + * such compound references. Attempts to exceed any implementation limits in + * this regard will result in this call failing and returning + * ODP_PACKET_INVALID. + * + * If the caller does not indend to push a header onto the returned reference, + * the odp_packet_ref_static() API may be used. This may be a more efficient + * means of obtaining another reference to a base packet that will be treated + * as read-only. + * + * @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 the shared reference + * is to begin. Must be in the range 0..odp_packet_len(pkt)-1. + * + * @return Handle of the reference packet + * @retval ODP_PACKET_INVALID Operation failed. Base packet remains unchanged. + * + + */ +odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t offset); + +/** + * Create a reference to another packet from a header packet + * + * Create a dynamic reference to a base packet starting at a specified byte + * offset by prepending a supplied header packet. The resulting reference + * consists of the unshared header followed by the shared base packet starting + * at the specified offset. This shared portion should be regarded as + * read-only. The storage associated with the shared portion of the reference + * is not freed until all references to it are freed, which permits easy + * multicasting or retransmission processing to be performed. + * + * Either packet input to this routine may itself be a reference, however + * individual implementations MAY impose limits on how deeply splices may be + * nested and fail the call if those limits are exceeded. + * + * The packets used as input to this routine may reside in different pools, + * however individual implementations MAY require that both reside in the same + * pool and fail the call if this restriction is not observed. + * + * odp_packet_pool() on the returned reference returns the pool id of the + * header packet. + * + * @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 the shared reference + * to begin. Must be in the range 0..odp_packet_len(pkt)-1. + * + * @param hdr Handle of the header packet to be prefixed onto the base + * packet to create the reference. If this is specified as + * ODP_PACKET_INVALID, this call is equivalent to + * odp_packet_ref(). The supplied hdr must be distinct from + * the base pkt and results are undefined if an attempt is made + * to create circular references. + * + * @return Handle of the reference packet. This may or may not be the + * same as the input hdr packet. The caller should only use this + * handle since the original hdr packet no longer has any + * independent existence. + * + * @retval ODP_PACKET_INVALID If the reference failed. In this case both pkt + * and hdr are unchanged. + */ +odp_packet_t odp_packet_ref_pkt(odp_packet_t pkt, uint32_t offset, + odp_packet_t hdr); + +/** + * Test if a packet is a reference + * + * A packet is a reference if it was created by odp_packet_ref() or + * odp_packet_ref_pkt(). Note that a reference created from another + * reference is considered a compound reference. Calls on such packets will + * result in return values greater than 1. + * + * @param pkt Packet handle + * + * @retval 0 Packet is not a reference + * @retval >0 Packet is a reference consisting of N individual packets. + */ +int odp_packet_is_ref(odp_packet_t pkt); + +/** + * Test if a packet has a reference + * + * A packet has a reference if a reference was created on it by + * odp_packet_ref_static(), odp_packet_ref(), or odp_packet_ref_pkt(). + * + * @param pkt Packet handle + * + * @retval 0 Packet does not have any references + * @retval >0 Packet has N references based on it + */ +int odp_packet_has_ref(odp_packet_t pkt); + +/* + * * Copy * ******************************************************** *