From patchwork Wed Apr 9 09:03:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 28067 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f199.google.com (mail-ig0-f199.google.com [209.85.213.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E1FFC2145A for ; Wed, 9 Apr 2014 09:04:35 +0000 (UTC) Received: by mail-ig0-f199.google.com with SMTP id c1sf5963586igq.10 for ; Wed, 09 Apr 2014 02:04:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=qpfGB+SZNSGLDi7aMd3urG1SJ/yZUD7TeyAIp2HHskw=; b=L2Ss388W++bPgdBPhXsHAu23osBJJVi/CUbUTaciniRYUltYmJGCOMs6F1OuBQ8FG7 Bz09BEMT8ZcSb1T8yh6YPqXbQNtbsgsZJVtmaS+snSxyZhEf3yFWbBAVnSRC8anfXMPN GPeXeaXuhJavkrjPePuVRY26ne70OqmR2qwcmRn5jaWoJugSdI2x79AxobFmYhR6+Nxw jd2LyGMnnEaaKI3PxoySvgkMqsY8Tq9Ym3+JcxPfmGTAAoCTKOEgLFZHL+ib9QROf3lw 1fV2CTN2YZp/E0azt++nQpLVxqekW5M5LstcaCMf75JKcLqSfdSYqvqufshZS8naV2dV +yfA== X-Gm-Message-State: ALoCoQm0nSixeATT19WzFpqiTRaDHUdaFrMXEou4Lw1BG5KG914x8Osmkq6XKq9gEs+gEzHkCzpw X-Received: by 10.50.136.198 with SMTP id qc6mr1929895igb.4.1397034275016; Wed, 09 Apr 2014 02:04:35 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.70 with SMTP id u64ls525309qgd.80.gmail; Wed, 09 Apr 2014 02:04:34 -0700 (PDT) X-Received: by 10.58.31.136 with SMTP id a8mr8052166vei.20.1397034274834; Wed, 09 Apr 2014 02:04:34 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id wg4si49439vcb.38.2014.04.09.02.04.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 09 Apr 2014 02:04:34 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id lh14so1775998vcb.6 for ; Wed, 09 Apr 2014 02:04:34 -0700 (PDT) X-Received: by 10.52.251.199 with SMTP id zm7mr6524120vdc.21.1397034274745; Wed, 09 Apr 2014 02:04:34 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp312792vcv; Wed, 9 Apr 2014 02:04:34 -0700 (PDT) X-Received: by 10.140.102.135 with SMTP id w7mr10175665qge.29.1397034274391; Wed, 09 Apr 2014 02:04:34 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id w73si135810qge.9.2014.04.09.02.04.33 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 09 Apr 2014 02:04:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WXoOV-0001wu-Nh; Wed, 09 Apr 2014 09:02:07 +0000 Received: from mail-la0-f42.google.com ([209.85.215.42]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WXoNx-00012u-T8 for lng-odp@lists.linaro.org; Wed, 09 Apr 2014 09:01:34 +0000 Received: by mail-la0-f42.google.com with SMTP id ec20so921556lab.29 for ; Wed, 09 Apr 2014 02:03:53 -0700 (PDT) X-Received: by 10.112.32.67 with SMTP id g3mr585748lbi.46.1397034233332; Wed, 09 Apr 2014 02:03:53 -0700 (PDT) Received: from sestofb10.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id x5sm334267lbk.5.2014.04.09.02.03.52 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 09 Apr 2014 02:03:52 -0700 (PDT) From: Ciprian Barbu To: lng-odp@lists.linaro.org Date: Wed, 9 Apr 2014 11:03:35 +0200 Message-Id: <1397034218-2971-3-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1397034218-2971-1-git-send-email-ciprian.barbu@linaro.org> References: <1397034218-2971-1-git-send-email-ciprian.barbu@linaro.org> Subject: [lng-odp] [PATCH 2/5] Adding odp_packet_copy X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ciprian.barbu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This function will not some more work when the scatter/gather support is added, for now the odp_buffer_copy_scatter is just a stub. Signed-off-by: Ciprian Barbu --- include/odp_packet.h | 11 +++++++ .../linux-generic/include/odp_buffer_internal.h | 2 ++ platform/linux-generic/source/odp_buffer.c | 6 ++++ platform/linux-generic/source/odp_packet.c | 38 ++++++++++++++++++++++ test/packet_netmap/odp_example_pktio_netmap.c | 31 +++++++----------- 5 files changed, 69 insertions(+), 19 deletions(-) diff --git a/include/odp_packet.h b/include/odp_packet.h index 3c7c9d0..4a16e11 100644 --- a/include/odp_packet.h +++ b/include/odp_packet.h @@ -209,6 +209,17 @@ 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_dst Destination packet + * @param pkt_src Source packet + * + * @return 0 if successful + */ +int odp_packet_copy(odp_packet_t pkt_dst, odp_packet_t pkt_src); + #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h index c4e5b33..f8ebc7c 100644 --- a/platform/linux-generic/include/odp_buffer_internal.h +++ b/platform/linux-generic/include/odp_buffer_internal.h @@ -107,6 +107,8 @@ typedef struct odp_buffer_chunk_hdr_t { int odp_buffer_snprint(char *str, size_t n, odp_buffer_t buf); +void odp_buffer_copy_scatter(odp_buffer_t buf_dst, odp_buffer_t buf_src); + #ifdef __cplusplus } diff --git a/platform/linux-generic/source/odp_buffer.c b/platform/linux-generic/source/odp_buffer.c index f506d35..afbe96a 100644 --- a/platform/linux-generic/source/odp_buffer.c +++ b/platform/linux-generic/source/odp_buffer.c @@ -111,3 +111,9 @@ void odp_buffer_print(odp_buffer_t buf) printf("\n%s\n", str); } + +void odp_buffer_copy_scatter(odp_buffer_t buf_dst, odp_buffer_t buf_src) +{ + (void)buf_dst; + (void)buf_src; +} diff --git a/platform/linux-generic/source/odp_packet.c b/platform/linux-generic/source/odp_packet.c index 8af5169..eb7c227 100644 --- a/platform/linux-generic/source/odp_packet.c +++ b/platform/linux-generic/source/odp_packet.c @@ -328,3 +328,41 @@ void odp_packet_print(odp_packet_t pkt) printf("\n%s\n", str); } + +int odp_packet_copy(odp_packet_t pkt_dst, odp_packet_t pkt_src) +{ + odp_packet_hdr_t *const pkt_hdr_dst = odp_packet_hdr(pkt_dst); + odp_packet_hdr_t *const pkt_hdr_src = odp_packet_hdr(pkt_src); + const size_t start_offset = ODP_FIELD_SIZEOF(odp_packet_hdr_t, buf_hdr); + uint8_t *start_src; + uint8_t *start_dst; + size_t len; + + if (pkt_dst == ODP_PACKET_INVALID || pkt_src == ODP_PACKET_INVALID) + return -1; + + if (pkt_hdr_dst->buf_hdr.size < + pkt_hdr_src->frame_len + pkt_hdr_src->frame_offset) + return -1; + + /* Copy packet header */ + start_dst = (uint8_t *)pkt_hdr_dst + start_offset; + start_src = (uint8_t *)pkt_hdr_src + start_offset; + len = ODP_OFFSETOF(odp_packet_hdr_t, payload) - start_offset; + memcpy(start_dst, start_src, len); + + /* Copy frame payload */ + start_dst = (uint8_t *)odp_packet_start(pkt_dst); + start_src = (uint8_t *)odp_packet_start(pkt_src); + len = pkt_hdr_src->frame_len; + memcpy(start_dst, start_src, len); + + /* Copy useful things from the buffer header */ + pkt_hdr_dst->buf_hdr.cur_offset = pkt_hdr_src->buf_hdr.cur_offset; + + /* Create a copy of the scatter list */ + odp_buffer_copy_scatter(odp_buffer_from_packet(pkt_dst), + odp_buffer_from_packet(pkt_src)); + + return 0; +} diff --git a/test/packet_netmap/odp_example_pktio_netmap.c b/test/packet_netmap/odp_example_pktio_netmap.c index 2d74f8a..7c60467 100644 --- a/test/packet_netmap/odp_example_pktio_netmap.c +++ b/test/packet_netmap/odp_example_pktio_netmap.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -149,33 +150,25 @@ static void *pktio_queue_thread(void *arg) /* Lookup the thread associated with the entry */ pktio_nr = args->pktio_tbl[pktio_tmp]; - odp_queue_enq(args->thread[pktio_nr].bridge_q, buf); /* Send back packets arrived on physical interface */ 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); - swap_pkt_addrs(&pkt_copy, 1); + pkt_copy = odp_packet_alloc(pkt_pool); - buf_copy = odp_buffer_from_packet(pkt_copy); - odp_queue_enq(outq_def, buf_copy); + if (odp_packet_copy(pkt_copy, pkt) != 0) { + ODP_ERR("Packet copy failed!\n"); + odp_packet_free(pkt_copy); + } else { + swap_pkt_addrs(&pkt_copy, 1); + odp_queue_enq(outq_def, + odp_buffer_from_packet(pkt_copy)); + } } + odp_queue_enq(args->thread[pktio_nr].bridge_q, buf); + /* Print packet counts every once in a while */ if (odp_unlikely(pkt_cnt++ % 100000 == 0)) { printf(" [%02i] pkt_cnt:%lu\n", thr, pkt_cnt);