Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2509/?format=api
https://patches.dpdk.org/api/patches/2509/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/1422242440-28948-10-git-send-email-huawei.xie@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": "<1422242440-28948-10-git-send-email-huawei.xie@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1422242440-28948-10-git-send-email-huawei.xie@intel.com", "date": "2015-01-26T03:20:35", "name": "[dpdk-dev,RFC,v2,09/14] add select based event driven fd management logic", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "6a1e82ffc2bb01f7fd97417f7843382037071648", "submitter": { "id": 16, "url": "https://patches.dpdk.org/api/people/16/?format=api", "name": "Huawei Xie", "email": "huawei.xie@intel.com" }, "delegate": null, "mbox": "https://patches.dpdk.org/project/dpdk/patch/1422242440-28948-10-git-send-email-huawei.xie@intel.com/mbox/", "series": [], "comments": "https://patches.dpdk.org/api/patches/2509/comments/", "check": "pending", "checks": "https://patches.dpdk.org/api/patches/2509/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 2AC7F5A98;\n\tMon, 26 Jan 2015 04:21:43 +0100 (CET)", "from mga11.intel.com (mga11.intel.com [192.55.52.93])\n\tby dpdk.org (Postfix) with ESMTP id 37FBB1F5\n\tfor <dev@dpdk.org>; Mon, 26 Jan 2015 04:21:33 +0100 (CET)", "from orsmga001.jf.intel.com ([10.7.209.18])\n\tby fmsmga102.fm.intel.com with ESMTP; 25 Jan 2015 19:21:31 -0800", "from shvmail01.sh.intel.com ([10.239.29.42])\n\tby orsmga001.jf.intel.com with ESMTP; 25 Jan 2015 19:21:30 -0800", "from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com\n\t[10.239.29.90])\n\tby shvmail01.sh.intel.com with ESMTP id t0Q3LR1e014974;\n\tMon, 26 Jan 2015 11:21:27 +0800", "from shecgisg003.sh.intel.com (localhost [127.0.0.1])\n\tby shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP\n\tid t0Q3LPRq029046; Mon, 26 Jan 2015 11:21:27 +0800", "(from hxie5@localhost)\n\tby shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t0Q3LPI6029042; \n\tMon, 26 Jan 2015 11:21:25 +0800" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"5.09,466,1418112000\"; d=\"scan'208\";a=\"642452707\"", "From": "Huawei Xie <huawei.xie@intel.com>", "To": "dev@dpdk.org", "Date": "Mon, 26 Jan 2015 11:20:35 +0800", "Message-Id": "<1422242440-28948-10-git-send-email-huawei.xie@intel.com>", "X-Mailer": "git-send-email 1.7.4.1", "In-Reply-To": "<1422242440-28948-1-git-send-email-huawei.xie@intel.com>", "References": "<1422242440-28948-1-git-send-email-huawei.xie@intel.com>", "Subject": "[dpdk-dev] [RFC PATCH v2 09/14] add select based event driven fd\n\tmanagement logic", "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": "for generic event driver processing, refer to:\n\thttp://libevent.org/\n\nSigned-off-by: Huawei Xie <huawei.xie@intel.com>\n---\n lib/librte_vhost/vhost_user/fd_man.c | 207 +++++++++++++++++++++++++++++++++++\n lib/librte_vhost/vhost_user/fd_man.h | 64 +++++++++++\n 2 files changed, 271 insertions(+)\n create mode 100644 lib/librte_vhost/vhost_user/fd_man.c\n create mode 100644 lib/librte_vhost/vhost_user/fd_man.h", "diff": "diff --git a/lib/librte_vhost/vhost_user/fd_man.c b/lib/librte_vhost/vhost_user/fd_man.c\nnew file mode 100644\nindex 0000000..09187e0\n--- /dev/null\n+++ b/lib/librte_vhost/vhost_user/fd_man.c\n@@ -0,0 +1,207 @@\n+/*-\n+ * BSD LICENSE\n+ *\n+ * Copyright(c) 2010-2014 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 <stdio.h>\n+#include <stdlib.h>\n+#include <sys/socket.h>\n+#include <sys/select.h>\n+#include <sys/time.h>\n+#include <sys/types.h>\n+#include <unistd.h>\n+\n+#include <rte_log.h>\n+\n+#include \"fd_man.h\"\n+\n+/**\n+ * Returns the index in the fdset for a given fd.\n+ * If fd is -1, it means to search for a free entry.\n+ * @return\n+ * index for the fd, or -1 if fd isn't in the fdset.\n+ */\n+static int\n+fdset_find_fd(struct fdset *pfdset, int fd)\n+{\n+\tint i;\n+\n+\tif (pfdset == NULL)\n+\t\treturn -1;\n+\n+\tfor (i = 0; i < MAX_FDS && pfdset->fd[i].fd != fd; i++)\n+\t\t;\n+\n+\treturn i == MAX_FDS ? -1 : i;\n+}\n+\n+static int\n+fdset_find_free_slot(struct fdset *pfdset)\n+{\n+\treturn fdset_find_fd(pfdset, -1);\n+}\n+\n+static void\n+fdset_add_fd(struct fdset *pfdset, int idx, int fd,\n+\tfd_cb rcb, fd_cb wcb, uint64_t dat)\n+{\n+\tstruct fdentry *pfdentry;\n+\n+\tif (pfdset == NULL || idx >= MAX_FDS)\n+\t\treturn;\n+\n+\tpfdentry = &pfdset->fd[idx];\n+\tpfdentry->fd = fd;\n+\tpfdentry->rcb = rcb;\n+\tpfdentry->wcb = wcb;\n+\tpfdentry->dat = dat;\n+}\n+\n+/**\n+ * Fill the read/write fd_set with the fds in the fdset.\n+ * @return\n+ * the maximum fds filled in the read/write fd_set.\n+ */\n+static int\n+fdset_fill(fd_set *rfset, fd_set *wfset, struct fdset *pfdset)\n+{\n+\tstruct fdentry *pfdentry;\n+\tint i, maxfds = -1;\n+\tint num = MAX_FDS;\n+\n+\tif (pfdset == NULL)\n+\t\treturn -1;\n+\n+\tfor (i = 0; i < num; i++) {\n+\t\tpfdentry = &pfdset->fd[i];\n+\t\tif (pfdentry->fd != -1) {\n+\t\t\tint added = 0;\n+\t\t\tif (pfdentry->rcb && rfset) {\n+\t\t\t\tFD_SET(pfdentry->fd, rfset);\n+\t\t\t\tadded = 1;\n+\t\t\t}\n+\t\t\tif (pfdentry->wcb && wfset) {\n+\t\t\t\tFD_SET(pfdentry->fd, wfset);\n+\t\t\t\tadded = 1;\n+\t\t\t}\n+\t\t\tif (added)\n+\t\t\t\tmaxfds = pfdentry->fd < maxfds ?\n+\t\t\t\t\tmaxfds : pfdentry->fd;\n+\t\t}\n+\t}\n+\treturn maxfds;\n+}\n+\n+void\n+fdset_init(struct fdset *pfdset)\n+{\n+\tint i;\n+\n+\tif (pfdset == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < MAX_FDS; i++)\n+\t\tpfdset->fd[i].fd = -1;\n+\tpfdset->num = 0;\n+}\n+\n+/**\n+ * Register the fd in the fdset with read/write handler and context.\n+ */\n+int\n+fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, uint64_t dat)\n+{\n+\tint i;\n+\n+\tif (pfdset == NULL || fd == -1)\n+\t\treturn -1;\n+\n+\t/* Find a free slot in the list. */\n+\ti = fdset_find_free_slot(pfdset);\n+\tif (i == -1)\n+\t\treturn -2;\n+\n+\tfdset_add_fd(pfdset, i, fd, rcb, wcb, dat);\n+\tpfdset->num++;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Unregister the fd from the fdset.\n+ */\n+void\n+fdset_del(struct fdset *pfdset, int fd)\n+{\n+\tint i;\n+\n+\ti = fdset_find_fd(pfdset, fd);\n+\tif (i != -1 && fd != -1) {\n+\t\tpfdset->fd[i].fd = -1;\n+\t\tpfdset->fd[i].rcb = pfdset->fd[i].wcb = NULL;\n+\t\tpfdset->num--;\n+\t}\n+}\n+\n+/**\n+ * This functions runs in infinite blocking loop until there is no fd in\n+ * pfdset. It calls corresponding r/w handler if there is event on the fd.\n+ */\n+void\n+fdset_event_dispatch(struct fdset *pfdset)\n+{\n+\tfd_set rfds, wfds;\n+\tint i, maxfds;\n+\tstruct fdentry *pfdentry;\n+\tint num = MAX_FDS;\n+\n+\tif (pfdset == NULL)\n+\t\treturn;\n+\n+\twhile (1) {\n+\t\tFD_ZERO(&rfds);\n+\t\tFD_ZERO(&wfds);\n+\t\tmaxfds = fdset_fill(&rfds, &wfds, pfdset);\n+\t\tif (maxfds == -1)\n+\t\t\treturn;\n+\n+\t\tselect(maxfds + 1, &rfds, &wfds, NULL, NULL);\n+\n+\t\tfor (i = 0; i < num; i++) {\n+\t\t\tpfdentry = &pfdset->fd[i];\n+\t\t\tif (FD_ISSET(pfdentry->fd, &rfds) && pfdentry->rcb)\n+\t\t\t\tpfdentry->rcb(pfdentry->fd, pfdentry->dat);\n+\t\t\tif (FD_ISSET(pfdentry->fd, &wfds) && pfdentry->wcb)\n+\t\t\t\tpfdentry->wcb(pfdentry->fd, pfdentry->dat);\n+\t\t}\n+\t}\n+}\ndiff --git a/lib/librte_vhost/vhost_user/fd_man.h b/lib/librte_vhost/vhost_user/fd_man.h\nnew file mode 100644\nindex 0000000..26b4619\n--- /dev/null\n+++ b/lib/librte_vhost/vhost_user/fd_man.h\n@@ -0,0 +1,64 @@\n+/*-\n+ * BSD LICENSE\n+ *\n+ * Copyright(c) 2010-2014 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+#ifndef _FD_MAN_H_\n+#define _FD_MAN_H_\n+#include <stdint.h>\n+\n+#define MAX_FDS 1024\n+\n+typedef void (*fd_cb)(int fd, void *dat);\n+\n+struct fdentry {\n+\tint fd;\t\t/* -1 indicates this entry is empty */\n+\tfd_cb rcb;\t/* callback when this fd is readable. */\n+\tfd_cb wcb;\t/* callback when this fd is writeable.*/\n+\tvoid *dat;\t/* fd context */\n+};\n+\n+struct fdset {\n+\tstruct fdentry fd[MAX_FDS];\n+\tint num;\t/* current fd number of this fdset */\n+};\n+\n+\n+void fdset_init(struct fdset *pfdset);\n+\n+int fdset_add(struct fdset *pfdset, int fd,\n+\tfd_cb rcb, fd_cb wcb, void *dat);\n+\n+void fdset_del(struct fdset *pfdset, int fd);\n+\n+void fdset_event_dispatch(struct fdset *pfdset);\n+\n+#endif\n", "prefixes": [ "dpdk-dev", "RFC", "v2", "09/14" ] }{ "id": 2509, "url": "