From patchwork Fri Mar 28 17:23:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 27365 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0A98620062 for ; Fri, 28 Mar 2014 17:23:32 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id c11sf9161454lbj.11 for ; Fri, 28 Mar 2014 10:23:31 -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=NoiTMtBFfoy02TYaMOGOZlv2+BBJEGCePtf7JR2kCec=; b=giPcV3RB3jFJEfAOWQkxoRarwX264tep/uBFI+sPDCWtlvBpc4uC2Mm6lyJtLwTcIt Wz4va/u1iFS7ncHH3ICI/C6zb0xr+WyT/H/PHINF1GPu31ikYqTP29PWZKYj2/OvwlPk aM+36/Sk2dNZwkkPmRrMHtw9By/WEGDF7x/Xn1sJIqTRdv7guccRwpiFZcXYO7eJObgy FNmeqWbsn03P9HYowcUT641/DmBWm23fUg3CybW8TuNPxvSmvQkDkF13QYkE3fLHih/u v1yxUrg4PSPUbpkwkqSV8LVdvkmS8mRBxHVgun92IzlDf7Knp8SS3Im67qX/DiX021mP Wvjw== X-Gm-Message-State: ALoCoQlss58h3I9Tt7uQKc+iIulFo+02B0Va+9wCCVHd3qw7adQYp95u5brg3r3RHEp54HCTA6R4 X-Received: by 10.112.1.99 with SMTP id 3mr3938113lbl.3.1396027411422; Fri, 28 Mar 2014 10:23:31 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: lng-odp@linaro.org Received: by 10.152.207.35 with SMTP id lt3ls235746lac.24.gmail; Fri, 28 Mar 2014 10:23:31 -0700 (PDT) X-Received: by 10.112.51.202 with SMTP id m10mr4838lbo.63.1396027411199; Fri, 28 Mar 2014 10:23:31 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com [209.85.215.52]) by mx.google.com with ESMTPS id zv8si3750664lbb.20.2014.03.28.10.23.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 10:23:31 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.215.52 is neither permitted nor denied by best guess record for domain of ciprian.barbu@linaro.org) client-ip=209.85.215.52; Received: by mail-la0-f52.google.com with SMTP id ec20so3828680lab.25 for ; Fri, 28 Mar 2014 10:23:31 -0700 (PDT) X-Received: by 10.152.21.66 with SMTP id t2mr12680lae.89.1396027411090; Fri, 28 Mar 2014 10:23:31 -0700 (PDT) Received: from sestofb10.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id d9sm5638391laa.17.2014.03.28.10.23.30 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 10:23:30 -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 18:23:24 +0100 Message-Id: <1396027404-34935-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.215.52 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: , Resending due to missing [lng-odp] 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);