Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/44320/?format=api
http://patches.dpdk.org/api/patches/44320/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/patch/20180906131653.10752-2-xiaolong.ye@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": "<20180906131653.10752-2-xiaolong.ye@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/20180906131653.10752-2-xiaolong.ye@intel.com", "date": "2018-09-06T13:16:53", "name": "[v1,2/2] examples/vdpa: add a new sample for vdpa", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "3e393b4959f856b9c528f796d47f8145109ac4d8", "submitter": { "id": 1120, "url": "http://patches.dpdk.org/api/people/1120/?format=api", "name": "Xiaolong Ye", "email": "xiaolong.ye@intel.com" }, "delegate": { "id": 2642, "url": "http://patches.dpdk.org/api/users/2642/?format=api", "username": "mcoquelin", "first_name": "Maxime", "last_name": "Coquelin", "email": "maxime.coquelin@redhat.com" }, "mbox": "http://patches.dpdk.org/project/dpdk/patch/20180906131653.10752-2-xiaolong.ye@intel.com/mbox/", "series": [ { "id": 1201, "url": "http://patches.dpdk.org/api/series/1201/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=1201", "date": "2018-09-06T13:16:52", "name": "[v1,1/2] vhost: introduce rte_vdpa_get_device_num api", "version": 1, "mbox": "http://patches.dpdk.org/series/1201/mbox/" } ], "comments": "http://patches.dpdk.org/api/patches/44320/comments/", "check": "success", "checks": "http://patches.dpdk.org/api/patches/44320/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 [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id A66294CBD;\n\tThu, 6 Sep 2018 08:29:12 +0200 (CEST)", "from mga06.intel.com (mga06.intel.com [134.134.136.31])\n\tby dpdk.org (Postfix) with ESMTP id 80D2A326C\n\tfor <dev@dpdk.org>; Thu, 6 Sep 2018 08:29:09 +0200 (CEST)", "from fmsmga007.fm.intel.com ([10.253.24.52])\n\tby orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t05 Sep 2018 23:29:07 -0700", "from yexl-server.sh.intel.com ([10.67.110.207])\n\tby fmsmga007.fm.intel.com with ESMTP; 05 Sep 2018 23:28:54 -0700" ], "X-Amp-Result": "SKIPPED(no attachment in message)", "X-Amp-File-Uploaded": "False", "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"5.53,334,1531810800\"; d=\"scan'208\";a=\"67936800\"", "From": "Xiaolong Ye <xiaolong.ye@intel.com>", "To": "dev@dpdk.org, Maxime Coquelin <maxime.coquelin@redhat.com>,\n\tTiwei Bie <tiwei.bie@intel.com>, Zhihong Wang <zhihong.wang@intel.com>", "Cc": "xiao.w.wang@intel.com,\n\tXiaolong Ye <xiaolong.ye@intel.com>", "Date": "Thu, 6 Sep 2018 21:16:53 +0800", "Message-Id": "<20180906131653.10752-2-xiaolong.ye@intel.com>", "X-Mailer": "git-send-email 2.17.1", "In-Reply-To": "<20180906131653.10752-1-xiaolong.ye@intel.com>", "References": "<20180906131653.10752-1-xiaolong.ye@intel.com>", "Subject": "[dpdk-dev] [PATCH v1 2/2] examples/vdpa: add a new sample for vdpa", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<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\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "From: Xiao Wang <xiao.w.wang@intel.com>\n\nThis patch adds a sample which creates vhost-user socket based on\nvdpa driver. vdpa driver can help to set up vhost datapath so this\napp doesn't need to spend a dedicated worker thread on vhost\nenqueue/dequeue operations.\n\nBelow are setup steps for your reference (using IFC driver):\n\n1. Make sure your kernnel vhost module and QEMU support vhost-user.\n - OS: CentOS 7.4\n - QEMU: 2.10.1\n - Guest OS: CentOS 7.2\n\n2. Bind VFIO-pci to VF\n a) modprobe vfio-pci\n d) ./usertools/dpdk-devbind.py -b vfio-pci 06:00.2 06:00.3\n\n3. Start vdpa sample\n ./examples/vdpa/build/vdpa --log-level=9 -c 0x10 -n 4 --socket-mem\n 1024,1024 -w 0000:06:00.2,vdpa=1 -w 0000:06:00.3,vdpa=1 --\n --iface /tmp/vhost-user- (or use interactive mode to create vdpa\n ports)\n\n4. Start two VMs\n ./qemu-2.10.1/x86_64-softmmu/qemu-system-x86_64 -cpu host -enable-kvm \\\n <snip>\n -mem-prealloc \\\n -chardev socket,id=char0,path=/tmp/vhost-user-0 \\\n -netdev type=vhost-user,id=vdpa,chardev=char0,vhostforce \\\n -device virtio-net-pci,netdev=vdpa,mac=00:aa:bb:cc:dd:ee \\\n\n ./qemu-2.10.1/x86_64-softmmu/qemu-system-x86_64 -cpu host -enable-kvm \\\n <snip>\n -mem-prealloc \\\n -chardev socket,id=char0,path=/tmp/vhost-user-1 \\\n -netdev type=vhost-user,id=vdpa,chardev=char0,vhostforce \\\n -device virtio-net-pci,netdev=vdpa,mac=00:aa:bb:cc:dd:ff \\\n\n5. Login two VMs and configure the ip, verify the network connection via\n ping.\n\nSigned-off-by: Xiao Wang <xiao.w.wang@intel.com>\nSigned-off-by: Xiaolong Ye <xiaolong.ye@intel.com>\n---\n examples/vdpa/Makefile | 32 ++++\n examples/vdpa/main.c | 327 ++++++++++++++++++++++++++++++++++++++\n examples/vdpa/meson.build | 11 ++\n 3 files changed, 370 insertions(+)\n create mode 100644 examples/vdpa/Makefile\n create mode 100644 examples/vdpa/main.c\n create mode 100644 examples/vdpa/meson.build", "diff": "diff --git a/examples/vdpa/Makefile b/examples/vdpa/Makefile\nnew file mode 100644\nindex 000000000..42672a2bc\n--- /dev/null\n+++ b/examples/vdpa/Makefile\n@@ -0,0 +1,32 @@\n+# SPDX-License-Identifier: BSD-3-Clause\n+# Copyright(c) 2018 Intel Corporation\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+ifneq ($(CONFIG_RTE_EXEC_ENV),\"linuxapp\")\n+$(info This application can only operate in a linuxapp environment, \\\n+please change the definition of the RTE_TARGET environment variable)\n+all:\n+else\n+\n+# binary name\n+APP = vdpa\n+\n+# all source are stored in SRCS-y\n+SRCS-y := main.c\n+\n+CFLAGS += -O2 -D_FILE_OFFSET_BITS=64\n+CFLAGS += $(WERROR_FLAGS)\n+CFLAGS += -D_GNU_SOURCE\n+CFLAGS += -DALLOW_EXPERIMENTAL_API\n+\n+include $(RTE_SDK)/mk/rte.extapp.mk\n+\n+endif\ndiff --git a/examples/vdpa/main.c b/examples/vdpa/main.c\nnew file mode 100644\nindex 000000000..b19d7a217\n--- /dev/null\n+++ b/examples/vdpa/main.c\n@@ -0,0 +1,327 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2018 Intel Corporation\n+ */\n+\n+#include <getopt.h>\n+#include <signal.h>\n+#include <stdint.h>\n+#include <string.h>\n+#include <unistd.h>\n+\n+#include <rte_ethdev.h>\n+#include <rte_malloc.h>\n+#include <rte_vhost.h>\n+#include <rte_vdpa.h>\n+\n+#include <cmdline_parse.h>\n+#include <cmdline_socket.h>\n+#include <cmdline_parse_string.h>\n+#include <cmdline.h>\n+\n+#define MAX_PATH_LEN 128\n+#define MAX_VDPA_SAMPLE_PORTS 1024\n+\n+struct vdpa_port {\n+\tchar ifname[MAX_PATH_LEN];\n+\tint did;\n+\tint vid;\n+};\n+\n+struct vdpa_port vports[MAX_VDPA_SAMPLE_PORTS];\n+\n+char iface[MAX_PATH_LEN];\n+int devcnt;\n+int dev_id;\n+uint8_t interactive;\n+\n+/* display usage */\n+static void\n+vdpa_usage(const char *prgname)\n+{\n+\tprintf(\"Usage: %s [EAL options] -- \"\n+\t\t\t\t \"[--interactive|-i] \"\n+\t\t\t\t \"[--iface PATH]\\n\"\n+\t\t\t\t \"\t--interactive: run in interactive mode.\\n\"\n+\t\t\t\t \"\t--iface <path>: specify the path prefix of the socket files, e.g. /tmp/vhost-user-\\n\",\n+\t\t\t\t prgname);\n+}\n+\n+static int\n+parse_args(int argc, char **argv)\n+{\n+\tstatic const char *short_option = \"i\";\n+\tstatic struct option long_option[] = {\n+\t\t{\"iface\", required_argument, NULL, 0},\n+\t\t{\"interactive\", 0, 0, 0},\n+\t\t{NULL, 0, 0, 0},\n+\t};\n+\tint opt, idx;\n+\tchar *prgname = argv[0];\n+\n+\twhile ((opt = getopt_long(argc, argv, short_option, long_option, &idx))\n+\t\t\t!= EOF) {\n+\t\tswitch (opt) {\n+\t\tcase 'i':\n+\t\t\tprintf(\"Interactive-mode selected\\n\");\n+\t\t\tinteractive = 1;\n+\t\t\tbreak;\n+\t\t/* long options */\n+\t\tcase 0:\n+\t\t\tif (strncmp(long_option[idx].name, \"iface\",\n+\t\t\t\t\t\tMAX_PATH_LEN) == 0) {\n+\t\t\t\tstrncpy(iface, optarg, MAX_PATH_LEN);\n+\t\t\t\tprintf(\"iface %s\\n\", iface);\n+\t\t\t}\n+\t\t\tif (!strcmp(long_option[idx].name, \"interactive\")) {\n+\t\t\t\tprintf(\"Interactive-mode selected\\n\");\n+\t\t\t\tinteractive = 1;\n+\t\t\t}\n+\t\t\tbreak;\n+\n+\t\tdefault:\n+\t\t\tvdpa_usage(prgname);\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\tif (*iface == '\\0' && interactive == 0) {\n+\t\tvdpa_usage(prgname);\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+data_init(void)\n+{\n+\tdevcnt = rte_vdpa_get_device_num();\n+\tif (devcnt <= 0) {\n+\t\tprintf(\"No available vdpa device found\\n\");\n+\t\treturn -1;\n+\t}\n+\tdev_id = 0;\n+\tinteractive = 0;\n+\tmemset(iface, 0, MAX_PATH_LEN * sizeof(iface[0]));\n+\tmemset(vports, 0, MAX_VDPA_SAMPLE_PORTS * sizeof(vports[0]));\n+\treturn 0;\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\texit(0);\n+\t}\n+}\n+\n+static int\n+new_device(int vid)\n+{\n+\tchar ifname[MAX_PATH_LEN];\n+\tint i;\n+\n+\trte_vhost_get_ifname(vid, ifname, sizeof(ifname));\n+\tfor (i = 0; i < MAX_VDPA_SAMPLE_PORTS; i++) {\n+\t\tif (strncmp(ifname, vports[i].ifname, MAX_PATH_LEN) == 0) {\n+\t\t\tprintf(\"\\nnew port %s, did: %d\\n\",\n+\t\t\t\t\tifname, vports[i].did);\n+\t\t\tvports[i].vid = vid;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tif (i >= MAX_VDPA_SAMPLE_PORTS)\n+\t\treturn -1;\n+\n+\treturn 0;\n+}\n+\n+static void\n+destroy_device(int vid)\n+{\n+\tchar ifname[MAX_PATH_LEN];\n+\tint i;\n+\n+\trte_vhost_get_ifname(vid, ifname, sizeof(ifname));\n+\tfor (i = 0; i < MAX_VDPA_SAMPLE_PORTS; i++) {\n+\t\tif (strcmp(ifname, vports[i].ifname) == 0) {\n+\t\t\tprintf(\"\\ndestroy port %s, did: %d\\n\",\n+\t\t\t\t\tifname, vports[i].did);\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+}\n+\n+static const struct vhost_device_ops vdpa_sample_devops = {\n+\t.new_device = new_device,\n+\t.destroy_device = destroy_device,\n+\t.vring_state_changed = NULL,\n+\t.features_changed = NULL,\n+\t.new_connection = NULL,\n+\t.destroy_connection = NULL,\n+};\n+\n+static void\n+start_vdpa(const char *socket_path, int did, uint64_t flags)\n+{\n+\tint ret;\n+\tret = rte_vhost_driver_register(socket_path, flags);\n+\tif (ret != 0)\n+\t\trte_exit(EXIT_FAILURE,\n+\t\t\t\"register driver failed: %s\\n\",\n+\t\t\tsocket_path);\n+\n+\tret = rte_vhost_driver_callback_register(socket_path,\n+\t\t\t&vdpa_sample_devops);\n+\tif (ret != 0)\n+\t\trte_exit(EXIT_FAILURE,\n+\t\t\t\"register driver ops failed: %s\\n\",\n+\t\t\tsocket_path);\n+\n+\tret = rte_vhost_driver_attach_vdpa_device(socket_path, did);\n+\tif (ret != 0)\n+\t\trte_exit(EXIT_FAILURE,\n+\t\t\t\"attach vdpa device failed: %s\\n\",\n+\t\t\tsocket_path);\n+\n+\tif (rte_vhost_driver_start(socket_path) < 0)\n+\t\trte_exit(EXIT_FAILURE,\n+\t\t\t\"start vhost driver failed: %s\\n\",\n+\t\t\tsocket_path);\n+}\n+\n+/* interactive cmds */\n+\n+/* *** Help command with introduction. *** */\n+struct cmd_help_result {\n+\tcmdline_fixed_string_t help;\n+};\n+\n+static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,\n+\t\t\t\tstruct cmdline *cl,\n+\t\t\t\t__attribute__((unused)) void *data)\n+{\n+\tcmdline_printf(\n+\t\tcl,\n+\t\t\"\\n\"\n+\t\t\"The following commands are currently available:\\n\\n\"\n+\t\t\"Control:\\n\"\n+\t\t\" help : Show interactive instructions.\\n\"\n+\t\t\" create <socket_file_path> : Create a new vdpa port.\\n\\n\"\n+\t);\n+}\n+\n+cmdline_parse_token_string_t cmd_help_help =\n+\tTOKEN_STRING_INITIALIZER(struct cmd_help_result, help, \"help\");\n+\n+cmdline_parse_inst_t cmd_help = {\n+\t.f = cmd_help_parsed,\n+\t.data = NULL,\n+\t.help_str = \"show help\",\n+\t.tokens = {\n+\t\t(void *)&cmd_help_help,\n+\t\tNULL,\n+\t},\n+};\n+\n+/* *** Create new vdpa port *** */\n+struct cmd_create_result {\n+\tcmdline_fixed_string_t action;\n+\tcmdline_fixed_string_t socket_path;\n+};\n+\n+static void cmd_create_vdpa_port_parsed(void *parsed_result,\n+\t\t\t\tstruct cmdline *cl,\n+\t\t\t\t__attribute__((unused)) void *data)\n+{\n+\tstruct cmd_create_result *res = parsed_result;\n+\tchar ifname[MAX_PATH_LEN];\n+\tuint64_t flags = 0;\n+\n+\tstrncpy(ifname, res->socket_path, MAX_PATH_LEN);\n+\tif (dev_id < devcnt)\n+\t\tstart_vdpa(ifname, dev_id++, flags);\n+\telse\n+\t\tcmdline_printf(cl, \"No available vdpa devices.\\n\");\n+}\n+\n+cmdline_parse_token_string_t cmd_action_create =\n+\tTOKEN_STRING_INITIALIZER(struct cmd_create_result, action, \"create\");\n+cmdline_parse_token_string_t cmd_socket_path =\n+\tTOKEN_STRING_INITIALIZER(struct cmd_create_result, socket_path, NULL);\n+\n+cmdline_parse_inst_t cmd_create_vdpa_port = {\n+\t.f = cmd_create_vdpa_port_parsed, /* function to call */\n+\t.data = NULL, /* 2nd arg of func */\n+\t.help_str = \"Create an new vdpa port\",\n+\t.tokens = { /* token list, NULL terminated */\n+\t\t(void *)&cmd_action_create,\n+\t\t(void *)&cmd_socket_path,\n+\t\tNULL,\n+\t},\n+};\n+\n+cmdline_parse_ctx_t main_ctx[] = {\n+\t(cmdline_parse_inst_t *)&cmd_help,\n+\t(cmdline_parse_inst_t *)&cmd_create_vdpa_port,\n+\tNULL,\n+};\n+\n+int\n+main(int argc, char *argv[])\n+{\n+\tchar ifname[MAX_PATH_LEN];\n+\tchar ch;\n+\tint i, did;\n+\tint ret;\n+\tuint64_t flags = 0;\n+\tstruct cmdline *cl;\n+\n+\tret = rte_eal_init(argc, argv);\n+\tif (ret < 0)\n+\t\trte_exit(EXIT_FAILURE, \"eal init failed\\n\");\n+\targc -= ret;\n+\targv += ret;\n+\n+\tsignal(SIGINT, signal_handler);\n+\tsignal(SIGTERM, signal_handler);\n+\n+\tdata_init();\n+\n+\tret = parse_args(argc, argv);\n+\tif (ret < 0)\n+\t\trte_exit(EXIT_FAILURE, \"invalid argument\\n\");\n+\n+\tif (interactive == 1) {\n+\t\tcl = cmdline_stdin_new(main_ctx, \"vdpa> \");\n+\t\tif (cl == NULL)\n+\t\t\trte_panic(\"Cannot create cmdline instance\\n\");\n+\t\tcmdline_interact(cl);\n+\t\tcmdline_stdin_exit(cl);\n+\t} else {\n+\t\tfor (i = 0; i < RTE_MIN(MAX_VDPA_SAMPLE_PORTS, devcnt); i++) {\n+\t\t\tdid = i;\n+\t\t\tsnprintf(ifname, sizeof(ifname), \"%s%d\", iface, i);\n+\t\t\tvports[i].did = did;\n+\t\t\tstrncpy(vports[i].ifname, ifname, MAX_PATH_LEN);\n+\n+\t\t\tstart_vdpa(ifname, did, flags);\n+\n+\t\t\tdid++;\n+\t\t}\n+\n+\t\tprintf(\"enter \\'q\\' to quit\\n\");\n+\t\twhile (scanf(\"%c\", &ch)) {\n+\t\t\tif (ch == 'q')\n+\t\t\t\tbreak;\n+\t\t\twhile (ch != '\\n')\n+\t\t\t\tscanf(\"%c\", &ch);\n+\t\t\tprintf(\"enter \\'q\\' to quit\\n\");\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\ndiff --git a/examples/vdpa/meson.build b/examples/vdpa/meson.build\nnew file mode 100644\nindex 000000000..e85d84a76\n--- /dev/null\n+++ b/examples/vdpa/meson.build\n@@ -0,0 +1,11 @@\n+# SPDX-License-Identifier: BSD-3-Clause\n+# Copyright(c) 2018 Intel Corporation\n+\n+# meson file, for building this example as part of a main DPDK build.\n+#\n+# To build this example as a standalone application with an already-installed\n+# DPDK instance, use 'make'\n+\n+sources = files(\n+\t'main.c'\n+)\n", "prefixes": [ "v1", "2/2" ] }{ "id": 44320, "url": "