From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 1A7CBA6A for ; Mon, 2 Mar 2015 20:02:32 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 02 Mar 2015 10:59:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,676,1418112000"; d="scan'208";a="674042534" Received: from irsmsx106.ger.corp.intel.com ([163.33.3.31]) by fmsmga001.fm.intel.com with ESMTP; 02 Mar 2015 11:02:21 -0800 Received: from irsmsx109.ger.corp.intel.com ([169.254.13.103]) by IRSMSX106.ger.corp.intel.com ([169.254.8.235]) with mapi id 14.03.0195.001; Mon, 2 Mar 2015 19:02:19 +0000 From: "Butler, Siobhan A" To: "Mcnamara, John" , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH 1/3] examples/skeleton: minor refactoring to help documentation Thread-Index: AQHQUTPzD4C9hf78Y0iAspaBhpdX+J0JlEUA Date: Mon, 2 Mar 2015 19:02:18 +0000 Message-ID: <0C5AFCA4B3408848ADF2A3073F7D8CC86D51AA0B@IRSMSX109.ger.corp.intel.com> References: <1424893562-8740-1-git-send-email-john.mcnamara@intel.com> <1424893562-8740-2-git-send-email-john.mcnamara@intel.com> In-Reply-To: <1424893562-8740-2-git-send-email-john.mcnamara@intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH 1/3] examples/skeleton: minor refactoring to help documentation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Mar 2015 19:02:33 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of John McNamara > Sent: Wednesday, February 25, 2015 7:46 PM > To: dev@dpdk.org > Subject: [dpdk-dev] [PATCH 1/3] examples/skeleton: minor refactoring to > help documentation >=20 > Minor refactoring and comments to make the sample app and code > examples clearer for the sample app guide. >=20 > Signed-off-by: John McNamara > --- > examples/skeleton/basicfwd.c | 77 > +++++++++++++++++++++++++++++++----------- > 1 files changed, 57 insertions(+), 20 deletions(-) >=20 > diff --git a/examples/skeleton/basicfwd.c b/examples/skeleton/basicfwd.c > index 6aa931e..1bce6e7 100644 > --- a/examples/skeleton/basicfwd.c > +++ b/examples/skeleton/basicfwd.c > @@ -1,7 +1,7 @@ > /*- > * BSD LICENSE > * > - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. > + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > @@ -48,12 +48,14 @@ > #define BURST_SIZE 32 >=20 > static const struct rte_eth_conf port_conf_default =3D { > - .rxmode =3D { .max_rx_pkt_len =3D ETHER_MAX_LEN, }, > + .rxmode =3D { .max_rx_pkt_len =3D ETHER_MAX_LEN } > }; >=20 > +/* basicfwd.c: Basic DPDK skeleton forwarding example. */ > + > /* > - * Initialises a given port using global settings and with the rx buffer= s > - * coming from the mbuf_pool passed as parameter > + * Initializes a given port using global settings and with the RX > + buffers > + * coming from the mbuf_pool passed as a parameter. > */ > static inline int > port_init(uint8_t port, struct rte_mempool *mbuf_pool) @@ -66,10 +68,12 > @@ port_init(uint8_t port, struct rte_mempool *mbuf_pool) > if (port >=3D rte_eth_dev_count()) > return -1; >=20 > + /* Configure the Ethernet device. */ > retval =3D rte_eth_dev_configure(port, rx_rings, tx_rings, > &port_conf); > if (retval !=3D 0) > return retval; >=20 > + /* Allocate and set up 1 RX queue per Ethernet port. */ > for (q =3D 0; q < rx_rings; q++) { > retval =3D rte_eth_rx_queue_setup(port, q, RX_RING_SIZE, > rte_eth_dev_socket_id(port), NULL, > mbuf_pool); @@ -77,6 +81,7 @@ port_init(uint8_t port, struct rte_mempool > *mbuf_pool) > return retval; > } >=20 > + /* Allocate and set up 1 TX queue per Ethernet port. */ > for (q =3D 0; q < tx_rings; q++) { > retval =3D rte_eth_tx_queue_setup(port, q, TX_RING_SIZE, > rte_eth_dev_socket_id(port), NULL); @@ - > 84,33 +89,41 @@ port_init(uint8_t port, struct rte_mempool *mbuf_pool) > return retval; > } >=20 > - retval =3D rte_eth_dev_start(port); > + /* Start the Ethernet port. */ > + retval =3D rte_eth_dev_start(port); > if (retval < 0) > return retval; >=20 > + /* Display the port MAC address. */ > struct ether_addr addr; > rte_eth_macaddr_get(port, &addr); > - printf("Port %u MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8 > - " %02"PRIx8" %02"PRIx8" %02"PRIx8"\n", > + printf("Port %u MAC: %02" PRIx8 " %02" PRIx8 " %02" PRIx8 > + " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 "\n", > (unsigned)port, > addr.addr_bytes[0], addr.addr_bytes[1], > addr.addr_bytes[2], addr.addr_bytes[3], > addr.addr_bytes[4], addr.addr_bytes[5]); >=20 > + /* Enable RX in promiscuous mode for the Ethernet device. */ > rte_eth_promiscuous_enable(port); >=20 > return 0; > } >=20 > /* > - * Main thread that does the work, reading from INPUT_PORT > - * and writing to OUTPUT_PORT > + * The lcore main. This is the main thread that does the work, reading > + from > + * an input port and writing to an output port. > */ > -static __attribute__((noreturn)) void > +static __attribute__((noreturn)) void > lcore_main(void) > { > const uint8_t nb_ports =3D rte_eth_dev_count(); > uint8_t port; > + > + /* > + * Check that the port is on the same NUMA node as the polling > thread > + * for best performance. > + */ > for (port =3D 0; port < nb_ports; port++) > if (rte_eth_dev_socket_id(port) > 0 && > rte_eth_dev_socket_id(port) !=3D > @@ -121,15 +134,28 @@ lcore_main(void) >=20 > printf("\nCore %u forwarding packets. [Ctrl+C to quit]\n", > rte_lcore_id()); > + > + /* Run until the application is quit or killed. */ > for (;;) { > + /* > + * Receive packets on a port and forward them on the paired > + * port. The mapping is 0 -> 1, 1 -> 0, 2 -> 3, 3 -> 2, etc. > + */ > for (port =3D 0; port < nb_ports; port++) { > + > + /* Get burst of RX packets, from first port of pair. */ > struct rte_mbuf *bufs[BURST_SIZE]; > const uint16_t nb_rx =3D rte_eth_rx_burst(port, 0, > bufs, BURST_SIZE); > + > if (unlikely(nb_rx =3D=3D 0)) > continue; > + > + /* Send burst of TX packets, to second port of pair. */ > const uint16_t nb_tx =3D rte_eth_tx_burst(port ^ 1, 0, > bufs, nb_rx); > + > + /* Free any unsent packets. */ > if (unlikely(nb_tx < nb_rx)) { > uint16_t buf; > for (buf =3D nb_tx; buf < nb_rx; buf++) @@ - > 139,7 +165,10 @@ lcore_main(void) > } > } >=20 > -/* Main function, does initialisation and calls the per-lcore functions = */ > +/* > + * The main function, which does initialization and calls the per-lcore > + * functions. > + */ > int > main(int argc, char *argv[]) > { > @@ -147,36 +176,44 @@ main(int argc, char *argv[]) > unsigned nb_ports; > uint8_t portid; >=20 > - /* init EAL */ > + /* Initialize the Environment Abstraction Layer (EAL). */ > int ret =3D rte_eal_init(argc, argv); > if (ret < 0) > rte_exit(EXIT_FAILURE, "Error with EAL initialization\n"); > + > argc -=3D ret; > argv +=3D ret; >=20 > + /* Check that there is an even number of ports to send/receive on. > */ > nb_ports =3D rte_eth_dev_count(); > if (nb_ports < 2 || (nb_ports & 1)) > rte_exit(EXIT_FAILURE, "Error: number of ports must be > even\n"); >=20 > - mbuf_pool =3D rte_mempool_create("MBUF_POOL", NUM_MBUFS * > nb_ports, > - MBUF_SIZE, MBUF_CACHE_SIZE, > + /* Creates a new mempool in memory to hold the mbufs. */ > + mbuf_pool =3D rte_mempool_create("MBUF_POOL", > + NUM_MBUFS * nb_ports, > + MBUF_SIZE, > + MBUF_CACHE_SIZE, > sizeof(struct rte_pktmbuf_pool_private), > rte_pktmbuf_pool_init, NULL, > - rte_pktmbuf_init, NULL, > - rte_socket_id(), 0); > + rte_pktmbuf_init, NULL, > + rte_socket_id(), > + 0); > + > if (mbuf_pool =3D=3D NULL) > rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n"); >=20 > - /* initialize all ports */ > + /* Initialize all ports. */ > for (portid =3D 0; portid < nb_ports; portid++) > if (port_init(portid, mbuf_pool) !=3D 0) > - rte_exit(EXIT_FAILURE, "Cannot init port > %"PRIu8"\n", > + rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 > "\n", > portid); >=20 > if (rte_lcore_count() > 1) > - printf("\nWARNING: Too much enabled lcores - App uses > only 1 lcore\n"); > + printf("\nWARNING: Too many lcores enabled. Only 1 > used.\n"); >=20 > - /* call lcore_main on master core only */ > + /* Call lcore_main on the master core only. */ > lcore_main(); > + > return 0; > } > -- > 1.7.4.1 Acked-by: Siobhan Butler