get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 9684,
    "url": "http://patches.dpdk.org/api/patches/9684/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1451431644-98362-3-git-send-email-zhihong.wang@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": "<1451431644-98362-3-git-send-email-zhihong.wang@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1451431644-98362-3-git-send-email-zhihong.wang@intel.com",
    "date": "2015-12-29T23:27:23",
    "name": "[dpdk-dev,v4,2/3] examples/l2fwd: Handle SIGINT and SIGTERM in l2fwd",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "9169eedc9ff0d86d81156b36e3b7d69d0688c62f",
    "submitter": {
        "id": 156,
        "url": "http://patches.dpdk.org/api/people/156/?format=api",
        "name": "Zhihong Wang",
        "email": "zhihong.wang@intel.com"
    },
    "delegate": null,
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1451431644-98362-3-git-send-email-zhihong.wang@intel.com/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/9684/comments/",
    "check": "pending",
    "checks": "http://patches.dpdk.org/api/patches/9684/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 ED2078E98;\n\tWed, 30 Dec 2015 07:30:51 +0100 (CET)",
            "from mga11.intel.com (mga11.intel.com [192.55.52.93])\n\tby dpdk.org (Postfix) with ESMTP id D77EF8E80\n\tfor <dev@dpdk.org>; Wed, 30 Dec 2015 07:30:48 +0100 (CET)",
            "from fmsmga001.fm.intel.com ([10.253.24.23])\n\tby fmsmga102.fm.intel.com with ESMTP; 29 Dec 2015 22:30:48 -0800",
            "from unknown (HELO dpdk5.sh.intel.com) ([10.239.129.244])\n\tby fmsmga001.fm.intel.com with ESMTP; 29 Dec 2015 22:30:47 -0800"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.20,499,1444719600\"; d=\"scan'208\";a=\"871632696\"",
        "From": "Zhihong Wang <zhihong.wang@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Tue, 29 Dec 2015 18:27:23 -0500",
        "Message-Id": "<1451431644-98362-3-git-send-email-zhihong.wang@intel.com>",
        "X-Mailer": "git-send-email 2.5.0",
        "In-Reply-To": "<1451431644-98362-1-git-send-email-zhihong.wang@intel.com>",
        "References": "<1451011032-83106-1-git-send-email-zhihong.wang@intel.com>\n\t<1451431644-98362-1-git-send-email-zhihong.wang@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v4 2/3] examples/l2fwd: Handle SIGINT and SIGTERM\n\tin l2fwd",
        "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": "Handle SIGINT and SIGTERM in l2fwd.\n\nSigned-off-by: Zhihong Wang <zhihong.wang@intel.com>\nAcked-by: Michael Qiu <michael.qiu@intel.com>\n---\n examples/l2fwd/main.c | 161 +++++++++++++++++++++++++++++++++++++++++++-------\n 1 file changed, 139 insertions(+), 22 deletions(-)",
    "diff": "diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c\nindex 720fd5a..9a6f80b 100644\n--- a/examples/l2fwd/main.c\n+++ b/examples/l2fwd/main.c\n@@ -44,6 +44,9 @@\n #include <ctype.h>\n #include <errno.h>\n #include <getopt.h>\n+#include <signal.h>\n+#include <unistd.h>\n+#include <stdbool.h>\n \n #include <rte_common.h>\n #include <rte_log.h>\n@@ -69,6 +72,16 @@\n #include <rte_mempool.h>\n #include <rte_mbuf.h>\n \n+#define PORT_IDLE 0\n+#define PORT_INIT 1\n+#define PORT_WORK 2\n+#define PORT_STOP 3\n+#define PORT_QUIT 4\n+\n+static volatile uint32_t port_status;\n+static volatile bool force_quit;\n+static volatile int signo_quit;\n+\n #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1\n \n #define NB_MBUF   8192\n@@ -283,8 +296,7 @@ l2fwd_main_loop(void)\n \t\t\tportid);\n \t}\n \n-\twhile (1) {\n-\n+\twhile (!force_quit) {\n \t\tcur_tsc = rte_rdtsc();\n \n \t\t/*\n@@ -491,8 +503,12 @@ check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)\n \tprintf(\"\\nChecking link status\");\n \tfflush(stdout);\n \tfor (count = 0; count <= MAX_CHECK_TIME; count++) {\n+\t\tif (force_quit)\n+\t\t\treturn;\n \t\tall_ports_up = 1;\n \t\tfor (portid = 0; portid < port_num; portid++) {\n+\t\t\tif (force_quit)\n+\t\t\t\treturn;\n \t\t\tif ((port_mask & (1 << portid)) == 0)\n \t\t\t\tcontinue;\n \t\t\tmemset(&link, 0, sizeof(link));\n@@ -534,18 +550,110 @@ check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)\n \t}\n }\n \n+static uint8_t\n+start_ports(void)\n+{\n+\tunsigned portid, nb_ports, avail_ports;\n+\tint ret;\n+\n+\tif (rte_atomic32_cmpset(&port_status,\n+\t\t\t\tPORT_IDLE, PORT_INIT) == 0) {\n+\t\tprintf(\"Ports not idle...\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tnb_ports = rte_eth_dev_count();\n+\tavail_ports = 0;\n+\tfor (portid = 0; portid < nb_ports; portid++) {\n+\t\tif ((l2fwd_enabled_port_mask & (1 << portid)) == 0)\n+\t\t\tcontinue;\n+\t\tavail_ports++;\n+\t\tprintf(\"Starting port %d...\", portid);\n+\t\tret = rte_eth_dev_start(portid);\n+\t\tif (ret < 0)\n+\t\t\trte_exit(EXIT_FAILURE,\n+\t\t\t\t\t\"rte_eth_dev_start:err=%d, port=%u\\n\",\n+\t\t\t\t\tret, (unsigned) portid);\n+\t\trte_eth_promiscuous_enable(portid);\n+\t\tprintf(\" Done\\n\");\n+\t}\n+\n+\tif (avail_ports) {\n+\t\tif (rte_atomic32_cmpset(&port_status,\n+\t\t\t\t\tPORT_INIT, PORT_WORK) == 0)\n+\t\t\tprintf(\"Set port state failed!\\n\");\n+\t} else {\n+\t\tif (rte_atomic32_cmpset(&port_status,\n+\t\t\t\t\tPORT_INIT, PORT_IDLE) == 0)\n+\t\t\tprintf(\"Set port state failed!\\n\");\n+\t}\n+\n+\treturn avail_ports;\n+}\n+\n+static void\n+stop_ports(void)\n+{\n+\tunsigned portid, nb_ports;\n+\n+\tif (rte_atomic32_cmpset(&port_status,\n+\t\t\t\tPORT_WORK, PORT_STOP) == 0) {\n+\t\tprintf(\"Ports not started...\\n\");\n+\t\treturn;\n+\t}\n+\n+\tnb_ports = rte_eth_dev_count();\n+\tfor (portid = 0; portid < nb_ports; portid++) {\n+\t\tif ((l2fwd_enabled_port_mask & (1 << portid)) == 0)\n+\t\t\tcontinue;\n+\t\tprintf(\"Stopping port %d...\", portid);\n+\t\trte_eth_dev_stop(portid);\n+\t\trte_eth_dev_close(portid);\n+\t\tprintf(\" Done\\n\");\n+\t}\n+\n+\tif (rte_atomic32_cmpset(&port_status,\n+\t\t\t\tPORT_STOP, PORT_IDLE) == 0)\n+\t\tprintf(\"Set port state failed!\\n\");\n+}\n+\n+static void\n+signal_handler(int signum)\n+{\n+\tif (signum == SIGINT || signum == SIGTERM) {\n+\t\tprintf(\"\\nSignal %d received, preparing to exit...\\n\",\n+\t\t\t\tsignum);\n+\t\tif (rte_atomic32_cmpset(&port_status,\n+\t\t\t\t\tPORT_IDLE, PORT_QUIT) == 0) {\n+\t\t\tprintf(\"Ports started already...\\n\");\n+\t\t\tsigno_quit = signum;\n+\t\t\tforce_quit = true;\n+\t\t} else {\n+\t\t\tprintf(\"Ports not started yet...\\n\");\n+\t\t\tprintf(\"Bye...\\n\");\n+\t\t\t/* exit with the expected status */\n+\t\t\tsignal(signum, SIG_DFL);\n+\t\t\tkill(getpid(), signum);\n+\t\t}\n+\t}\n+}\n+\n int\n main(int argc, char **argv)\n {\n \tstruct lcore_queue_conf *qconf;\n \tstruct rte_eth_dev_info dev_info;\n \tint ret;\n-\tuint8_t nb_ports;\n-\tuint8_t nb_ports_available;\n+\tuint8_t nb_ports, avail_ports;\n \tuint8_t portid, last_port;\n \tunsigned lcore_id, rx_lcore_id;\n \tunsigned nb_ports_in_mask = 0;\n \n+\tport_status = PORT_IDLE;\n+\tforce_quit = false;\n+\tsignal(SIGINT, signal_handler);\n+\tsignal(SIGTERM, signal_handler);\n+\n \t/* init EAL */\n \tret = rte_eal_init(argc, argv);\n \tif (ret < 0)\n@@ -627,14 +735,11 @@ main(int argc, char **argv)\n \t\tprintf(\"Lcore %u: RX port %u\\n\", rx_lcore_id, (unsigned) portid);\n \t}\n \n-\tnb_ports_available = nb_ports;\n-\n \t/* Initialise each port */\n \tfor (portid = 0; portid < nb_ports; portid++) {\n \t\t/* skip ports that are not enabled */\n \t\tif ((l2fwd_enabled_port_mask & (1 << portid)) == 0) {\n \t\t\tprintf(\"Skipping disabled port %u\\n\", (unsigned) portid);\n-\t\t\tnb_ports_available--;\n \t\t\tcontinue;\n \t\t}\n \t\t/* init port */\n@@ -666,16 +771,6 @@ main(int argc, char **argv)\n \t\t\trte_exit(EXIT_FAILURE, \"rte_eth_tx_queue_setup:err=%d, port=%u\\n\",\n \t\t\t\tret, (unsigned) portid);\n \n-\t\t/* Start device */\n-\t\tret = rte_eth_dev_start(portid);\n-\t\tif (ret < 0)\n-\t\t\trte_exit(EXIT_FAILURE, \"rte_eth_dev_start:err=%d, port=%u\\n\",\n-\t\t\t\t  ret, (unsigned) portid);\n-\n-\t\tprintf(\"done: \\n\");\n-\n-\t\trte_eth_promiscuous_enable(portid);\n-\n \t\tprintf(\"Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\\n\\n\",\n \t\t\t\t(unsigned) portid,\n \t\t\t\tl2fwd_ports_eth_addr[portid].addr_bytes[0],\n@@ -689,19 +784,41 @@ main(int argc, char **argv)\n \t\tmemset(&port_statistics, 0, sizeof(port_statistics));\n \t}\n \n-\tif (!nb_ports_available) {\n+\t/* start ports */\n+\tavail_ports = start_ports();\n+\n+\tif (!avail_ports) {\n+\t\t/* exit with the expected status */\n+\t\tif (force_quit) {\n+\t\t\tprintf(\"All ports disabled...\\n\");\n+\t\t\tprintf(\"Bye...\\n\");\n+\t\t\tsignal(signo_quit, SIG_DFL);\n+\t\t\tkill(getpid(), signo_quit);\n+\t\t}\n \t\trte_exit(EXIT_FAILURE,\n-\t\t\t\"All available ports are disabled. Please set portmask.\\n\");\n+\t\t\t\"All ports are disabled, please check portmask...\\n\");\n \t}\n \n \tcheck_all_ports_link_status(nb_ports, l2fwd_enabled_port_mask);\n \n+\tret = 0;\n \t/* launch per-lcore init on every lcore */\n \trte_eal_mp_remote_launch(l2fwd_launch_one_lcore, NULL, CALL_MASTER);\n \tRTE_LCORE_FOREACH_SLAVE(lcore_id) {\n-\t\tif (rte_eal_wait_lcore(lcore_id) < 0)\n-\t\t\treturn -1;\n+\t\tif (rte_eal_wait_lcore(lcore_id) < 0) {\n+\t\t\tret = -1;\n+\t\t\tbreak;\n+\t\t}\n \t}\n \n-\treturn 0;\n+\t/* stop ports */\n+\tstop_ports();\n+\tprintf(\"Bye...\\n\");\n+\t/* exit with the expected status */\n+\tif (force_quit) {\n+\t\tsignal(signo_quit, SIG_DFL);\n+\t\tkill(getpid(), signo_quit);\n+\t}\n+\n+\treturn ret;\n }\n",
    "prefixes": [
        "dpdk-dev",
        "v4",
        "2/3"
    ]
}