get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/105142/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 105142,
    "url": "http://patches.dpdk.org/api/patches/105142/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20211214141242.3383831-10-ronan.randles@intel.com/",
    "project": {
        "id": 1,
        "url": "http://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": "<20211214141242.3383831-10-ronan.randles@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20211214141242.3383831-10-ronan.randles@intel.com",
    "date": "2021-12-14T14:12:39",
    "name": "[09/12] examples/generator: enable gen library for traffic gen",
    "commit_ref": null,
    "pull_url": null,
    "state": "not-applicable",
    "archived": true,
    "hash": "fe1adc4917562ab3c0b1dfce2ef9e897a66eae16",
    "submitter": {
        "id": 2439,
        "url": "http://patches.dpdk.org/api/people/2439/?format=api",
        "name": "Ronan Randles",
        "email": "ronan.randles@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20211214141242.3383831-10-ronan.randles@intel.com/mbox/",
    "series": [
        {
            "id": 20944,
            "url": "http://patches.dpdk.org/api/series/20944/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=20944",
            "date": "2021-12-14T14:12:30",
            "name": "add packet generator library and example app",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/20944/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/105142/comments/",
    "check": "warning",
    "checks": "http://patches.dpdk.org/api/patches/105142/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 437CAA00C3;\n\tTue, 14 Dec 2021 15:14:09 +0100 (CET)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 5862F411CB;\n\tTue, 14 Dec 2021 15:13:17 +0100 (CET)",
            "from mga01.intel.com (mga01.intel.com [192.55.52.88])\n by mails.dpdk.org (Postfix) with ESMTP id 0B5E34114D\n for <dev@dpdk.org>; Tue, 14 Dec 2021 15:13:12 +0100 (CET)",
            "from orsmga006.jf.intel.com ([10.7.209.51])\n by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 14 Dec 2021 06:13:11 -0800",
            "from silpixa00401120.ir.intel.com ([10.55.129.95])\n by orsmga006.jf.intel.com with ESMTP; 14 Dec 2021 06:12:59 -0800"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=simple/simple;\n d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n t=1639491193; x=1671027193;\n h=from:to:cc:subject:date:message-id:in-reply-to:\n references:mime-version:content-transfer-encoding;\n bh=A4TR+Iv3bwbzdF1neNp9lNkV6o0Wa4LZudFokwIVJD8=;\n b=XM0y/XxwKo8NjIX84NjEYgtIVBjBRkqXtirrHk9jKj3+S9jYcezkHj98\n c4IFlmrWi1WrDvDX5X7C721sHu8egCUnvsy+mHfNoLVbeAnm/eETwEMTA\n gWzX+NnH/XlIcFrsaRrfkLS2Cfz7cIG6SYvHbrfsRvK0HpE2RfUceJ0CW\n 3s4IaoIRpp/0PHmhD0I+iENie+LaYyAVn1ym3eHS3YgvGX3haL2pVuxD/\n lqFOUAQj9rkIDrQF/U2dJ5VMDpxAk0lUgGUWHkygMKDNeBZJq4cFc19Fp\n TtbgE1WzP55KHFBSSQGvnf/gCBKRCfmxn6SuHKdAFiaD+ZVK2ujVwF13A A==;",
        "X-IronPort-AV": [
            "E=McAfee;i=\"6200,9189,10197\"; a=\"263123887\"",
            "E=Sophos;i=\"5.88,205,1635231600\"; d=\"scan'208\";a=\"263123887\"",
            "E=Sophos;i=\"5.88,205,1635231600\"; d=\"scan'208\";a=\"465104165\""
        ],
        "X-ExtLoop1": "1",
        "From": "Ronan Randles <ronan.randles@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "harry.van.haaren@intel.com,\n\tRonan Randles <ronan.randles@intel.com>",
        "Subject": "[PATCH 09/12] examples/generator: enable gen library for traffic gen",
        "Date": "Tue, 14 Dec 2021 14:12:39 +0000",
        "Message-Id": "<20211214141242.3383831-10-ronan.randles@intel.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20211214141242.3383831-1-ronan.randles@intel.com>",
        "References": "<20211214141242.3383831-1-ronan.randles@intel.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "This commit shows the steps necessary to enable traffic generation\nusing the gen library\n\nSigned-off-by: Ronan Randles <ronan.randles@intel.com>\n---\n examples/generator/main.c      | 175 ++++++++++++++++++++++-----------\n examples/generator/meson.build |   1 +\n examples/meson.build           |   1 +\n 3 files changed, 120 insertions(+), 57 deletions(-)",
    "diff": "diff --git a/examples/generator/main.c b/examples/generator/main.c\nindex 0082f588b4..1ddf4c1603 100644\n--- a/examples/generator/main.c\n+++ b/examples/generator/main.c\n@@ -1,14 +1,18 @@\n /* SPDX-License-Identifier: BSD-3-Clause\n- * Copyright(c) 2010-2015 Intel Corporation\n+ * Copyright(c) 2021 Intel Corporation\n  */\n \n #include <stdint.h>\n #include <inttypes.h>\n+#include <unistd.h>\n+#include <signal.h>\n+\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_gen.h>\n \n #define RX_RING_SIZE 1024\n #define TX_RING_SIZE 1024\n@@ -16,23 +20,23 @@\n #define NUM_MBUFS 8191\n #define MBUF_CACHE_SIZE 256\n #define BURST_SIZE 32\n+#define MIN_THREADS 3\n \n-/* Configuration of ethernet ports. 8<  */\n static const struct rte_eth_conf port_conf_default = {\n \t.rxmode = {\n \t\t.max_lro_pkt_size = RTE_ETHER_MAX_LEN,\n \t},\n };\n-/* >8 End of configuration of ethernet ports. */\n \n-/* basicfwd.c: Basic DPDK skeleton forwarding example. */\n+static volatile int done;\n+static struct rte_mempool *mbuf_pool;\n+struct rte_gen *gen;\n+\n+static void handle_sigint(int sig);\n \n-/*\n- * Initializes a given port using global settings and with the RX buffers\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-\n-/* Main functional part of port initialization. 8< */\n static inline int\n port_init(uint16_t port, struct rte_mempool *mbuf_pool)\n {\n@@ -68,6 +72,12 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)\n \tif (retval != 0)\n \t\treturn retval;\n \n+\tint lcore_available_count = rte_lcore_count();\n+\tif (lcore_available_count < MIN_THREADS) {\n+\t\tprintf(\"Not enough threads available\\n\");\n+\t\treturn -1;\n+\t}\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, nb_rxd,\n@@ -86,9 +96,8 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)\n \t\t\treturn retval;\n \t}\n \n-\t/* Starting Ethernet port. 8< */\n+\t/* Start the Ethernet port. */\n \tretval = rte_eth_dev_start(port);\n-\t/* >8 End of starting of ethernet port. */\n \tif (retval < 0)\n \t\treturn retval;\n \n@@ -104,27 +113,67 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)\n \n \t/* Enable RX in promiscuous mode for the Ethernet device. */\n \tretval = rte_eth_promiscuous_enable(port);\n-\t/* End of setting RX port in promiscuous mode. */\n \tif (retval != 0)\n \t\treturn retval;\n \n \treturn 0;\n }\n-/* >8 End of main functional part of port initialization. */\n \n-/*\n- * The lcore main. This is the main thread that does the work, reading from\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 int\n+lcore_producer(__rte_unused void *arg)\n+{\n+\tuint16_t port;\n+\n+\t/* Check that the port is on the same NUMA node as the polling thread\n+\t * for best performance.\n+\t */\n+\tRTE_ETH_FOREACH_DEV(port)\n+\t\tif (rte_eth_dev_socket_id(port) >= 0 &&\n+\t\t\t\trte_eth_dev_socket_id(port) !=\n+\t\t\t\t\t\t(int)rte_socket_id())\n+\t\t\tprintf(\"WARNING, port %u is on remote NUMA node to \"\n+\t\t\t\t\t\"polling thread.\\n\\tPerformance will \"\n+\t\t\t\t\t\"not be optimal.\\n\", port);\n \n- /* Basic forwarding application lcore. 8< */\n-static __rte_noreturn void\n-lcore_main(void)\n+\t/* Run until the application is quit or killed. */\n+\twhile (!done) {\n+\t\tstruct rte_mbuf *bufs[BURST_SIZE];\n+\t\tint i;\n+\t\t/* Receive packets from gen and then tx them over port */\n+\t\tRTE_ETH_FOREACH_DEV(port) {\n+\t\t\tint nb_recieved = rte_gen_rx_burst(gen, bufs,\n+\t\t\t\t\t\t\tBURST_SIZE);\n+\t\t\tfor (i = 0; i < nb_recieved; i++) {\n+\t\t\t\tbufs[i]->pkt_len = 64;\n+\t\t\t\tbufs[i]->data_len = 64;\n+\t\t\t}\n+\n+\t\t\tuint16_t nb_tx = rte_eth_tx_burst(port, 0, bufs,\n+\t\t\t\t\t\t\tnb_recieved);\n+\t\t\tif (nb_tx != nb_recieved)\n+\t\t\t\trte_pktmbuf_free_bulk(&bufs[nb_tx],\n+\t\t\t\t\t\t\t(nb_recieved - nb_tx));\n+\n+\t\t\tif (unlikely(nb_tx == 0))\n+\t\t\t\tcontinue;\n+\n+\t\t}\n+\t}\n+\treturn 0;\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 int\n+lcore_consumer(__rte_unused void *arg)\n {\n \tuint16_t port;\n \n-\t/*\n-\t * Check that the port is on the same NUMA node as the polling thread\n+\t/* Check that the port is on the same NUMA node as the polling thread\n \t * for best performance.\n \t */\n \tRTE_ETH_FOREACH_DEV(port)\n@@ -135,57 +184,53 @@ lcore_main(void)\n \t\t\t\t\t\"polling thread.\\n\\tPerformance will \"\n \t\t\t\t\t\"not be optimal.\\n\", port);\n \n-\tprintf(\"\\nCore %u forwarding packets. [Ctrl+C to quit]\\n\",\n-\t\t\trte_lcore_id());\n+\t/* Run until the application is quit or killed. */\n+\twhile (!done) {\n+\t\tstruct rte_mbuf *bufs[BURST_SIZE];\n \n-\t/* Main work of application loop. 8< */\n-\tfor (;;) {\n-\t\t/*\n-\t\t * Receive packets on a port and forward them on the paired\n-\t\t * port. The mapping is 0 -> 1, 1 -> 0, 2 -> 3, 3 -> 2, etc.\n+\t\t/* Receive packets over port and then tx them to gen library\n+\t\t * for stats\n \t\t */\n \t\tRTE_ETH_FOREACH_DEV(port) {\n+\t\t\tuint64_t latency[BURST_SIZE];\n+\t\t\tuint16_t nb_rx = rte_eth_rx_burst(port, 0, bufs,\n+\t\t\t\t\t\t\tBURST_SIZE);\n+\t\t\trte_gen_tx_burst(gen, bufs, latency, nb_rx);\n \n-\t\t\t/* Get burst of RX packets, from first port of pair. */\n-\t\t\tstruct rte_mbuf *bufs[BURST_SIZE];\n-\t\t\tconst uint16_t nb_rx = rte_eth_rx_burst(port, 0,\n-\t\t\t\t\tbufs, BURST_SIZE);\n+\t\t\tint nb_sent = rte_gen_tx_burst(gen, bufs,\n+\t\t\t\t\t\t\tlatency, nb_rx);\n+\t\t\tif (nb_sent != nb_rx)\n+\t\t\t\trte_panic(\"invalid tx quantity\\n\");\n \n \t\t\tif (unlikely(nb_rx == 0))\n \t\t\t\tcontinue;\n \n-\t\t\t/* Send burst of TX packets, to second port of pair. */\n-\t\t\tconst uint16_t nb_tx = rte_eth_tx_burst(port ^ 1, 0,\n-\t\t\t\t\tbufs, nb_rx);\n-\n-\t\t\t/* Free any unsent packets. */\n-\t\t\tif (unlikely(nb_tx < nb_rx)) {\n-\t\t\t\tuint16_t buf;\n-\t\t\t\tfor (buf = nb_tx; buf < nb_rx; buf++)\n-\t\t\t\t\trte_pktmbuf_free(bufs[buf]);\n-\t\t\t}\n \t\t}\n \t}\n-\t/* >8 End of loop. */\n+\treturn 0;\n }\n-/* >8 End Basic forwarding application lcore. */\n \n-/*\n- * The main function, which does initialization and calls the per-lcore\n+void handle_sigint(int sig)\n+{\n+\tRTE_SET_USED(sig);\n+\tprintf(\"\\nExiting...\\n\");\n+\tdone = 1;\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 rte_mempool *mbuf_pool;\n+\tsignal(SIGINT, handle_sigint);\n \tunsigned int nb_ports;\n \tuint16_t portid;\n \n-\t/* Initializion the Environment Abstraction Layer (EAL). 8< */\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-\t/* >8 End of initializion the Environment Abstraction Layer (EAL). */\n \n \targc -= ret;\n \targv += ret;\n@@ -196,28 +241,44 @@ main(int argc, char *argv[])\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-\n-\t/* Allocates mempool to hold the mbufs. 8< */\n \tmbuf_pool = rte_pktmbuf_pool_create(\"MBUF_POOL\", NUM_MBUFS * nb_ports,\n \t\tMBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());\n-\t/* >8 End of allocating mempool to hold mbuf. */\n \n \tif (mbuf_pool == NULL)\n \t\trte_exit(EXIT_FAILURE, \"Cannot create mbuf pool\\n\");\n \n-\t/* Initializing all ports. 8< */\n+\t/* Initialize all ports. */\n \tRTE_ETH_FOREACH_DEV(portid)\n \t\tif (port_init(portid, mbuf_pool) != 0)\n \t\t\trte_exit(EXIT_FAILURE, \"Cannot init port %\"PRIu16 \"\\n\",\n \t\t\t\t\tportid);\n-\t/* >8 End of initializing all ports. */\n \n-\tif (rte_lcore_count() > 1)\n-\t\tprintf(\"\\nWARNING: Too many lcores enabled. Only 1 used.\\n\");\n+\tgen = rte_gen_create(mbuf_pool);\n+\tif (!gen)\n+\t\trte_panic(\"Gen failed to initialize\\n\");\n+\n+\tint err = rte_gen_packet_parse_string(gen, \"Ether()/IP()\", NULL);\n+\tif (err)\n+\t\trte_panic(\"Failed to parse input args\");\n+\n+\t/* launch lcore functions */\n+\tuint32_t lcore_count = 0;\n+\tuint32_t lcore_id = 0;\n+\tRTE_LCORE_FOREACH_WORKER(lcore_id) {\n+\t\tif (lcore_count == 0)\n+\t\t\trte_eal_remote_launch(lcore_producer, NULL, lcore_id);\n+\t\telse if (lcore_count == 1)\n+\t\t\trte_eal_remote_launch(lcore_consumer, NULL, lcore_id);\n+\t\telse\n+\t\t\tbreak;\n+\n+\t\tlcore_count++;\n+\t}\n+\t/* Stall the main thread until all other threads have returned. */\n+\trte_eal_mp_wait_lcore();\n \n-\t/* Call lcore_main on the main core only. Called on single lcore. 8< */\n-\tlcore_main();\n-\t/* >8 End of called on single lcore. */\n+\t/* All threads returned, safe to destroy gen instance */\n+\trte_gen_destroy(gen);\n \n \t/* clean up the EAL */\n \trte_eal_cleanup();\ndiff --git a/examples/generator/meson.build b/examples/generator/meson.build\nindex 441678bbe5..15d84674a5 100644\n--- a/examples/generator/meson.build\n+++ b/examples/generator/meson.build\n@@ -10,3 +10,4 @@ allow_experimental_apis = true\n sources = files(\n         'main.c',\n )\n+deps += 'gen'\n\\ No newline at end of file\ndiff --git a/examples/meson.build b/examples/meson.build\nindex bac9b76007..79ce36d02b 100644\n--- a/examples/meson.build\n+++ b/examples/meson.build\n@@ -18,6 +18,7 @@ all_examples = [\n         'fips_validation',\n         'flow_classify',\n         'flow_filtering',\n+        'generator',\n         'helloworld',\n         'ip_fragmentation',\n         'ip_pipeline',\n",
    "prefixes": [
        "09/12"
    ]
}