From patchwork Fri Mar 28 16:56:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 27364 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 89B6120545 for ; Fri, 28 Mar 2014 16:56:23 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id cc10sf1778428wib.5 for ; Fri, 28 Mar 2014 09:56:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe:content-type; bh=NwRgEBS0w+rxGLIA/ihJZ7YC+7FN1RZWUL9FqchNU1o=; b=EPcZUVEVsvQPxRtlPY93QwQQ/o2ovRbS9orRJkIfuqoBOzyjtGYrJxIKyskALPIb6L 1vJmHLmD1DupMQVKbAI+BBIokBTO526xa8G+1NPduyOgSW3/l5qRi/uh7oSOYuKeJ0/m wnbZNk72cD+yBQsA0Q8dmKlDXqQLXhMAqcrc/ZYqlM7f8WdbCDCFHQrpeCcJy3XfOVZV CDJymGLTe7EfBLg0u6sJwCIY/yG9/FBvRzzj1XuWL0RdLWRFkaOURkHw746TPF9WOBpE 6ufF+dGKR/CW1IXhJMoCNSKkAsNMxivLrl1StOXdFLTwyDKLyz0nJD+MfFhnzKmUBdNW pK0g== X-Gm-Message-State: ALoCoQlTYMqORrbKeWtc9PIxaJnbAZuNxGetFYDmKHdSvXvW3En1/NNr2nQ0r4Jpd6NBY51Pzz+H X-Received: by 10.152.5.170 with SMTP id t10mr3886941lat.4.1396025782025; Fri, 28 Mar 2014 09:56:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: lng-odp@linaro.org Received: by 10.152.27.7 with SMTP id p7ls235016lag.54.gmail; Fri, 28 Mar 2014 09:56:21 -0700 (PDT) X-Received: by 10.152.19.7 with SMTP id a7mr6348279lae.16.1396025781649; Fri, 28 Mar 2014 09:56:21 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com [209.85.217.169]) by mx.google.com with ESMTPS id be6si3688176lbc.228.2014.03.28.09.56.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 09:56:21 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.217.169 is neither permitted nor denied by best guess record for domain of ciprian.barbu@linaro.org) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id q8so3911906lbi.14 for ; Fri, 28 Mar 2014 09:56:21 -0700 (PDT) X-Received: by 10.112.13.101 with SMTP id g5mr1811926lbc.39.1396025781072; Fri, 28 Mar 2014 09:56:21 -0700 (PDT) Received: from sestofb10.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id g8sm5604829laf.0.2014.03.28.09.56.20 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 09:56:20 -0700 (PDT) From: Ciprian Barbu To: lng-odp@linaro.org Cc: ciprian.barbu@linaro.org Subject: [lng-odp] [PATCH] Adding odp_packet_copy Date: Fri, 28 Mar 2014 17:56:14 +0100 Message-Id: <1396025774-56222-1-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Original-Sender: ciprian.barbu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.217.169 is neither permitted nor denied by best guess record for domain of ciprian.barbu@linaro.org) smtp.mail=ciprian.barbu@linaro.org Precedence: list Mailing-list: list lng-odp@linaro.org; contact lng-odp+owners@linaro.org List-ID: X-Google-Group-Id: 474323889996 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , odp_packet_copy for copying pkt contents and metadata Signed-off-by: Ciprian Barbu --- include/odp_packet.h | 9 +++++++++ platform/linux-generic/source/odp_packet.c | 24 ++++++++++++++++++++++++ test/packet_netmap/odp_example_pktio_netmap.c | 11 +---------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/include/odp_packet.h b/include/odp_packet.h index 3c7c9d0..c0bedcd 100644 --- a/include/odp_packet.h +++ b/include/odp_packet.h @@ -209,6 +209,15 @@ void odp_packet_set_l4_offset(odp_packet_t pkt, size_t offset); */ void odp_packet_print(odp_packet_t pkt); +/** + * Copy contents and metadata from pkt_src to pkt_dst + * Useful when creating copies of packets + * + * @param pkt_src Source packet + * @param pkt_dst Destination packet + */ +void odp_packet_copy(odp_packet_t pkt_src, odp_packet_t pkt_dst); + #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/source/odp_packet.c b/platform/linux-generic/source/odp_packet.c index b990222..47cabd3 100644 --- a/platform/linux-generic/source/odp_packet.c +++ b/platform/linux-generic/source/odp_packet.c @@ -331,3 +331,27 @@ void odp_packet_print(odp_packet_t pkt) printf("\n%s\n", str); } +void odp_packet_copy(odp_packet_t pkt_src, odp_packet_t pkt_dst) +{ + odp_packet_hdr_t *const pkt_hdr_src = odp_packet_hdr(pkt_src); + odp_packet_hdr_t *const pkt_hdr_dst = odp_packet_hdr(pkt_dst); + const size_t start_offset = ODP_FIELD_SIZEOF(odp_packet_hdr_t, buf_hdr); + odp_pktio_t input; + uint8_t *start_src; + uint8_t *start_dst; + size_t len; + + /* Preserve input */ + input = pkt_hdr_dst->input; + + start_src = (uint8_t *)pkt_hdr_src + start_offset; + start_dst = (uint8_t *)pkt_hdr_dst + start_offset; + + len = ODP_OFFSETOF(odp_packet_hdr_t, payload) - start_offset; + len += pkt_hdr_src->frame_offset + pkt_hdr_src->frame_len; + + memcpy(start_dst, start_src, len); + + /* Restore input */ + pkt_hdr_dst->input = input; +} diff --git a/test/packet_netmap/odp_example_pktio_netmap.c b/test/packet_netmap/odp_example_pktio_netmap.c index 2d74f8a..f9ed3b3 100644 --- a/test/packet_netmap/odp_example_pktio_netmap.c +++ b/test/packet_netmap/odp_example_pktio_netmap.c @@ -155,20 +155,11 @@ static void *pktio_queue_thread(void *arg) if (args->thread[pktio_nr].netmap_mode == ODP_NETMAP_MODE_HW) { odp_packet_t pkt_copy; odp_buffer_t buf_copy; - size_t frame_len = odp_packet_get_len(pkt); - size_t l2_offset = odp_packet_l2_offset(pkt); - size_t l3_offset = odp_packet_l3_offset(pkt); buf_copy = odp_buffer_alloc(pkt_pool); pkt_copy = odp_packet_from_buffer(buf_copy); - odp_packet_init(pkt_copy); - odp_packet_set_len(pkt_copy, frame_len); - odp_packet_set_l2_offset(pkt_copy, l2_offset); - odp_packet_set_l3_offset(pkt_copy, l3_offset); - - memcpy(odp_buffer_addr(pkt_copy), - odp_buffer_addr(pkt), frame_len); + odp_packet_copy(pkt, pkt_copy); swap_pkt_addrs(&pkt_copy, 1);