Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/5348/?format=api
https://patches.dpdk.org/api/patches/5348/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/1433941641-19405-4-git-send-email-bruce.richardson@intel.com/", "project": { "id": 1, "url": "https://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<1433941641-19405-4-git-send-email-bruce.richardson@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1433941641-19405-4-git-send-email-bruce.richardson@intel.com", "date": "2015-06-10T13:07:18", "name": "[dpdk-dev,RFC-PATCH-v3,3/6] example app showing pktdevs used in a chain", "commit_ref": null, "pull_url": null, "state": "rfc", "archived": true, "hash": "4d7f91d977d2d623cfb737777d548740dcb1fe8d", "submitter": { "id": 20, "url": "https://patches.dpdk.org/api/people/20/?format=api", "name": "Bruce Richardson", "email": "bruce.richardson@intel.com" }, "delegate": null, "mbox": "https://patches.dpdk.org/project/dpdk/patch/1433941641-19405-4-git-send-email-bruce.richardson@intel.com/mbox/", "series": [], "comments": "https://patches.dpdk.org/api/patches/5348/comments/", "check": "pending", "checks": "https://patches.dpdk.org/api/patches/5348/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@dpdk.org", "Delivered-To": "patchwork@dpdk.org", "Received": [ "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 113EF5FEB;\n\tWed, 10 Jun 2015 15:07:30 +0200 (CEST)", "from mga14.intel.com (mga14.intel.com [192.55.52.115])\n\tby dpdk.org (Postfix) with ESMTP id 79A4F5A9D\n\tfor <dev@dpdk.org>; Wed, 10 Jun 2015 15:07:28 +0200 (CEST)", "from fmsmga003.fm.intel.com ([10.253.24.29])\n\tby fmsmga103.fm.intel.com with ESMTP; 10 Jun 2015 06:07:28 -0700", "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby FMSMGA003.fm.intel.com with ESMTP; 10 Jun 2015 06:07:25 -0700", "from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com\n\t[10.237.217.45])\n\tby irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id\n\tt5AD7PRS010131; Wed, 10 Jun 2015 14:07:25 +0100", "from sivswdev01.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev01.ir.intel.com with ESMTP id t5AD7Pbw019486;\n\tWed, 10 Jun 2015 14:07:25 +0100", "(from bricha3@localhost)\n\tby sivswdev01.ir.intel.com with id t5AD7PZU019480;\n\tWed, 10 Jun 2015 14:07:25 +0100" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"5.13,587,1427785200\"; d=\"scan'208\";a=\"506102618\"", "From": "Bruce Richardson <bruce.richardson@intel.com>", "To": "dev@dpdk.org", "Date": "Wed, 10 Jun 2015 14:07:18 +0100", "Message-Id": "<1433941641-19405-4-git-send-email-bruce.richardson@intel.com>", "X-Mailer": "git-send-email 1.7.4.1", "In-Reply-To": "<1433941641-19405-1-git-send-email-bruce.richardson@intel.com>", "References": "<20150519113112.GA10700@bricha3-MOBL3>\n\t<1433941641-19405-1-git-send-email-bruce.richardson@intel.com>", "Subject": "[dpdk-dev] [RFC-PATCH-v3 3/6] example app showing pktdevs used in a\n\tchain", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "patches and discussions about DPDK <dev.dpdk.org>", "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://dpdk.org/ml/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "This is a trivial example showing code which is using ethdevs and rings\nin a neutral manner, with the same piece of pipeline code passing mbufs\nalong a chain without ever having to query its source or destination\ntype.\n\nSigned-off-by: Bruce Richardson <bruce.richardson@intel.com>\n---\n examples/pktdev-chain/Makefile | 57 ++++++++++\n examples/pktdev-chain/basicfwd.c | 221 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 278 insertions(+)\n create mode 100644 examples/pktdev-chain/Makefile\n create mode 100644 examples/pktdev-chain/basicfwd.c", "diff": "diff --git a/examples/pktdev-chain/Makefile b/examples/pktdev-chain/Makefile\nnew file mode 100644\nindex 0000000..4a5d99f\n--- /dev/null\n+++ b/examples/pktdev-chain/Makefile\n@@ -0,0 +1,57 @@\n+# BSD LICENSE\n+#\n+# Copyright(c) 2015 Intel Corporation. All rights reserved.\n+# All rights reserved.\n+#\n+# Redistribution and use in source and binary forms, with or without\n+# modification, are permitted provided that the following conditions\n+# are met:\n+#\n+# * Redistributions of source code must retain the above copyright\n+# notice, this list of conditions and the following disclaimer.\n+# * Redistributions in binary form must reproduce the above copyright\n+# notice, this list of conditions and the following disclaimer in\n+# the documentation and/or other materials provided with the\n+# distribution.\n+# * Neither the name of Intel Corporation nor the names of its\n+# contributors may be used to endorse or promote products derived\n+# from this software without specific prior written permission.\n+#\n+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+\n+ifeq ($(RTE_SDK),)\n+$(error \"Please define RTE_SDK environment variable\")\n+endif\n+\n+# Default target, can be overridden by command line or environment\n+RTE_TARGET ?= x86_64-native-linuxapp-gcc\n+\n+include $(RTE_SDK)/mk/rte.vars.mk\n+\n+# binary name\n+APP = basicfwd\n+\n+# all source are stored in SRCS-y\n+SRCS-y := basicfwd.c\n+\n+CFLAGS += $(WERROR_FLAGS)\n+\n+# workaround for a gcc bug with noreturn attribute\n+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603\n+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)\n+CFLAGS_main.o += -Wno-return-type\n+endif\n+\n+EXTRA_CFLAGS += -O3 -g -Wfatal-errors\n+\n+include $(RTE_SDK)/mk/rte.extapp.mk\ndiff --git a/examples/pktdev-chain/basicfwd.c b/examples/pktdev-chain/basicfwd.c\nnew file mode 100644\nindex 0000000..be2b3f1\n--- /dev/null\n+++ b/examples/pktdev-chain/basicfwd.c\n@@ -0,0 +1,221 @@\n+/*-\n+ * BSD LICENSE\n+ *\n+ * Copyright(c) 2015 Intel Corporation. All rights reserved.\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ *\n+ * * Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * * Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in\n+ * the documentation and/or other materials provided with the\n+ * distribution.\n+ * * Neither the name of Intel Corporation nor the names of its\n+ * contributors may be used to endorse or promote products derived\n+ * from this software without specific prior written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <stdint.h>\n+#include <inttypes.h>\n+#include <rte_eal.h>\n+#include <rte_ethdev.h>\n+#include <rte_cycles.h>\n+#include <rte_lcore.h>\n+#include <rte_mbuf.h>\n+#include <rte_pktdev.h>\n+\n+#define RX_RING_SIZE 128\n+#define TX_RING_SIZE 512\n+\n+#define NUM_MBUFS 8191\n+#define MBUF_SIZE (1600 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)\n+#define MBUF_CACHE_SIZE 250\n+#define BURST_SIZE 32\n+\n+static const struct rte_eth_conf port_conf_default = {\n+\t.rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN }\n+};\n+\n+/* basicfwd.c: Basic DPDK skeleton forwarding example. */\n+\n+/*\n+ * Initializes a given port using global settings and with the RX buffers\n+ * coming from the mbuf_pool passed as a parameter.\n+ */\n+static inline int\n+port_init(uint8_t port, struct rte_mempool *mbuf_pool)\n+{\n+\tstruct rte_eth_conf port_conf = port_conf_default;\n+\tconst uint16_t rx_rings = 1, tx_rings = 1;\n+\tint retval;\n+\tuint16_t q;\n+\n+\tif (port >= rte_eth_dev_count())\n+\t\treturn -1;\n+\n+\t/* Configure the Ethernet device. */\n+\tretval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);\n+\tif (retval != 0)\n+\t\treturn retval;\n+\n+\t/* Allocate and set up 1 RX queue per Ethernet port. */\n+\tfor (q = 0; q < rx_rings; q++) {\n+\t\tretval = rte_eth_rx_queue_setup(port, q, RX_RING_SIZE,\n+\t\t\t\trte_eth_dev_socket_id(port), NULL, mbuf_pool);\n+\t\tif (retval < 0)\n+\t\t\treturn retval;\n+\t}\n+\n+\t/* Allocate and set up 1 TX queue per Ethernet port. */\n+\tfor (q = 0; q < tx_rings; q++) {\n+\t\tretval = rte_eth_tx_queue_setup(port, q, TX_RING_SIZE,\n+\t\t\t\trte_eth_dev_socket_id(port), NULL);\n+\t\tif (retval < 0)\n+\t\t\treturn retval;\n+\t}\n+\n+\t/* Start the Ethernet port. */\n+\tretval = rte_eth_dev_start(port);\n+\tif (retval < 0)\n+\t\treturn retval;\n+\n+\t/* Display the port MAC address. */\n+\tstruct ether_addr addr;\n+\trte_eth_macaddr_get(port, &addr);\n+\tprintf(\"Port %u MAC: %02\" PRIx8 \" %02\" PRIx8 \" %02\" PRIx8\n+\t\t\t \" %02\" PRIx8 \" %02\" PRIx8 \" %02\" PRIx8 \"\\n\",\n+\t\t\t(unsigned)port,\n+\t\t\taddr.addr_bytes[0], addr.addr_bytes[1],\n+\t\t\taddr.addr_bytes[2], addr.addr_bytes[3],\n+\t\t\taddr.addr_bytes[4], addr.addr_bytes[5]);\n+\n+\t/* Enable RX in promiscuous mode for the Ethernet device. */\n+\trte_eth_promiscuous_enable(port);\n+\n+\treturn 0;\n+}\n+\n+struct pipeline_params {\n+\tstruct rte_pktdev *src;\n+\tstruct rte_pktdev *dst;\n+};\n+\n+/*\n+ * The lcore main. This is the main thread that does the work, reading from\n+ * an input port and writing to an output port.\n+ */\n+static __attribute__((noreturn)) void\n+do_work(const struct pipeline_params *p)\n+{\n+\tprintf(\"\\nCore %u forwarding packets. %p -> %p\\n\",\n+\t\t\trte_lcore_id(),\n+\t\t\tp->src,\n+\t\t\tp->dst);\n+\n+\t/* Run until the application is quit or killed. */\n+\tfor (;;) {\n+\t\t/*\n+\t\t * Receive packets on a src device and forward them on out\n+\t\t * the dst device.\n+\t\t */\n+\t\t/* Get burst of RX packets, from first port of pair. */\n+\t\tstruct rte_mbuf *bufs[BURST_SIZE];\n+\t\tconst uint16_t nb_rx = rte_pkt_rx_burst(p->src, bufs, BURST_SIZE);\n+\n+\t\tif (unlikely(nb_rx == 0))\n+\t\t\tcontinue;\n+\n+\t\t/* Send burst of TX packets, to second port of pair. */\n+\t\tconst uint16_t nb_tx = rte_pkt_tx_burst(p->dst, bufs, nb_rx);\n+\n+\t\t/* Free any unsent packets. */\n+\t\tif (unlikely(nb_tx < nb_rx)) {\n+\t\t\tuint16_t buf;\n+\t\t\tfor (buf = nb_tx; buf < nb_rx; buf++)\n+\t\t\t\trte_pktmbuf_free(bufs[buf]);\n+\t\t}\n+\t}\n+}\n+\n+/*\n+ * The main function, which does initialization and calls the per-lcore\n+ * functions.\n+ */\n+int\n+main(int argc, char *argv[])\n+{\n+\tstruct pipeline_params p[RTE_MAX_LCORE];\n+\tstruct rte_mempool *mbuf_pool;\n+\tunsigned nb_ports, lcore_id;\n+\tuint8_t portid;\n+\n+\t/* Initialize the Environment Abstraction Layer (EAL). */\n+\tint ret = rte_eal_init(argc, argv);\n+\tif (ret < 0)\n+\t\trte_exit(EXIT_FAILURE, \"Error with EAL initialization\\n\");\n+\n+\targc -= ret;\n+\targv += ret;\n+\n+\t/* Check that there is an even number of ports to send/receive on. */\n+\tnb_ports = rte_eth_dev_count();\n+\tif (nb_ports < 2 || (nb_ports & 1))\n+\t\trte_exit(EXIT_FAILURE, \"Error: number of ports must be even\\n\");\n+\n+\t/* Creates a new mempool in memory to hold the mbufs. */\n+\tmbuf_pool = rte_mempool_create(\"MBUF_POOL\",\n+\t\t\t\t NUM_MBUFS * nb_ports,\n+\t\t\t\t MBUF_SIZE,\n+\t\t\t\t MBUF_CACHE_SIZE,\n+\t\t\t\t sizeof(struct rte_pktmbuf_pool_private),\n+\t\t\t\t rte_pktmbuf_pool_init, NULL,\n+\t\t\t\t rte_pktmbuf_init, NULL,\n+\t\t\t\t rte_socket_id(),\n+\t\t\t\t 0);\n+\n+\tif (mbuf_pool == NULL)\n+\t\trte_exit(EXIT_FAILURE, \"Cannot create mbuf pool\\n\");\n+\n+\t/* Initialize all ports. */\n+\tfor (portid = 0; portid < nb_ports; portid++)\n+\t\tif (port_init(portid, mbuf_pool) != 0)\n+\t\t\trte_exit(EXIT_FAILURE, \"Cannot init port %\"PRIu8 \"\\n\",\n+\t\t\t\t\tportid);\n+\n+\tstruct rte_pktdev *in = rte_pktdev_from_ethport(0, 0, 0);\n+\tRTE_LCORE_FOREACH_SLAVE(lcore_id){\n+\t\tchar name[RTE_RING_NAMESIZE];\n+\t\tsnprintf(name, sizeof(name), \"RING_from_%u\", lcore_id);\n+\t\tstruct rte_pktdev *out = rte_pktdev_from_ring(\n+\t\t\t\trte_ring_create(name, 4096, rte_socket_id(), 0));\n+\n+\t\tp[lcore_id].src = in;\n+\t\tp[lcore_id].dst = out;\n+\t\trte_eal_remote_launch((lcore_function_t *)do_work,\n+\t\t\t\t&p[lcore_id], lcore_id);\n+\t\tin = out; // next pipeline stage reads from my output.\n+\t}\n+\t//now finish pipeline on master lcore\n+\tlcore_id = rte_lcore_id();\n+\tp[lcore_id].src = in;\n+\tp[lcore_id].dst = rte_pktdev_from_ethport(1, 0, 0);\n+\tdo_work(&p[lcore_id]);\n+\n+\treturn 0;\n+}\n", "prefixes": [ "dpdk-dev", "RFC-PATCH-v3", "3/6" ] }{ "id": 5348, "url": "