From patchwork Tue Apr 1 18:01:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 27560 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D0E7320341 for ; Tue, 1 Apr 2014 18:01:16 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id m15sf17049121wgh.7 for ; Tue, 01 Apr 2014 11:01:15 -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=2SC6qvCxt4bvthVynB3u63KJ759ETobITH9DCIkWP5Q=; b=OcI3nf/Btezk/L87GTgEu4YVqed8+1+ujxrCG3I603fw6Oy3oLSPIStbcBGBiuQGeo d6oxU/PZykVTCF9NeRlLgoIBfi4WTP0AEZ9zUxhF/aGNjf3rMUpBw+mNkhmQ7tgfL4sY FQKULosRJAxz+srF3uEnDSB2KaOIWKBnQoCjZtHWUwjYzzPvo9FJbADHcPMbAA/RsIn6 tu6qu/WR8NS2u3+6IRSUPKs/yU04ckDfUVqOcTGGgzFhplDJhGI6NlAQyzTX4ujZmPzc coECV7MkAzgs0/gc3atBXMaHTeDLL/ibbtKU4dwujwJ+L5kve8UmcMC+9LIT37d0K7Cm eYjw== X-Gm-Message-State: ALoCoQklx9ozhmxT0l8zo1OMo36nbFKcP8cP9oum4xc0O511sUa/oaNkX/zGsSuAW3owzG0yhXtJ X-Received: by 10.112.145.162 with SMTP id sv2mr14427671lbb.15.1396375275233; Tue, 01 Apr 2014 11:01:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: lng-odp@linaro.org Received: by 10.152.36.194 with SMTP id s2ls27513laj.16.gmail; Tue, 01 Apr 2014 11:01:14 -0700 (PDT) X-Received: by 10.112.56.148 with SMTP id a20mr1826650lbq.44.1396375274785; Tue, 01 Apr 2014 11:01:14 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com [209.85.215.49]) by mx.google.com with ESMTPS id tr4si10152782lbb.238.2014.04.01.11.01.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Apr 2014 11:01:14 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.215.49 is neither permitted nor denied by best guess record for domain of ciprian.barbu@linaro.org) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id mc6so7091883lab.8 for ; Tue, 01 Apr 2014 11:01:14 -0700 (PDT) X-Received: by 10.152.22.72 with SMTP id b8mr26274laf.63.1396375274378; Tue, 01 Apr 2014 11:01:14 -0700 (PDT) Received: from sestofb10.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id mk5sm17738199lac.6.2014.04.01.11.01.13 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Apr 2014 11:01:13 -0700 (PDT) From: Ciprian Barbu To: lng-odp@linaro.org Cc: ciprian.barbu@linaro.org Subject: [lng-odp][PATCH v2] Adding odp_packet_copy Date: Tue, 1 Apr 2014 20:01:07 +0200 Message-Id: <1396375267-1221-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.49 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: , Signed-off-by: Ciprian Barbu --- include/odp_packet.h | 9 +++++++ .../linux-generic/include/odp_buffer_internal.h | 2 ++ platform/linux-generic/source/odp_buffer.c | 5 ++++ platform/linux-generic/source/odp_packet.c | 28 ++++++++++++++++++++++ test/packet_netmap/odp_example_pktio_netmap.c | 14 +++-------- 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/include/odp_packet.h b/include/odp_packet.h index 3c7c9d0..3701078 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_dst Destination packet + * @param pkt_src Source packet + */ +void 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 f5b02fd..f25bd45 100644 --- a/platform/linux-generic/source/odp_buffer.c +++ b/platform/linux-generic/source/odp_buffer.c @@ -122,3 +122,8 @@ void odp_buffer_print(odp_buffer_t buf) +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 5f07374..5471b0a 100644 --- a/platform/linux-generic/source/odp_packet.c +++ b/platform/linux-generic/source/odp_packet.c @@ -331,3 +331,31 @@ void odp_packet_print(odp_packet_t pkt) printf("\n%s\n", str); } +void 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; + + /* 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)); +} diff --git a/test/packet_netmap/odp_example_pktio_netmap.c b/test/packet_netmap/odp_example_pktio_netmap.c index 2d74f8a..586356d 100644 --- a/test/packet_netmap/odp_example_pktio_netmap.c +++ b/test/packet_netmap/odp_example_pktio_netmap.c @@ -149,26 +149,16 @@ 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); + odp_packet_copy(pkt_copy, pkt); swap_pkt_addrs(&pkt_copy, 1); @@ -176,6 +166,8 @@ static void *pktio_queue_thread(void *arg) odp_queue_enq(outq_def, buf_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);