From patchwork Fri Mar 24 14:01:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Pricope X-Patchwork-Id: 95944 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp62428qgd; Fri, 24 Mar 2017 07:06:31 -0700 (PDT) X-Received: by 10.55.189.130 with SMTP id n124mr7966302qkf.235.1490364391725; Fri, 24 Mar 2017 07:06:31 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k77si1990112qkl.14.2017.03.24.07.06.31; Fri, 24 Mar 2017 07:06:31 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 58BFD642C5; Fri, 24 Mar 2017 14:06:31 +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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 EAF4E63E17; Fri, 24 Mar 2017 14:03:29 +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 D7A29642D3; Fri, 24 Mar 2017 14:03:21 +0000 (UTC) Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) by lists.linaro.org (Postfix) with ESMTPS id DD944642C8 for ; Fri, 24 Mar 2017 14:02:02 +0000 (UTC) Received: by mail-wr0-f175.google.com with SMTP id l43so2371226wre.1 for ; Fri, 24 Mar 2017 07:02:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=j+Fso7sysVSkz5wdr6OJ8Ur0/T9NdrlgjUm2rEGiboE=; b=ARtIoxzaTGiiwlwl8H4tJ0NIkbYQAh37qHkKVuWj7n1WB6tXjkWo5jU8XF2XjVKY2P bn06xgHHyY9wlaeV0JtCKeuv57A9lMR73uvZyiD7KreJUhG7lEstdsOFXvZI1g354rSW KD9FZ6rlEyB8/H91GX+DMxUoXx0bW/Q+qf1tHcWx9rzucGg9KCv9uyLkFtrBohVz3IDS TPkyKZGuTS9Z28lkiGfqObiXOjlaM9vQ/rc1Dgl8h351Sw7Ki6L+tBi/dRJkanw/7EvW 8H5r3K/adpF8nwXJKnGr4TtyRiEyGIafHFPILN/zBB5w74//aAW/i9Zg/w2gwHzj+LjF 4iEQ== X-Gm-Message-State: AFeK/H1Jk1+67j6n46GpMyJkqR6O1mqTZe7ETWC6MIxgYfhQjQiYTtJcrjR2YfUI4aRVWYb6ehwn7qoy X-Received: by 10.223.167.66 with SMTP id e2mr7744012wrd.48.1490364120253; Fri, 24 Mar 2017 07:02:00 -0700 (PDT) Received: from localhost.localdomain ([193.202.22.66]) by smtp.gmail.com with ESMTPSA id c8sm2979045wrd.57.2017.03.24.07.01.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 07:01:59 -0700 (PDT) From: Bogdan Pricope To: lng-odp@lists.linaro.org Date: Fri, 24 Mar 2017 16:01:38 +0200 Message-Id: <1490364102-13781-2-git-send-email-bogdan.pricope@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490364102-13781-1-git-send-email-bogdan.pricope@linaro.org> References: <1490364102-13781-1-git-send-email-bogdan.pricope@linaro.org> Subject: [lng-odp] [PATCHv4 1/5] test: generator: compose sending packets from reference packet plus differences 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Signed-off-by: Bogdan Pricope --- example/generator/odp_generator.c | 130 +++++++++++++++++++++++++++++++++----- 1 file changed, 113 insertions(+), 17 deletions(-) -- 1.9.1 diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 8062d87..816db88 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -170,21 +170,20 @@ static int scan_ip(char *buf, unsigned int *paddr) } /** - * set up an udp packet + * set up an udp packet reference * * @param pool Buffer pool to create packet in * * @return Handle of created packet * @retval ODP_PACKET_INVALID Packet could not be created */ -static odp_packet_t pack_udp_pkt(odp_pool_t pool) +static odp_packet_t setup_udp_pkt_ref(odp_pool_t pool) { odp_packet_t pkt; char *buf; odph_ethhdr_t *eth; odph_ipv4hdr_t *ip; odph_udphdr_t *udp; - unsigned short seq; pkt = odp_packet_alloc(pool, args->appl.payload + ODPH_UDPHDR_LEN + ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); @@ -200,8 +199,10 @@ static odp_packet_t pack_udp_pkt(odp_pool_t pool) memcpy((char *)eth->src.addr, args->appl.srcmac.addr, ODPH_ETHADDR_LEN); memcpy((char *)eth->dst.addr, args->appl.dstmac.addr, ODPH_ETHADDR_LEN); eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4); + /* ip */ odp_packet_l3_offset_set(pkt, ODPH_ETHHDR_LEN); + odp_packet_has_ipv4_set(pkt, 1); ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN); ip->dst_addr = odp_cpu_to_be_32(args->appl.dstip); ip->src_addr = odp_cpu_to_be_32(args->appl.srcip); @@ -209,12 +210,13 @@ static odp_packet_t pack_udp_pkt(odp_pool_t pool) ip->tot_len = odp_cpu_to_be_16(args->appl.payload + ODPH_UDPHDR_LEN + ODPH_IPV4HDR_LEN); ip->proto = ODPH_IPPROTO_UDP; - seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xFFFF; - ip->id = odp_cpu_to_be_16(seq); + ip->id = 0; + ip->ttl = 64; ip->chksum = 0; - odph_ipv4_csum_update(pkt); + /* udp */ odp_packet_l4_offset_set(pkt, ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); + odp_packet_has_udp_set(pkt, 1); udp = (odph_udphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); udp->src_port = 0; udp->dst_port = 0; @@ -226,27 +228,60 @@ static odp_packet_t pack_udp_pkt(odp_pool_t pool) } /** - * Set up an icmp packet + * set up an udp packet + * + * @param pool Buffer pool to create packet in + * @param pkt_ref Reference UDP packet + * + * @return Handle of created packet + * @retval ODP_PACKET_INVALID Packet could not be created + */ +static odp_packet_t pack_udp_pkt(odp_pool_t pool, odp_packet_t pkt_ref) +{ + odp_packet_t pkt; + char *buf; + odph_ipv4hdr_t *ip; + unsigned short seq; + + pkt = odp_packet_alloc(pool, args->appl.payload + ODPH_UDPHDR_LEN + + ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); + + if (pkt == ODP_PACKET_INVALID) + return pkt; + + buf = (char *)odp_packet_data(pkt); + odp_memcpy(buf, odp_packet_data(pkt_ref), + args->appl.payload + ODPH_UDPHDR_LEN + + ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); + + /*Update IP ID and checksum*/ + ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN); + seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xFFFF; + ip->id = odp_cpu_to_be_16(seq); + ip->chksum = odph_chksum(ip, ODPH_IPV4HDR_LEN); + + return pkt; +} + +/** + * Set up an icmp packet reference * * @param pool Buffer pool to create packet in * * @return Handle of created packet * @retval ODP_PACKET_INVALID Packet could not be created */ -static odp_packet_t pack_icmp_pkt(odp_pool_t pool) +static odp_packet_t setup_icmp_pkt_ref(odp_pool_t pool) { odp_packet_t pkt; char *buf; odph_ethhdr_t *eth; odph_ipv4hdr_t *ip; odph_icmphdr_t *icmp; - struct timeval tval; - uint8_t *tval_d; - unsigned short seq; args->appl.payload = 56; pkt = odp_packet_alloc(pool, args->appl.payload + ODPH_ICMPHDR_LEN + - ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); + ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); if (pkt == ODP_PACKET_INVALID) return pkt; @@ -265,18 +300,62 @@ static odp_packet_t pack_icmp_pkt(odp_pool_t pool) ip->dst_addr = odp_cpu_to_be_32(args->appl.dstip); ip->src_addr = odp_cpu_to_be_32(args->appl.srcip); ip->ver_ihl = ODPH_IPV4 << 4 | ODPH_IPV4HDR_IHL_MIN; + ip->ttl = 64; ip->tot_len = odp_cpu_to_be_16(args->appl.payload + ODPH_ICMPHDR_LEN + ODPH_IPV4HDR_LEN); ip->proto = ODPH_IPPROTO_ICMP; - seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xffff; - ip->id = odp_cpu_to_be_16(seq); + ip->id = 0; ip->chksum = 0; - odph_ipv4_csum_update(pkt); + /* icmp */ icmp = (odph_icmphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); icmp->type = ICMP_ECHO; icmp->code = 0; icmp->un.echo.id = 0; + icmp->un.echo.sequence = 0; + icmp->chksum = 0; + + return pkt; +} + +/** + * Set up an icmp packet + * + * @param pool Buffer pool to create packet in + * @param pkt_ref Reference ICMP packet + * + * @return Handle of created packet + * @retval ODP_PACKET_INVALID Packet could not be created + */ +static odp_packet_t pack_icmp_pkt(odp_pool_t pool, odp_packet_t pkt_ref) +{ + odp_packet_t pkt; + char *buf; + odph_ipv4hdr_t *ip; + odph_icmphdr_t *icmp; + struct timeval tval; + uint8_t *tval_d; + unsigned short seq; + + pkt = odp_packet_alloc(pool, args->appl.payload + ODPH_ICMPHDR_LEN + + ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); + + if (pkt == ODP_PACKET_INVALID) + return pkt; + + buf = (char *)odp_packet_data(pkt); + odp_memcpy(buf, odp_packet_data(pkt_ref), + args->appl.payload + ODPH_ICMPHDR_LEN + + ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); + + /* ip */ + ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN); + seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xffff; + ip->id = odp_cpu_to_be_16(seq); + ip->chksum = odph_chksum(ip, ODPH_IPV4HDR_LEN); + + /* icmp */ + icmp = (odph_icmphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); icmp->un.echo.sequence = ip->id; tval_d = (uint8_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN + ODPH_ICMPHDR_LEN); @@ -357,6 +436,7 @@ static int gen_send_thread(void *arg) thread_args_t *thr_args; odp_pktout_queue_t pktout; odp_packet_t pkt; + odp_packet_t pkt_ref = ODP_PACKET_INVALID; thr = odp_thread_id(); thr_args = arg; @@ -373,6 +453,21 @@ static int gen_send_thread(void *arg) return -1; } + if (args->appl.mode == APPL_MODE_UDP) { + pkt_ref = setup_udp_pkt_ref(thr_args->pool); + } else if (args->appl.mode == APPL_MODE_PING) { + pkt_ref = setup_icmp_pkt_ref(thr_args->pool); + } else { + EXAMPLE_ERR(" [%02i] Error: invalid processing mode %d\n", + thr, args->appl.mode); + return -1; + } + if (pkt_ref == ODP_PACKET_INVALID) { + EXAMPLE_ERR(" [%2i] Error: reference packet creation failed\n", + thr); + return -1; + } + printf(" [%02i] created mode: SEND\n", thr); odp_barrier_wait(&barrier); @@ -386,9 +481,9 @@ static int gen_send_thread(void *arg) pkt = ODP_PACKET_INVALID; if (args->appl.mode == APPL_MODE_UDP) - pkt = pack_udp_pkt(thr_args->pool); + pkt = pack_udp_pkt(thr_args->pool, pkt_ref); else if (args->appl.mode == APPL_MODE_PING) - pkt = pack_icmp_pkt(thr_args->pool); + pkt = pack_icmp_pkt(thr_args->pool, pkt_ref); if (pkt == ODP_PACKET_INVALID) { /* Thread gives up as soon as it sees the pool empty. @@ -440,6 +535,7 @@ static int gen_send_thread(void *arg) args->appl.timeout--; } } + odp_packet_free(pkt_ref); return 0; } From patchwork Fri Mar 24 14:01:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Pricope X-Patchwork-Id: 95945 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp62941qgd; Fri, 24 Mar 2017 07:07:22 -0700 (PDT) X-Received: by 10.200.4.30 with SMTP id v30mr7799273qtg.171.1490364442286; Fri, 24 Mar 2017 07:07:22 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f6si1982293qtd.98.2017.03.24.07.07.22; Fri, 24 Mar 2017 07:07:22 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id EAA9963E1B; Fri, 24 Mar 2017 14:07:21 +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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 771AC642D2; Fri, 24 Mar 2017 14:03:43 +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 41B96642D3; Fri, 24 Mar 2017 14:03:32 +0000 (UTC) Received: from mail-wr0-f169.google.com (mail-wr0-f169.google.com [209.85.128.169]) by lists.linaro.org (Postfix) with ESMTPS id 6890F642CF for ; Fri, 24 Mar 2017 14:02:06 +0000 (UTC) Received: by mail-wr0-f169.google.com with SMTP id y90so2398800wrb.0 for ; Fri, 24 Mar 2017 07:02:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uISijGYn+6fuJTLmfbVwoSPq9tEBVx2pNtxDm1LDWmA=; b=kywLXFvfYdCE1O8xmbd+F09i/RR7QVL53WccqbpfhtIICfddX6yO9IhLXjVJd9JWJ1 JQan1cZJP7VEA3PfJHIfZyWlUe3FVdMD+4jETstj8aMmFS+npiihtfj7PnDr11Q9nZ6+ FHNVTFEXuODp3v0aaih0dQiiCIa4RqRGIlm4glKUDPtCcJ0cgIU3Xpl7GLD7AtN9AsTv iyyUnpZIRJlUeAzPzCfEamE/WjI3u19WQWiRe6BKlq+R5EH1baQS++FEedWw7GN/9WAx d48pD2YRtj7qzjB+m8iudb6qsZ/Sv4j05hiknrzx9ws6GKo1BYWP07CafH5HKbRng3eY tiDQ== X-Gm-Message-State: AFeK/H2v1c5x2LBJH037SGq5F+DJV10VPGJX98qejXIdTu0+0gh2B8ZMHHyFCBMvcJEsAwRE5bw= X-Received: by 10.223.134.69 with SMTP id 5mr8472261wrw.22.1490364124478; Fri, 24 Mar 2017 07:02:04 -0700 (PDT) Received: from localhost.localdomain ([193.202.22.66]) by smtp.gmail.com with ESMTPSA id c8sm2979045wrd.57.2017.03.24.07.02.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 07:02:03 -0700 (PDT) From: Bogdan Pricope To: lng-odp@lists.linaro.org Date: Fri, 24 Mar 2017 16:01:39 +0200 Message-Id: <1490364102-13781-3-git-send-email-bogdan.pricope@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490364102-13781-1-git-send-email-bogdan.pricope@linaro.org> References: <1490364102-13781-1-git-send-email-bogdan.pricope@linaro.org> Subject: [lng-odp] [PATCHv4 2/5] test: generator: send UDP packets in bursts 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Signed-off-by: Bogdan Pricope --- example/generator/odp_generator.c | 75 ++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 21 deletions(-) -- 1.9.1 diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 816db88..a47bd94 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -26,6 +26,7 @@ #define POOL_NUM_PKT 2048 /* Number of packets in packet pool */ #define POOL_PKT_LEN 1856 /* Max packet length */ #define DEFAULT_PKT_INTERVAL 1000 /* Interval between each packet */ +#define MAX_UDP_TX_BURST 32 #define APPL_MODE_UDP 0 /**< UDP mode */ #define APPL_MODE_PING 1 /**< ping mode */ @@ -57,6 +58,8 @@ typedef struct { int timeout; /**< wait time */ int interval; /**< wait interval ms between sending each packet */ + int udp_tx_burst; /**< number of udp packets to send with one + API call */ } appl_args_t; /** @@ -431,11 +434,13 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool) static int gen_send_thread(void *arg) { int thr; - int ret; + int ret, i, j; odp_pktio_t pktio; thread_args_t *thr_args; odp_pktout_queue_t pktout; - odp_packet_t pkt; + odp_packet_t pkt_array[MAX_UDP_TX_BURST]; + int pkt_array_size; + int burst_start, burst_size; odp_packet_t pkt_ref = ODP_PACKET_INVALID; thr = odp_thread_id(); @@ -455,8 +460,10 @@ static int gen_send_thread(void *arg) if (args->appl.mode == APPL_MODE_UDP) { pkt_ref = setup_udp_pkt_ref(thr_args->pool); + pkt_array_size = args->appl.udp_tx_burst; } else if (args->appl.mode == APPL_MODE_PING) { pkt_ref = setup_icmp_pkt_ref(thr_args->pool); + pkt_array_size = 1; } else { EXAMPLE_ERR(" [%02i] Error: invalid processing mode %d\n", thr, args->appl.mode); @@ -478,32 +485,47 @@ static int gen_send_thread(void *arg) (unsigned int)args->appl.number) break; - pkt = ODP_PACKET_INVALID; - - if (args->appl.mode == APPL_MODE_UDP) - pkt = pack_udp_pkt(thr_args->pool, pkt_ref); - else if (args->appl.mode == APPL_MODE_PING) - pkt = pack_icmp_pkt(thr_args->pool, pkt_ref); - - if (pkt == ODP_PACKET_INVALID) { - /* Thread gives up as soon as it sees the pool empty. - * Depending on pool size and transmit latency, it may - * be normal that pool gets empty sometimes. */ - EXAMPLE_ERR(" [%2i] alloc_single failed\n", thr); + if (args->appl.mode == APPL_MODE_UDP) { + for (i = 0; i < pkt_array_size; i++) { + pkt_array[i] = pack_udp_pkt(thr_args->pool, + pkt_ref); + if (!odp_packet_is_valid(pkt_array[i])) + break; + } + if (i != pkt_array_size) { + EXAMPLE_ERR(" [%2i] alloc_multi failed\n", + thr); + for (j = 0; j < i; j++) + odp_packet_free(pkt_array[j]); + break; + } + } else if (args->appl.mode == APPL_MODE_PING) { + pkt_array[0] = pack_icmp_pkt(thr_args->pool, pkt_ref); + if (!odp_packet_is_valid(pkt_array[0])) { + EXAMPLE_ERR(" [%2i] alloc_single failed\n", + thr); + break; + } + } else { break; } - for (;;) { - ret = odp_pktout_send(pktout, &pkt, 1); - if (ret == 1) { + for (burst_start = 0, burst_size = pkt_array_size;;) { + ret = odp_pktout_send(pktout, &pkt_array[burst_start], + burst_size); + if (ret == burst_size) { break; - } else if (ret == 0) { - odp_atomic_add_u64(&counters.tx_drops, 1); + } else if (ret >= 0 && ret < burst_size) { + odp_atomic_add_u64(&counters.tx_drops, + burst_size - ret); + burst_start += ret; + burst_size -= ret; odp_time_wait_ns(ODP_TIME_MSEC_IN_NS); continue; } EXAMPLE_ERR(" [%02i] packet send failed\n", thr); - odp_packet_free(pkt); + for (i = 0; i < burst_size; i++) + odp_packet_free(pkt_array[burst_start + i]); break; } @@ -1053,10 +1075,11 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) {"timeout", required_argument, NULL, 't'}, {"interval", required_argument, NULL, 'i'}, {"help", no_argument, NULL, 'h'}, + {"udp_tx_burst", required_argument, NULL, 'x'}, {NULL, 0, NULL, 0} }; - static const char *shortopts = "+I:a:b:s:d:p:i:m:n:t:w:c:h"; + static const char *shortopts = "+I:a:b:s:d:p:i:m:n:t:w:c:x:h"; /* let helper collect its own arguments (e.g. --odph_proc) */ odph_parse_options(argc, argv, shortopts, longopts); @@ -1066,6 +1089,7 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) appl_args->payload = 56; appl_args->timeout = -1; appl_args->interval = DEFAULT_PKT_INTERVAL; + appl_args->udp_tx_burst = 16; opterr = 0; /* do not issue errors on helper options */ @@ -1191,6 +1215,14 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) exit(EXIT_FAILURE); } break; + case 'x': + appl_args->udp_tx_burst = atoi(optarg); + if (appl_args->udp_tx_burst > MAX_UDP_TX_BURST) { + EXAMPLE_ERR("wrong UDP Tx burst size (max %d)\n", + MAX_UDP_TX_BURST); + exit(EXIT_FAILURE); + } + break; case 'h': usage(argv[0]); @@ -1285,6 +1317,7 @@ static void usage(char *progname) " default is to assign all\n" " -n, --count the number of packets to be send\n" " -c, --cpumask to set on cores\n" + " -x, --udp_tx_burst size of UDP TX burst\n" "\n", NO_PATH(progname), NO_PATH(progname) ); } From patchwork Fri Mar 24 14:01:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Pricope X-Patchwork-Id: 95946 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp63266qgd; Fri, 24 Mar 2017 07:07:57 -0700 (PDT) X-Received: by 10.55.20.100 with SMTP id e97mr8351902qkh.3.1490364477623; Fri, 24 Mar 2017 07:07:57 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id m23si770058qke.157.2017.03.24.07.07.57; Fri, 24 Mar 2017 07:07:57 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 4518B642C5; Fri, 24 Mar 2017 14:07:57 +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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, 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 C1F38642D9; Fri, 24 Mar 2017 14:03:45 +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 F2027642C8; Fri, 24 Mar 2017 14:03:37 +0000 (UTC) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by lists.linaro.org (Postfix) with ESMTPS id 59F01642D1 for ; Fri, 24 Mar 2017 14:02:08 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id t189so3062620wmt.1 for ; Fri, 24 Mar 2017 07:02:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VcJp3VUBRLgfNHuT7BuPSVYXvRJgLWk41K68bf3ePtA=; b=EGO9gn9ujPjY40CaFBbIaEb7m5whR8a8BDdFQNy2PGLqpnyt47WKxyQ7g4xm7Na2km Sdj2wxx3AainMl1Ol8W3ZCCj6bquygoXK774U66gPutdVgf0ePjg10whoHcbZkgDVE/5 BA31qT7qcdmAVSiVK2C+xrVPQG14noEeh/d26Vx+j7uRi92WxYfkW1I/kNq7lifAOvNj I/iYHV+KuNygu1otG8/zFXOSX45bfKQfIeFSpdEnM5V/HS0mP0LBsrN2ZJfR1icSaFTL g+WYJW7GcMXiGbfnkzVxuo2kVHNEgUvH1EWNQHcnn703j5OnpZ/08HSdek9I91v45Z7r zkfA== X-Gm-Message-State: AFeK/H0Y3RNryL518X1ypULx7Skb5snstYOkOUwYpXkV6VjqFON8Ots/4XTvh7yruEXW0z0KW43YE4L8 X-Received: by 10.28.209.75 with SMTP id i72mr3007177wmg.31.1490364126497; Fri, 24 Mar 2017 07:02:06 -0700 (PDT) Received: from localhost.localdomain ([193.202.22.66]) by smtp.gmail.com with ESMTPSA id c8sm2979045wrd.57.2017.03.24.07.02.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 07:02:06 -0700 (PDT) From: Bogdan Pricope To: lng-odp@lists.linaro.org Date: Fri, 24 Mar 2017 16:01:40 +0200 Message-Id: <1490364102-13781-4-git-send-email-bogdan.pricope@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490364102-13781-1-git-send-email-bogdan.pricope@linaro.org> References: <1490364102-13781-1-git-send-email-bogdan.pricope@linaro.org> Subject: [lng-odp] [PATCHv4 3/5] test: generator: receive packets in bursts 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Signed-off-by: Bogdan Pricope --- example/generator/odp_generator.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) -- 1.9.1 diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index a47bd94..34014d8 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -27,6 +27,7 @@ #define POOL_PKT_LEN 1856 /* Max packet length */ #define DEFAULT_PKT_INTERVAL 1000 /* Interval between each packet */ #define MAX_UDP_TX_BURST 32 +#define MAX_RX_BURST 32 #define APPL_MODE_UDP 0 /**< UDP mode */ #define APPL_MODE_PING 1 /**< ping mode */ @@ -638,8 +639,9 @@ static int gen_recv_thread(void *arg) int thr; odp_pktio_t pktio; thread_args_t *thr_args; - odp_packet_t pkt; - odp_event_t ev; + odp_packet_t pkts[MAX_RX_BURST], pkt; + odp_event_t events[MAX_RX_BURST]; + int pkt_cnt, ev_cnt, i; thr = odp_thread_id(); thr_args = arg; @@ -662,18 +664,24 @@ static int gen_recv_thread(void *arg) } /* Use schedule to get buf from any input queue */ - ev = odp_schedule(NULL, ODP_SCHED_WAIT); - - pkt = odp_packet_from_event(ev); - /* Drop packets with errors */ - if (odp_unlikely(odp_packet_has_error(pkt))) { - odp_packet_free(pkt); + ev_cnt = odp_schedule_multi(NULL, ODP_SCHED_WAIT, + events, MAX_RX_BURST); + if (ev_cnt == 0) continue; + for (i = 0, pkt_cnt = 0; i < ev_cnt; i++) { + pkt = odp_packet_from_event(events[i]); + + /* Drop packets with errors */ + if (odp_unlikely(odp_packet_has_error(pkt))) { + odp_packet_free(pkt); + continue; + } + pkts[pkt_cnt++] = pkt; } - print_pkts(thr, &pkt, 1); + print_pkts(thr, pkts, pkt_cnt); - odp_packet_free(pkt); + odp_packet_free_multi(pkts, pkt_cnt); } return 0; From patchwork Fri Mar 24 14:01:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Pricope X-Patchwork-Id: 95947 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp63672qgd; Fri, 24 Mar 2017 07:08:38 -0700 (PDT) X-Received: by 10.237.40.66 with SMTP id r60mr8552408qtd.42.1490364518782; Fri, 24 Mar 2017 07:08:38 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p89si1993942qtd.31.2017.03.24.07.08.38; Fri, 24 Mar 2017 07:08:38 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 57F0E63E15; Fri, 24 Mar 2017 14:08:38 +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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, 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 0990C642D1; Fri, 24 Mar 2017 14:03:49 +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 4F9DF642D4; Fri, 24 Mar 2017 14:03:41 +0000 (UTC) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by lists.linaro.org (Postfix) with ESMTPS id E30F0642D2 for ; Fri, 24 Mar 2017 14:02:10 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id u132so13867751wmg.0 for ; Fri, 24 Mar 2017 07:02:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Gi51UIsqnz3WFp3rQUH7GgnjUIQXnenV3Gqaaes7/AY=; b=T4F7jIhbxRgGh/C9oW+nJ09/sIxrYh5gjN1N0ypbzQ/2RSaeC+0Ii2wxHhaxAkABFe b0SUJMe47VFFA53yTyXe5J+Lyez/RNHRnDZDR3zGzeYaobrmQeKZXWqWqlDEm9SMR0JY /K7460tfcUOj2IIzNcekY/Szd+xsYFAM1Ye+eXzwu2FjzDXqnkYfawoRyCiVLSBsJnOJ hix+EKYWUb7KDFtnBQ/w25lUroj9/QCatCK+7eO+uTN8emU5WKBuzmyegNuv7l3RWa/7 PO/gkXh8ywfDP59n4a3bKffttThxC6m8OMytTBQ72V2qUdgXCIqX7k5CMRxUUFbCDVK9 GpYA== X-Gm-Message-State: AFeK/H1TvQpqZh0xxc3mNjFXmOyt0aUuYAAmHAYJvV/MMWLW9e+AVLp38xX66weH7Lm0Q4UaoRM+IslR X-Received: by 10.28.28.16 with SMTP id c16mr3497341wmc.38.1490364128747; Fri, 24 Mar 2017 07:02:08 -0700 (PDT) Received: from localhost.localdomain ([193.202.22.66]) by smtp.gmail.com with ESMTPSA id c8sm2979045wrd.57.2017.03.24.07.02.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 07:02:08 -0700 (PDT) From: Bogdan Pricope To: lng-odp@lists.linaro.org Date: Fri, 24 Mar 2017 16:01:41 +0200 Message-Id: <1490364102-13781-5-git-send-email-bogdan.pricope@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490364102-13781-1-git-send-email-bogdan.pricope@linaro.org> References: <1490364102-13781-1-git-send-email-bogdan.pricope@linaro.org> Subject: [lng-odp] [PATCHv4 4/5] test: generator: use multiple RX queue in receiving mode 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Signed-off-by: Bogdan Pricope --- example/generator/odp_generator.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) -- 1.9.1 diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 34014d8..df47857 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -382,9 +382,11 @@ static odp_packet_t pack_icmp_pkt(odp_pool_t pool, odp_packet_t pkt_ref) * @return The handle of the created pktio object. * @warning This routine aborts if the create is unsuccessful. */ -static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool) +static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, + unsigned num_rx_queues) { odp_pktio_t pktio; + odp_pktio_capability_t capa; int ret; odp_pktio_param_t pktio_param; odp_pktin_queue_param_t pktin_param; @@ -400,7 +402,16 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool) exit(EXIT_FAILURE); } + if (odp_pktio_capability(pktio, &capa)) { + EXAMPLE_ERR("Error: Failed to get interface capabilities %s\n", + dev); + exit(EXIT_FAILURE); + } + if (num_rx_queues > capa.max_input_queues) + num_rx_queues = capa.max_input_queues; + odp_pktin_queue_param_init(&pktin_param); + pktin_param.num_queues = num_rx_queues; pktin_param.queue_param.sched.sync = ODP_SCHED_SYNC_ATOMIC; if (odp_pktin_queue_config(pktio, &pktin_param)) { @@ -750,6 +761,7 @@ int main(int argc, char *argv[]) odph_odpthread_t thread_tbl[MAX_WORKERS]; odp_pool_t pool; int num_workers; + unsigned num_rx_queues; int i; odp_shm_t shm; odp_cpumask_t cpumask; @@ -873,8 +885,15 @@ int main(int argc, char *argv[]) pktio = malloc(sizeof(odp_pktio_t) * args->appl.if_count); + if (args->appl.mode == APPL_MODE_PING || + args->appl.mode == APPL_MODE_UDP) + num_rx_queues = 1; + else + num_rx_queues = num_workers; + for (i = 0; i < args->appl.if_count; ++i) - pktio[i] = create_pktio(args->appl.if_names[i], pool); + pktio[i] = create_pktio(args->appl.if_names[i], pool, + num_rx_queues); /* Create and init worker threads */ memset(thread_tbl, 0, sizeof(thread_tbl)); From patchwork Fri Mar 24 14:01:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Pricope X-Patchwork-Id: 95948 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp63812qgd; Fri, 24 Mar 2017 07:08:55 -0700 (PDT) X-Received: by 10.55.16.230 with SMTP id 99mr7162942qkq.171.1490364534959; Fri, 24 Mar 2017 07:08:54 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id h57si1972686qtf.244.2017.03.24.07.08.54; Fri, 24 Mar 2017 07:08:54 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id A6EF563E0F; Fri, 24 Mar 2017 14:08:54 +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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 945F5642E0; Fri, 24 Mar 2017 14:03:58 +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 A5056642E5; Fri, 24 Mar 2017 14:03:50 +0000 (UTC) Received: from mail-wr0-f170.google.com (mail-wr0-f170.google.com [209.85.128.170]) by lists.linaro.org (Postfix) with ESMTPS id 6B91E63CAB for ; Fri, 24 Mar 2017 14:02:13 +0000 (UTC) Received: by mail-wr0-f170.google.com with SMTP id l43so2374145wre.1 for ; Fri, 24 Mar 2017 07:02:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LxhlWTZuYu0Mst4EaMSXnaIL6lbIde0ZdrJIw42QfpE=; b=m5mtYGm6ChL/+25YML9kCa3cfX0L/uLRAO8uRLQ7w361Dckh+mPJ7J1LormIhMf8wH eRDE/P9k1YeqJBHAyNj0y2ljia9qgqwduw61NtvlxUXNpDRFSFeLxNZlzM8aFiOElho1 0dTlgl0jXkNQKI1iAnV0ZurB5HO1FhVhBXywYio/yiPWyDn30TUfd+SdJHaF6oucHGss xZkNDiGBYK4eas31M39UZXCNhdJWroH7e2krsH8jLbqgMbl+5gU3900CaG/tEt0qFPOl tKPf7I/c88Y1EFd01qJWP7Nl5Y8Goq0/RT1nVMcrltrxfgfh4zS30RrZINeQ0+6rmdAn UMWQ== X-Gm-Message-State: AFeK/H2IThMIA6ngXXpL+Mlo7kO5crzjYN6giK8tmGQCobY/8GPPe9/v2lOJv7nbJhS0tNh/Vlk= X-Received: by 10.223.162.155 with SMTP id s27mr7500097wra.159.1490364131304; Fri, 24 Mar 2017 07:02:11 -0700 (PDT) Received: from localhost.localdomain ([193.202.22.66]) by smtp.gmail.com with ESMTPSA id c8sm2979045wrd.57.2017.03.24.07.02.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 07:02:10 -0700 (PDT) From: Bogdan Pricope To: lng-odp@lists.linaro.org Date: Fri, 24 Mar 2017 16:01:42 +0200 Message-Id: <1490364102-13781-6-git-send-email-bogdan.pricope@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490364102-13781-1-git-send-email-bogdan.pricope@linaro.org> References: <1490364102-13781-1-git-send-email-bogdan.pricope@linaro.org> Subject: [lng-odp] [PATCHv4 5/5] test: generator: use multiple TX queues in send UDP mode 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Signed-off-by: Bogdan Pricope --- example/generator/odp_generator.c | 136 +++++++++++++++++++++++--------------- 1 file changed, 84 insertions(+), 52 deletions(-) -- 1.9.1 diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index df47857..c284ecb 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -39,6 +39,17 @@ /** Get rid of path in filename - only for unix-type paths using '/' */ #define NO_PATH(file_name) (strrchr((file_name), '/') ? \ strrchr((file_name), '/') + 1 : (file_name)) + +/** + * Interfaces + */ + +typedef struct { + odp_pktio_t pktio; + odp_pktout_queue_t pktout[MAX_WORKERS]; + unsigned pktout_count; +} interface_t; + /** * Parsed command line application arguments */ @@ -78,7 +89,7 @@ static struct { /** * Thread specific arguments */ typedef struct { - char *pktio_dev; /**< Interface name to use */ + odp_pktout_queue_t pktout; /**< Packet output queue to use*/ odp_pool_t pool; /**< Pool for packet IO */ odp_timer_pool_t tp; /**< Timer pool handle */ odp_queue_t tq; /**< Queue for timeouts */ @@ -382,30 +393,33 @@ static odp_packet_t pack_icmp_pkt(odp_pool_t pool, odp_packet_t pkt_ref) * @return The handle of the created pktio object. * @warning This routine aborts if the create is unsuccessful. */ -static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, - unsigned num_rx_queues) +static int create_pktio(const char *dev, odp_pool_t pool, + unsigned num_rx_queues, + unsigned num_tx_queues, + interface_t *itf) { - odp_pktio_t pktio; odp_pktio_capability_t capa; int ret; odp_pktio_param_t pktio_param; odp_pktin_queue_param_t pktin_param; + odp_pktout_queue_param_t pktout_param; + odp_pktio_op_mode_t pktout_mode; odp_pktio_param_init(&pktio_param); pktio_param.in_mode = ODP_PKTIN_MODE_SCHED; /* Open a packet IO instance */ - pktio = odp_pktio_open(dev, pool, &pktio_param); + itf->pktio = odp_pktio_open(dev, pool, &pktio_param); - if (pktio == ODP_PKTIO_INVALID) { + if (itf->pktio == ODP_PKTIO_INVALID) { EXAMPLE_ERR("Error: pktio create failed for %s\n", dev); - exit(EXIT_FAILURE); + return -1; } - if (odp_pktio_capability(pktio, &capa)) { + if (odp_pktio_capability(itf->pktio, &capa)) { EXAMPLE_ERR("Error: Failed to get interface capabilities %s\n", dev); - exit(EXIT_FAILURE); + return -1; } if (num_rx_queues > capa.max_input_queues) num_rx_queues = capa.max_input_queues; @@ -414,27 +428,44 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, pktin_param.num_queues = num_rx_queues; pktin_param.queue_param.sched.sync = ODP_SCHED_SYNC_ATOMIC; - if (odp_pktin_queue_config(pktio, &pktin_param)) { + if (odp_pktin_queue_config(itf->pktio, &pktin_param)) { EXAMPLE_ERR("Error: pktin queue config failed for %s\n", dev); - exit(EXIT_FAILURE); + return -1; + } + + pktout_mode = ODP_PKTIO_OP_MT_UNSAFE; + if (num_tx_queues > capa.max_output_queues) { + num_tx_queues = capa.max_output_queues; + pktout_mode = ODP_PKTIO_OP_MT; } - if (odp_pktout_queue_config(pktio, NULL)) { + odp_pktout_queue_param_init(&pktout_param); + pktout_param.num_queues = num_tx_queues; + pktout_param.op_mode = pktout_mode; + + if (odp_pktout_queue_config(itf->pktio, &pktout_param)) { EXAMPLE_ERR("Error: pktout queue config failed for %s\n", dev); - exit(EXIT_FAILURE); + return -1; } - ret = odp_pktio_start(pktio); + ret = odp_pktio_start(itf->pktio); if (ret) EXAMPLE_ABORT("Error: unable to start %s\n", dev); + itf->pktout_count = num_tx_queues; + if (odp_pktout_queue(itf->pktio, itf->pktout, itf->pktout_count) != + (int)itf->pktout_count) { + EXAMPLE_ERR("Error: failed to get output queues for %s\n", dev); + return -1; + } + printf(" created pktio:%02" PRIu64 ", dev:%s, queue mode (ATOMIC queues)\n" " default pktio%02" PRIu64 "\n", - odp_pktio_to_u64(pktio), dev, - odp_pktio_to_u64(pktio)); + odp_pktio_to_u64(itf->pktio), dev, + odp_pktio_to_u64(itf->pktio)); - return pktio; + return 0; } /** @@ -447,7 +478,6 @@ static int gen_send_thread(void *arg) { int thr; int ret, i, j; - odp_pktio_t pktio; thread_args_t *thr_args; odp_pktout_queue_t pktout; odp_packet_t pkt_array[MAX_UDP_TX_BURST]; @@ -458,17 +488,7 @@ static int gen_send_thread(void *arg) thr = odp_thread_id(); thr_args = arg; - pktio = odp_pktio_lookup(thr_args->pktio_dev); - if (pktio == ODP_PKTIO_INVALID) { - EXAMPLE_ERR(" [%02i] Error: lookup of pktio %s failed\n", - thr, thr_args->pktio_dev); - return -1; - } - - if (odp_pktout_queue(pktio, &pktout, 1) != 1) { - EXAMPLE_ERR(" [%02i] Error: no output queue\n", thr); - return -1; - } + pktout = thr_args->pktout; if (args->appl.mode == APPL_MODE_UDP) { pkt_ref = setup_udp_pkt_ref(thr_args->pool); @@ -648,21 +668,12 @@ static void print_pkts(int thr, odp_packet_t pkt_tbl[], unsigned len) static int gen_recv_thread(void *arg) { int thr; - odp_pktio_t pktio; - thread_args_t *thr_args; odp_packet_t pkts[MAX_RX_BURST], pkt; odp_event_t events[MAX_RX_BURST]; int pkt_cnt, ev_cnt, i; thr = odp_thread_id(); - thr_args = arg; - - pktio = odp_pktio_lookup(thr_args->pktio_dev); - if (pktio == ODP_PKTIO_INVALID) { - EXAMPLE_ERR(" [%02i] Error: lookup of pktio %s failed\n", - thr, thr_args->pktio_dev); - return -1; - } + (void)arg; printf(" [%02i] created mode: RECEIVE\n", thr); odp_barrier_wait(&barrier); @@ -761,7 +772,7 @@ int main(int argc, char *argv[]) odph_odpthread_t thread_tbl[MAX_WORKERS]; odp_pool_t pool; int num_workers; - unsigned num_rx_queues; + unsigned num_rx_queues, num_tx_queues; int i; odp_shm_t shm; odp_cpumask_t cpumask; @@ -772,7 +783,7 @@ int main(int argc, char *argv[]) odp_pool_t tmop; odp_queue_t tq; odp_event_t ev; - odp_pktio_t *pktio; + interface_t *ifs; odp_instance_t instance; odph_odpthread_params_t thr_params; @@ -883,7 +894,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - pktio = malloc(sizeof(odp_pktio_t) * args->appl.if_count); + ifs = malloc(sizeof(interface_t) * args->appl.if_count); if (args->appl.mode == APPL_MODE_PING || args->appl.mode == APPL_MODE_UDP) @@ -891,9 +902,22 @@ int main(int argc, char *argv[]) else num_rx_queues = num_workers; + if (args->appl.mode == APPL_MODE_PING || + args->appl.mode == APPL_MODE_RCV) + num_tx_queues = 1; + else { + num_tx_queues = num_workers / args->appl.if_count; + if (num_workers % args->appl.if_count) + num_tx_queues++; + } + for (i = 0; i < args->appl.if_count; ++i) - pktio[i] = create_pktio(args->appl.if_names[i], pool, - num_rx_queues); + if (create_pktio(args->appl.if_names[i], pool, num_rx_queues, + num_tx_queues, &ifs[i])) { + EXAMPLE_ERR("Error: create interface %s failed.\n", + args->appl.if_names[i]); + exit(EXIT_FAILURE); + } /* Create and init worker threads */ memset(thread_tbl, 0, sizeof(thread_tbl)); @@ -919,7 +943,7 @@ int main(int argc, char *argv[]) EXAMPLE_ERR("queue_create failed\n"); abort(); } - args->thread[1].pktio_dev = args->appl.if_names[0]; + (void)args->thread[1].pktout; /* Not used*/ args->thread[1].pool = pool; args->thread[1].tp = tp; args->thread[1].tq = tq; @@ -948,7 +972,7 @@ int main(int argc, char *argv[]) EXAMPLE_ERR("queue_create failed\n"); abort(); } - args->thread[0].pktio_dev = args->appl.if_names[0]; + args->thread[0].pktout = ifs[0].pktout[0]; args->thread[0].pool = pool; args->thread[0].tp = tp; args->thread[0].tq = tq; @@ -974,14 +998,22 @@ int main(int argc, char *argv[]) } else { int cpu = odp_cpumask_first(&cpumask); + for (i = 0; i < num_workers; ++i) { odp_cpumask_t thd_mask; int (*thr_run_func)(void *); - int if_idx; + int if_idx, pktout_idx; - if_idx = i % args->appl.if_count; + if (args->appl.mode == APPL_MODE_RCV) + (void)args->thread[i].pktout; /*not used*/ + else { + if_idx = i % args->appl.if_count; + pktout_idx = (i / args->appl.if_count) % + ifs[if_idx].pktout_count; - args->thread[i].pktio_dev = args->appl.if_names[if_idx]; + args->thread[i].pktout = + ifs[if_idx].pktout[pktout_idx]; + } tq = odp_queue_create("", NULL); if (tq == ODP_QUEUE_INVALID) { EXAMPLE_ERR("queue_create failed\n"); @@ -1035,7 +1067,7 @@ int main(int argc, char *argv[]) odph_odpthreads_join(&thread_tbl[i]); for (i = 0; i < args->appl.if_count; ++i) - odp_pktio_stop(pktio[i]); + odp_pktio_stop(ifs[i].pktio); for (i = 0; i < num_workers; ++i) { odp_timer_cancel(args->thread[i].tim, &ev); @@ -1054,8 +1086,8 @@ int main(int argc, char *argv[]) } for (i = 0; i < args->appl.if_count; ++i) - odp_pktio_close(pktio[i]); - free(pktio); + odp_pktio_close(ifs[i].pktio); + free(ifs); free(args->appl.if_names); free(args->appl.if_str); if (0 != odp_pool_destroy(pool))