From patchwork Mon Mar 21 21:43:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 64142 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1679416lbc; Mon, 21 Mar 2016 14:44:34 -0700 (PDT) X-Received: by 10.140.236.72 with SMTP id h69mr13707063qhc.92.1458596673941; Mon, 21 Mar 2016 14:44:33 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id s105si25766306qgs.111.2016.03.21.14.44.33; Mon, 21 Mar 2016 14:44:33 -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 Received: by lists.linaro.org (Postfix, from userid 109) id 9BB62619C1; Mon, 21 Mar 2016 21:44:33 +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, URIBL_BLOCKED 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 31F29619C5; Mon, 21 Mar 2016 21:43:51 +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 7C8556198B; Mon, 21 Mar 2016 21:43:47 +0000 (UTC) Received: from mail-oi0-f53.google.com (mail-oi0-f53.google.com [209.85.218.53]) by lists.linaro.org (Postfix) with ESMTPS id EF84861845 for ; Mon, 21 Mar 2016 21:43:45 +0000 (UTC) Received: by mail-oi0-f53.google.com with SMTP id r187so154162298oih.3 for ; Mon, 21 Mar 2016 14:43:45 -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=cgqMU4lhQiP8eErSp8s/gjhgsNVsAO1Jh+AVR9zEPXg=; b=HO1WLj6WiJ/qBSbRYUYPhW4WL0SRfbIkF/15NkrjssPI9iq2P+j96MWSRcT2Olo+oh xhzLGq6SMYnyjcs0aVVBgD71z+eH53Hf13qTk4zt1xkZ9pVoBGcNPnbejggb+GWx25oi NxEtTg7cnHsinLVWDZ0Kx9BWzmuAPeErmwZ2EGn8TaDtgGXBH6QXx1WU3rtwlFqJ7jSd Bc1bXVLMU/UqS8II8FZ176iLGxleZ3wR3dKSC3WWI8bhuBmKE6gocQ2lLDR3WwtMOy44 +J5MJ4EKL18O8f8vCm56HkvNboExd/H6ldqLtGZKs9luSYEWRlsL58ZMMOOSI28E7tTC O35A== X-Gm-Message-State: AD7BkJI8NSGKsuAfsTvHQQ5o5Rs5NLfoW3uyiH+VSO1zxB/+4JeO1djEC1730GavxfzuluxU5o8= X-Received: by 10.157.54.235 with SMTP id s40mr1852438otd.133.1458596625445; Mon, 21 Mar 2016 14:43:45 -0700 (PDT) Received: from Ubuntu15.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id du1sm12569273oeb.9.2016.03.21.14.43.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Mar 2016 14:43:44 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Mon, 21 Mar 2016 16:43:40 -0500 Message-Id: <1458596621-18381-2-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1458596621-18381-1-git-send-email-bill.fischofer@linaro.org> References: <1458596621-18381-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv2 2/3] linux-generic: packet: support multi-segment head/tail push/pull ops 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Add support for multi-segment push/pull operations for Monarch compliance. If a push for more than the available headroom/tailroom is requested, then allocate additional head/tail segments if possible to complete the operation. Similarly, when pulling more than a single segment, allow empty segments to exist that consist entirely of headroom/tailroom. Signed-off-by: Bill Fischofer --- .../linux-generic/include/odp_buffer_internal.h | 4 ++ .../linux-generic/include/odp_packet_internal.h | 49 ++++++++++++++ platform/linux-generic/odp_packet.c | 10 ++- platform/linux-generic/odp_pool.c | 75 ++++++++++++++++++++++ 4 files changed, 136 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h index ea092ca..0a4c290 100644 --- a/platform/linux-generic/include/odp_buffer_internal.h +++ b/platform/linux-generic/include/odp_buffer_internal.h @@ -170,6 +170,10 @@ typedef struct { odp_buffer_t buffer_alloc(odp_pool_t pool, size_t size); int buffer_alloc_multi(odp_pool_t pool_hdl, size_t size, odp_buffer_t buf[], int num); +int seg_alloc_head(odp_buffer_hdr_t *buf_hdr, int segcount); +void seg_free_head(odp_buffer_hdr_t *buf_hdr, int segcount); +int seg_alloc_tail(odp_buffer_hdr_t *buf_hdr, int segcount); +void seg_free_tail(odp_buffer_hdr_t *buf_hdr, int segcount); #ifdef __cplusplus } diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index b632ece..77e32fe 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -210,6 +210,30 @@ static inline void pull_head(odp_packet_hdr_t *pkt_hdr, size_t len) pkt_hdr->frame_len -= len; } +static inline int push_head_seg(odp_packet_hdr_t *pkt_hdr, size_t len) +{ + uint32_t newsegcount = + (len - pkt_hdr->headroom + pkt_hdr->buf_hdr.size - 1) / + pkt_hdr->buf_hdr.size; + + if (pkt_hdr->buf_hdr.segcount + newsegcount > ODP_BUFFER_MAX_SEG) + return -1; + + if (seg_alloc_head(&pkt_hdr->buf_hdr, newsegcount)) + return -1; + + pkt_hdr->headroom += newsegcount * pkt_hdr->buf_hdr.size; + return 0; +} + +static inline void pull_head_seg(odp_packet_hdr_t *pkt_hdr) +{ + uint32_t extrasegs = pkt_hdr->headroom / pkt_hdr->buf_hdr.size; + + seg_free_head(&pkt_hdr->buf_hdr, extrasegs); + pkt_hdr->headroom -= extrasegs * pkt_hdr->buf_hdr.size; +} + static inline void push_tail(odp_packet_hdr_t *pkt_hdr, size_t len) { pkt_hdr->tailroom -= len; @@ -223,6 +247,31 @@ static inline void pull_tail(odp_packet_hdr_t *pkt_hdr, size_t len) pkt_hdr->frame_len -= len; } +static inline int push_tail_seg(odp_packet_hdr_t *pkt_hdr, size_t len) +{ + uint32_t newsegcount = + (len - pkt_hdr->tailroom + pkt_hdr->buf_hdr.size - 1) / + pkt_hdr->buf_hdr.size; + + if (pkt_hdr->buf_hdr.segcount + newsegcount > ODP_BUFFER_MAX_SEG) + return -1; + + if (seg_alloc_tail(&pkt_hdr->buf_hdr, newsegcount)) + return -1; + + pkt_hdr->tailroom += newsegcount * pkt_hdr->buf_hdr.size; + return 0; +} + +static inline void pull_tail_seg(odp_packet_hdr_t *pkt_hdr) +{ + uint32_t extrasegs = pkt_hdr->tailroom / pkt_hdr->buf_hdr.size; + + seg_free_tail(&pkt_hdr->buf_hdr, extrasegs); + + pkt_hdr->tailroom -= extrasegs * pkt_hdr->buf_hdr.size; +} + static inline uint32_t packet_len(odp_packet_hdr_t *pkt_hdr) { return pkt_hdr->frame_len; diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index aac42b6..4ea1812 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -255,7 +255,7 @@ void *odp_packet_push_head(odp_packet_t pkt, uint32_t len) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - if (len > pkt_hdr->headroom) + if (len > pkt_hdr->headroom && push_head_seg(pkt_hdr, len)) return NULL; push_head(pkt_hdr, len); @@ -270,6 +270,9 @@ void *odp_packet_pull_head(odp_packet_t pkt, uint32_t len) return NULL; pull_head(pkt_hdr, len); + if (pkt_hdr->headroom > pkt_hdr->buf_hdr.size) + pull_head_seg(pkt_hdr); + return packet_map(pkt_hdr, 0, NULL); } @@ -278,7 +281,7 @@ void *odp_packet_push_tail(odp_packet_t pkt, uint32_t len) odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); uint32_t origin = pkt_hdr->frame_len; - if (len > pkt_hdr->tailroom) + if (len > pkt_hdr->tailroom && push_tail_seg(pkt_hdr, len)) return NULL; push_tail(pkt_hdr, len); @@ -293,6 +296,9 @@ void *odp_packet_pull_tail(odp_packet_t pkt, uint32_t len) return NULL; pull_tail(pkt_hdr, len); + if (pkt_hdr->tailroom > pkt_hdr->buf_hdr.size) + pull_tail_seg(pkt_hdr); + return packet_map(pkt_hdr, pkt_hdr->frame_len, NULL); } diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c index f6fa8f5..e494d5a 100644 --- a/platform/linux-generic/odp_pool.c +++ b/platform/linux-generic/odp_pool.c @@ -500,6 +500,81 @@ int odp_pool_destroy(odp_pool_t pool_hdl) return 0; } +int seg_alloc_head(odp_buffer_hdr_t *buf_hdr, int segcount) +{ + uint32_t pool_id = pool_handle_to_index(buf_hdr->pool_hdl); + pool_entry_t *pool = get_pool_entry(pool_id); + void *newsegs[segcount]; + int i; + + for (i = 0; i < segcount; i++) { + newsegs[i] = get_blk(&pool->s); + if (newsegs[i] == NULL) { + while (--i >= 0) + ret_blk(&pool->s, newsegs[i]); + return -1; + } + } + + for (i = buf_hdr->segcount - 1; i >= 0; i--) + buf_hdr->addr[i + segcount] = buf_hdr->addr[i]; + + for (i = 0; i < segcount; i++) + buf_hdr->addr[i] = newsegs[i]; + + buf_hdr->segcount += segcount; + return 0; +} + +void seg_free_head(odp_buffer_hdr_t *buf_hdr, int segcount) +{ + uint32_t pool_id = pool_handle_to_index(buf_hdr->pool_hdl); + pool_entry_t *pool = get_pool_entry(pool_id); + int s_cnt = buf_hdr->segcount; + int i; + + for (i = 0; i < s_cnt; i++) + ret_blk(&pool->s, buf_hdr->addr[i]); + + for (i = 0; i < s_cnt - segcount; i++) + buf_hdr->addr[i] = buf_hdr->addr[i + segcount]; + + buf_hdr->segcount -= segcount; +} + +int seg_alloc_tail(odp_buffer_hdr_t *buf_hdr, int segcount) +{ + uint32_t pool_id = pool_handle_to_index(buf_hdr->pool_hdl); + pool_entry_t *pool = get_pool_entry(pool_id); + uint32_t s_cnt = buf_hdr->segcount; + int i; + + for (i = 0; i < segcount; i++) { + buf_hdr->addr[s_cnt + i] = get_blk(&pool->s); + if (buf_hdr->addr[s_cnt + i] == NULL) { + while (--i >= 0) + ret_blk(&pool->s, buf_hdr->addr[s_cnt + i]); + return -1; + } + } + + buf_hdr->segcount += segcount; + return 0; +} + +void seg_free_tail(odp_buffer_hdr_t *buf_hdr, int segcount) +{ + uint32_t pool_id = pool_handle_to_index(buf_hdr->pool_hdl); + pool_entry_t *pool = get_pool_entry(pool_id); + int s_cnt = buf_hdr->segcount; + int i; + + for (i = s_cnt - 1; i > s_cnt - segcount; i--) + ret_blk(&pool->s, buf_hdr->addr[i]); + + buf_hdr->segcount -= segcount; +} + odp_buffer_t buffer_alloc(odp_pool_t pool_hdl, size_t size) { uint32_t pool_id = pool_handle_to_index(pool_hdl);