Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/9665/?format=api
http://patches.dpdk.org/api/patches/9665/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/patch/1451011032-83106-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": "<1451011032-83106-3-git-send-email-zhihong.wang@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1451011032-83106-3-git-send-email-zhihong.wang@intel.com", "date": "2015-12-25T02:37:11", "name": "[dpdk-dev,v2,2/3] examples/l2fwd: Handle SIGINT and SIGTERM in l2fwd", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "32c9ca225e8ebd79ed2aac66c42551a154bd377f", "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/1451011032-83106-3-git-send-email-zhihong.wang@intel.com/mbox/", "series": [], "comments": "http://patches.dpdk.org/api/patches/9665/comments/", "check": "pending", "checks": "http://patches.dpdk.org/api/patches/9665/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 059A48E6A;\n\tFri, 25 Dec 2015 10:40:40 +0100 (CET)", "from mga04.intel.com (mga04.intel.com [192.55.52.120])\n\tby dpdk.org (Postfix) with ESMTP id 607445A89\n\tfor <dev@dpdk.org>; Fri, 25 Dec 2015 10:40:37 +0100 (CET)", "from orsmga002.jf.intel.com ([10.7.209.21])\n\tby fmsmga104.fm.intel.com with ESMTP; 25 Dec 2015 01:40:31 -0800", "from unknown (HELO dpdk5.sh.intel.com) ([10.239.129.244])\n\tby orsmga002.jf.intel.com with ESMTP; 25 Dec 2015 01:40:29 -0800" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"5.20,478,1444719600\"; d=\"scan'208\";a=\"878462064\"", "From": "Zhihong Wang <zhihong.wang@intel.com>", "To": "dev@dpdk.org", "Date": "Thu, 24 Dec 2015 21:37:11 -0500", "Message-Id": "<1451011032-83106-3-git-send-email-zhihong.wang@intel.com>", "X-Mailer": "git-send-email 2.5.0", "In-Reply-To": "<1451011032-83106-1-git-send-email-zhihong.wang@intel.com>", "References": "<1451011032-83106-1-git-send-email-zhihong.wang@intel.com>", "Subject": "[dpdk-dev] [PATCH v2 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>\n---\n examples/l2fwd/main.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 60 insertions(+)", "diff": "diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c\nindex 720fd5a..75899dd 100644\n--- a/examples/l2fwd/main.c\n+++ b/examples/l2fwd/main.c\n@@ -44,6 +44,8 @@\n #include <ctype.h>\n #include <errno.h>\n #include <getopt.h>\n+#include <signal.h>\n+#include <unistd.h>\n \n #include <rte_common.h>\n #include <rte_log.h>\n@@ -69,6 +71,9 @@\n #include <rte_mempool.h>\n #include <rte_mbuf.h>\n \n+static int force_quit = -1;\n+static int signo_quit = -1;\n+\n #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1\n \n #define NB_MBUF 8192\n@@ -284,6 +289,8 @@ l2fwd_main_loop(void)\n \t}\n \n \twhile (1) {\n+\t\tif (unlikely(force_quit != 0))\n+\t\t\tbreak;\n \n \t\tcur_tsc = rte_rdtsc();\n \n@@ -534,6 +541,45 @@ check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)\n \t}\n }\n \n+static void\n+stop_ports(void)\n+{\n+\tunsigned portid, nb_ports;\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\t}\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+\n+static void\n+signal_handler(__rte_unused 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 (force_quit < 0) {\n+\t\t\tprintf(\"Forwarding not started yet...\\n\");\n+\t\t\t/* stop ports */\n+\t\t\tstop_ports();\n+\t\t\tprintf(\"Bye...\\n\");\n+\t\t\t/* inform if there's a caller */\n+\t\t\tsignal(signum, SIG_DFL);\n+\t\t\tkill(getpid(), signum);\n+\t\t} else {\n+\t\t\tprintf(\"Forwarding started already...\\n\");\n+\t\t\tsigno_quit = signum;\n+\t\t\tforce_quit = 1;\n+\t\t}\n+\t}\n+}\n+\n int\n main(int argc, char **argv)\n {\n@@ -546,6 +592,9 @@ main(int argc, char **argv)\n \tunsigned lcore_id, rx_lcore_id;\n \tunsigned nb_ports_in_mask = 0;\n \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@@ -697,11 +746,22 @@ main(int argc, char **argv)\n \tcheck_all_ports_link_status(nb_ports, l2fwd_enabled_port_mask);\n \n \t/* launch per-lcore init on every lcore */\n+\tforce_quit = 0;\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}\n \n+\tprintf(\"Stopping forwarding... Done\\n\");\n+\t/* stop ports */\n+\tstop_ports();\n+\tprintf(\"Bye...\\n\");\n+\t/* inform if there's a caller */\n+\tif (force_quit != 0) {\n+\t\tsignal(signo_quit, SIG_DFL);\n+\t\tkill(getpid(), signo_quit);\n+\t}\n+\n \treturn 0;\n }\n", "prefixes": [ "dpdk-dev", "v2", "2/3" ] }{ "id": 9665, "url": "