get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 31120,
    "url": "http://patches.dpdk.org/api/patches/31120/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20171102160924.41266-7-roy.fan.zhang@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": "<20171102160924.41266-7-roy.fan.zhang@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20171102160924.41266-7-roy.fan.zhang@intel.com",
    "date": "2017-11-02T16:09:24",
    "name": "[dpdk-dev,RFC,6/6] example/vhost_crypto: add vhost_crypto sample application",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "52988215c391ea568b8e2a71e46190d0e656738d",
    "submitter": {
        "id": 304,
        "url": "http://patches.dpdk.org/api/people/304/?format=api",
        "name": "Fan Zhang",
        "email": "roy.fan.zhang@intel.com"
    },
    "delegate": null,
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20171102160924.41266-7-roy.fan.zhang@intel.com/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/31120/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/31120/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 220AA1B638;\n\tThu,  2 Nov 2017 17:09:27 +0100 (CET)",
            "from mga05.intel.com (mga05.intel.com [192.55.52.43])\n\tby dpdk.org (Postfix) with ESMTP id 06BD91B646\n\tfor <dev@dpdk.org>; Thu,  2 Nov 2017 17:09:24 +0100 (CET)",
            "from fmsmga006.fm.intel.com ([10.253.24.20])\n\tby fmsmga105.fm.intel.com with ESMTP; 02 Nov 2017 09:09:20 -0700",
            "from silpixa00398673.ir.intel.com (HELO\n\tsilpixa00398673.ger.corp.intel.com) ([10.237.223.54])\n\tby fmsmga006.fm.intel.com with ESMTP; 02 Nov 2017 09:09:18 -0700"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.44,335,1505804400\"; d=\"scan'208\";a=\"171111803\"",
        "From": "Fan Zhang <roy.fan.zhang@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "yliu@fridaylinux.org, maxime.coquelin@redhat.com, jianfeng.tan@intel.com,\n\tpablo.de.lara.guarch@intel.com, zhihong.wang@intel.com,\n\ttiwei.bie@intel.com",
        "Date": "Thu,  2 Nov 2017 16:09:24 +0000",
        "Message-Id": "<20171102160924.41266-7-roy.fan.zhang@intel.com>",
        "X-Mailer": "git-send-email 2.9.5",
        "In-Reply-To": "<20171102160924.41266-1-roy.fan.zhang@intel.com>",
        "References": "<20171102160924.41266-1-roy.fan.zhang@intel.com>",
        "Subject": "[dpdk-dev] [RFC PATCH 6/6] example/vhost_crypto: add vhost_crypto\n\tsample application",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <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": "This patch adds vhost_crypto sample application to DPDK.\n\nSigned-off-by: Fan Zhang <roy.fan.zhang@intel.com>\n---\n examples/vhost_crypto/Makefile |  59 ++++\n examples/vhost_crypto/main.c   | 617 +++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 676 insertions(+)\n create mode 100644 examples/vhost_crypto/Makefile\n create mode 100644 examples/vhost_crypto/main.c",
    "diff": "diff --git a/examples/vhost_crypto/Makefile b/examples/vhost_crypto/Makefile\nnew file mode 100644\nindex 0000000..e457524\n--- /dev/null\n+++ b/examples/vhost_crypto/Makefile\n@@ -0,0 +1,59 @@\n+#   BSD LICENSE\n+#\n+#   Copyright(c) 2010-2017 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+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 = vhost-crypto\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+\n+include $(RTE_SDK)/mk/rte.extapp.mk\n+\n+endif\ndiff --git a/examples/vhost_crypto/main.c b/examples/vhost_crypto/main.c\nnew file mode 100644\nindex 0000000..a67469d\n--- /dev/null\n+++ b/examples/vhost_crypto/main.c\n@@ -0,0 +1,617 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2017 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\t 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 <stdio.h>\n+#include <stdlib.h>\n+#include <unistd.h>\n+#include <stdbool.h>\n+#include <assert.h>\n+#include <getopt.h>\n+\n+#include <rte_malloc.h>\n+#include <rte_cycles.h>\n+#include <rte_vhost.h>\n+#include <rte_cryptodev.h>\n+#include <rte_vhost_crypto.h>\n+\n+#define NB_VIRTIO_QUEUES\t(1)\n+#define MAX_PKT_BURST \t\t\t(64) /**< Max burst size for RX/TX */\n+#define NB_MEMPOOL_OBJS\t\t\t(1024)\n+#define NB_CRYPTO_DESCRIPTORS\t\t(1024)\n+#define NB_CACHE_OBJS\t\t\t(128)\n+#define SESSION_MAP_ENTRIES\t\t(1024) /**< Max nb sessions per vdev */\n+\n+#define MAX_NB_SOCKETS\t\t\t(32)\n+#define DEF_SOCKET_FILE\t\t\t\"/tmp/vhost_crypto1.socket\"\n+\n+struct vhost_crypto_options {\n+\tchar *socket_files[MAX_NB_SOCKETS];\n+\tuint32_t nb_sockets;\n+\tuint64_t cryptodev_mask;\n+\tint no_copy;\n+} options;\n+\n+struct vhost_crypto_info {\n+\tint vids[MAX_NB_SOCKETS];\n+\tstruct rte_mempool *sess_pool;\n+\tstruct rte_mempool *cop_pool;\n+\tuint32_t lcore_id;\n+\tuint8_t cid;\n+\tvolatile uint32_t initialized;\n+} info;\n+\n+#define NO_COPY_KEYWORD\t\t\"no-copy\"\n+#define SOCKET_FILE_KEYWORD\t\"socket-file\"\n+#define CRYPTODEV_MASK_KEYWORD\t\"cryptodev-mask\"\n+\n+/** support *SOCKET_FILE_PATH:CRYPTODEV_ID* format */\n+static int\n+parse_socket_arg(char *arg)\n+{\n+\tuint32_t nb_sockets = options.nb_sockets;\n+\tsize_t len = strlen(arg);\n+\n+\tif (nb_sockets >= MAX_NB_SOCKETS) {\n+\t\tRTE_LOG(ERR, USER1, \"Too many socket files!\\n\");\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\toptions.socket_files[nb_sockets] = rte_malloc(NULL, len, 0);\n+\tif (!options.socket_files[nb_sockets]) {\n+\t\tRTE_LOG(ERR, USER1, \"Insufficient memory\\n\");\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\trte_memcpy(options.socket_files[nb_sockets], arg, len);\n+\n+\toptions.nb_sockets++;\n+\n+\treturn 0;\n+}\n+\n+static int\n+parse_cryptodev_mask(const char *q_arg)\n+{\n+\tchar *end = NULL;\n+\tuint64_t pm;\n+\n+\t/* parse hexadecimal string */\n+\tpm = strtoul(q_arg, &end, 16);\n+\tif ((pm == '\\0') || (end == NULL) || (*end != '\\0'))\n+\t\tpm = 0;\n+\n+\toptions.cryptodev_mask = pm;\n+\tif (options.cryptodev_mask == 0 ||\n+\t\t\t__builtin_popcountll(options.cryptodev_mask) > 1) {\n+\t\tprintf(\"invalid cryptodev-mask specified\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static void\n+vhost_crypto_usage(const char *prgname)\n+{\n+\tprintf(\"%s [EAL options] --\\n\"\n+\t\t\"  --%s SOCKET-FILE-PATH\\n\"\n+\t\t\"  --%s\\n\" /* no-copy */\n+\t\t\"  --%s MASK: hexadecimal bitmask of crypto devices to configure\\n\",\n+\t\tprgname, SOCKET_FILE_KEYWORD, NO_COPY_KEYWORD,\n+\t\tCRYPTODEV_MASK_KEYWORD);\n+}\n+\n+static int\n+vhost_crypto_parse_args(int argc, char **argv)\n+{\n+\tint opt, ret;\n+\tchar *prgname = argv[0];\n+\tchar **argvopt;\n+\tint option_index;\n+\tstruct option lgopts[] = {\n+\t\t\t{SOCKET_FILE_KEYWORD, required_argument, 0, 0},\n+\t\t\t{CRYPTODEV_MASK_KEYWORD, required_argument, 0, 0},\n+\t\t\t{NO_COPY_KEYWORD, no_argument, 0, 0},\n+\t\t\t{NULL, 0, 0, 0}\n+\t};\n+\n+\targvopt = argv;\n+\n+\twhile ((opt = getopt_long(argc, argvopt, \"s:\",\n+\t\t\t\t  lgopts, &option_index)) != EOF) {\n+\n+\t\tswitch (opt) {\n+\t\tcase 0:\n+\t\t\tif (strcmp(lgopts[option_index].name,\n+\t\t\t\t\tSOCKET_FILE_KEYWORD) == 0) {\n+\t\t\t\tret = parse_socket_arg(optarg);\n+\t\t\t\tif (ret < 0) {\n+\t\t\t\t\tvhost_crypto_usage(prgname);\n+\t\t\t\t\treturn ret;\n+\t\t\t\t}\n+\t\t\t} else if (strcmp(lgopts[option_index].name,\n+\t\t\t\t\tCRYPTODEV_MASK_KEYWORD) == 0) {\n+\t\t\t\tret = parse_cryptodev_mask(optarg);\n+\t\t\t\tif (ret < 0) {\n+\t\t\t\t\tvhost_crypto_usage(prgname);\n+\t\t\t\t\treturn ret;\n+\t\t\t\t}\n+\t\t\t} else if (strcmp(lgopts[option_index].name,\n+\t\t\t\t\tNO_COPY_KEYWORD) == 0)\n+\t\t\t\toptions.no_copy = 1;\n+\t\t\telse {\n+\t\t\t\tvhost_crypto_usage(prgname);\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\tif (options.nb_sockets == 0) {\n+\t\toptions.socket_files[0] = strdup(DEF_SOCKET_FILE);\n+\t\toptions.nb_sockets = 1;\n+\t\tRTE_LOG(INFO, USER1,\n+\t\t\t\t\"VHOST-CRYPTO: use default socket file %s\\n\",\n+\t\t\t\tDEF_SOCKET_FILE);\n+\t}\n+\n+\tif (options.cryptodev_mask == 0)\n+\t\toptions.cryptodev_mask = (1 << options.nb_sockets) - 1;\n+\n+\treturn 0;\n+}\n+\n+static int\n+new_device(int vid)\n+{\n+\tchar path[PATH_MAX];\n+\tuint32_t i;\n+\tint ret;\n+\n+\tret = rte_vhost_get_ifname(vid, path, PATH_MAX);\n+\tif (ret) {\n+\t\tRTE_LOG(ERR, USER1, \"Cannot find matched socket\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\tret = rte_vhost_crypto_create(vid, info.cid, info.sess_pool,\n+\t\t\trte_lcore_to_socket_id(info.lcore_id));\n+\tif (ret) {\n+\t\tRTE_LOG(ERR, USER1, \"Cannot create vhost crypto\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\tfor (i = 0; i < options.nb_sockets; i++) {\n+\t\tif (strcmp(path, options.socket_files[i]) == 0)\n+\t\t\tbreak;\n+\t}\n+\n+\tif (i == options.nb_sockets) {\n+\t\tRTE_LOG(ERR, USER1, \"Cannot find socket file from list\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tinfo.vids[i] = vid;\n+\n+\tinfo.initialized = 1;\n+\n+\tRTE_LOG(INFO, USER1, \"New Vhost-crypto Device %s, Device ID %d\\n\", path,\n+\t\t\tvid);\n+\treturn 0;\n+}\n+\n+static void\n+destroy_device(int vid)\n+{\n+\tinfo.initialized = 0;\n+\n+\trte_vhost_crypto_free(vid);\n+\n+\trte_mempool_free(info.cop_pool);\n+\trte_mempool_free(info.sess_pool);\n+\n+\tRTE_LOG(INFO, USER1, \"Vhost Crypto Device %i Removed\\n\", vid);\n+}\n+\n+static const struct vhost_device_ops virtio_crypto_device_ops =\n+{\n+\t.new_device =  new_device,\n+\t.destroy_device = destroy_device,\n+};\n+\n+/*\n+static void clrscr(void)\n+{\n+    system(\"@cls||clear\");\n+}\n+*/\n+static int\n+vhost_crypto_stats_worker(__rte_unused void *arg)\n+{\n+\tuint64_t t_start, t_end, hz = rte_get_tsc_hz();\n+\tstruct rte_cryptodev_stats stats;\n+\tuint64_t threshold = hz;\n+\tdouble throughput;\n+\n+\tRTE_LOG(INFO, USER1, \"VHOST-CRYPTO: start stats lcore\\n\");\n+\n+\tt_start = rte_rdtsc_precise();\n+\twhile (1) {\n+\t\tuint64_t interval;\n+\t\tuint32_t timeout;\n+\n+\t\tif (unlikely(info.initialized == 0))\n+\t\t\tcontinue;\n+\n+\t\tt_end = rte_rdtsc_precise();\n+\t\tinterval = t_end - t_start;\n+\t\ttimeout = (interval > threshold) ? 1 : 0;\n+\t\tif (timeout)\n+\t\t\tt_start = t_end;\n+\n+\t\tif (unlikely(timeout)) {\n+\t\t\t//clrscr();\n+\n+\t\t\trte_cryptodev_stats_get(info.cid, &stats);\n+\n+\t\t\tif (unlikely(stats.enqueued_count + stats.dequeued_count\n+\t\t\t\t\t+ stats.enqueue_err_count +\n+\t\t\t\t\tstats.dequeue_err_count == 0))\n+\t\t\t\tcontinue;\n+\n+\t\t\tthroughput = ((double)stats.dequeued_count / interval)\n+\t\t\t\t\t* hz;\n+\n+\t\t\tprintf(\"%12s%12s%12s%12s%12s%12s\\n\", \"cryptodevid\",\n+\t\t\t\t\t\"enq reqs\", \"deq reqs\", \"enq err\",\n+\t\t\t\t\t\"deq err\", \"ops/sec\");\n+\t\t\tprintf(\"%12u%12\"PRIu64\"%12\"PRIu64\"%12\"PRIu64\"%12\"\n+\t\t\t\t\tPRIu64\"%12.4f\\n\", info.cid,\n+\t\t\t\t\tstats.enqueued_count,\n+\t\t\t\t\tstats.dequeued_count,\n+\t\t\t\t\tstats.enqueue_err_count,\n+\t\t\t\t\tstats.dequeue_err_count, throughput);\n+\t\t\trte_cryptodev_stats_reset(info.cid);\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static __rte_always_inline int\n+enqueue_and_realloc_cops(uint16_t q_id, struct rte_crypto_op **ops,\n+\t\tuint16_t nb_ops)\n+{\n+\tuint16_t enqd;\n+\n+\tenqd = rte_cryptodev_enqueue_burst(info.cid, q_id, ops,\n+\t\t\tnb_ops);\n+\tif (unlikely(enqd < nb_ops)) {\n+\t\tRTE_LOG(ERR, USER1, \"Cannot enqueue enough cops\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (unlikely(rte_crypto_op_bulk_alloc(info.cop_pool,\n+\t\t\tRTE_CRYPTO_OP_TYPE_SYMMETRIC, ops, enqd) < enqd)) {\n+\t\tRTE_LOG(ERR, USER1, \"Failed to realloc cops\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static __rte_always_inline int\n+dequeue_and_free_cops(uint16_t q_id, struct rte_crypto_op **ops,\n+\t\tuint32_t *inflight)\n+{\n+\tuint16_t nb_ops = *inflight < MAX_PKT_BURST ? *inflight : MAX_PKT_BURST;\n+\tuint64_t vid_mask;\n+\tuint16_t deqd;\n+\tuint8_t i;\n+\n+\tdeqd = rte_cryptodev_dequeue_burst(info.cid, q_id, ops, nb_ops);\n+\n+\tif (!deqd)\n+\t\treturn 0;\n+\n+\tvid_mask = rte_vhost_crypto_finalize_requests(ops, deqd);\n+\n+\trte_mempool_put_bulk(info.cop_pool, (void **)ops, deqd);\n+\n+\tfor (i = 0; i < options.nb_sockets; i++) {\n+\t\tstruct rte_vhost_vring vq;\n+\n+\t\tif (unlikely(((1 << i) & vid_mask) == 0))\n+\t\t\tcontinue;\n+\n+\t\tif (unlikely(rte_vhost_get_vhost_vring(info.vids[i], q_id, &vq)\n+\t\t\t\t< 0)) {\n+\t\t\tRTE_LOG(ERR, USER1, \"Failed to get vring\\n\");\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tif (unlikely(eventfd_write(vq.callfd, (eventfd_t)1) < 0)) {\n+\t\t\tRTE_LOG(ERR, USER1, \"Failed to kick\\n\");\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\t*inflight -= nb_ops;\n+\n+\treturn 0;\n+}\n+\n+static int\n+vhost_crypto_worker(__rte_unused void *arg)\n+{\n+\tstruct rte_crypto_op *ops[NB_VIRTIO_QUEUES][MAX_PKT_BURST + 1];\n+\tstruct rte_crypto_op *ops_deq[NB_VIRTIO_QUEUES][MAX_PKT_BURST + 1];\n+\tstruct rte_cryptodev_qp_conf qp_conf = {NB_CRYPTO_DESCRIPTORS};\n+\tuint32_t nb_inflight_ops[NB_VIRTIO_QUEUES];\n+\tuint16_t fetched[NB_VIRTIO_QUEUES];\n+\tuint32_t lcore_id = rte_lcore_id();\n+\tint socket_id = rte_lcore_to_socket_id(lcore_id);\n+\tstruct rte_cryptodev_config config = {socket_id, NB_VIRTIO_QUEUES};\n+\tuint64_t t_start, t_end, hz = rte_get_tsc_hz();\n+\tuint64_t threshold = hz / 100;\n+\tuint32_t i, j;\n+\tchar name[128];\n+\tint ret = 0;\n+\n+\tRTE_LOG(INFO, USER1, \"Procesing on Core %u started\\n\", lcore_id);\n+\n+\tret =rte_cryptodev_configure(info.cid, &config);\n+\tif (ret < 0) {\n+\t\tRTE_LOG(ERR, USER1, \"Failed to configure cryptodev %u\",\n+\t\t\t\tinfo.cid);\n+\t\tgoto exit;\n+\t}\n+\n+\tsnprintf(name, 127, \"COPPOOL_%u\", lcore_id);\n+\tinfo.cop_pool = rte_vhost_crypto_create_cop_pool(name,\n+\t\t\tRTE_CRYPTO_OP_TYPE_SYMMETRIC, NB_MEMPOOL_OBJS,\n+\t\t\tNB_CACHE_OBJS, socket_id);\n+\tif (!info.cop_pool) {\n+\t\tRTE_LOG(ERR, USER1, \"Lcore %u failed to create crypto pool\",\n+\t\t\t\tlcore_id);\n+\t\tret = -1;\n+\t\tgoto exit;\n+\t}\n+\n+\tfor (i = 0; i < NB_VIRTIO_QUEUES; i++) {\n+\t\tret = rte_cryptodev_queue_pair_setup(info.cid, i, &qp_conf,\n+\t\t\t\tsocket_id, info.sess_pool);\n+\t\tif (ret < 0) {\n+\t\t\tRTE_LOG(ERR, USER1, \"Failed to configure qp %u\\n\",\n+\t\t\t\t\tinfo.cid);\n+\t\t\tgoto exit;\n+\t\t}\n+\n+\t\tif (rte_crypto_op_bulk_alloc(info.cop_pool,\n+\t\t\t\tRTE_CRYPTO_OP_TYPE_SYMMETRIC, ops[i],\n+\t\t\t\tMAX_PKT_BURST) < MAX_PKT_BURST) {\n+\t\t\tRTE_LOG(ERR, USER1, \"Failed to alloc cops\\n\");\n+\t\t\tret = -1;\n+\t\t\tgoto exit;\n+\t\t}\n+\n+\t\tfetched[i] = 0;\n+\t\tnb_inflight_ops[i] = 0;\n+\t}\n+\n+\tt_start = rte_rdtsc_precise();\n+\twhile (1) {\n+\t\tuint64_t interval;\n+\t\tuint32_t timeout;\n+\n+\t\tif (unlikely(info.initialized == 0))\n+\t\t\tcontinue;\n+\n+\t\tt_end = rte_rdtsc_precise();\n+\t\tinterval = t_end - t_start;\n+\t\ttimeout = (interval > threshold) ? 1 : 0;\n+\t\tif (timeout)\n+\t\t\tt_start = t_end;\n+\n+\t\tif (unlikely(timeout)) {\n+\t\t\tfor (j = 0; j < NB_VIRTIO_QUEUES; j++) {\n+\t\t\t\tif (unlikely(enqueue_and_realloc_cops(j,\n+\t\t\t\t\t\tops[j], fetched[j]) < 0))\n+\t\t\t\t\tgoto exit;\n+\n+\t\t\t\tnb_inflight_ops[j] += fetched[j];\n+\t\t\t\tfetched[j] = 0;\n+\n+\t\t\t\tif (unlikely(dequeue_and_free_cops(j,\n+\t\t\t\t\t\tops_deq[j], &nb_inflight_ops[j])\n+\t\t\t\t\t\t< 0))\n+\t\t\t\t\tgoto exit;\n+\t\t\t}\n+\t\t}\n+\n+\t\tfor (j = 0; j < NB_VIRTIO_QUEUES; j++) {\n+\t\t\tfor (i = 0; i < options.nb_sockets; i++) {\n+\t\t\t\tuint16_t to_fetch = MAX_PKT_BURST -\n+\t\t\t\t\t\tfetched[j];\n+\t\t\t\tuint16_t available = NB_CACHE_OBJS -\n+\t\t\t\t\t\tnb_inflight_ops[j];\n+\n+\t\t\t\tfetched[j] += rte_vhost_crypto_fetch_requests(\n+\t\t\t\t\tinfo.vids[i], j, &ops[j][fetched[j]],\n+\t\t\t\t\tRTE_MIN(to_fetch, available));\n+\n+\t\t\t\tif (fetched[j] >= MAX_PKT_BURST) {\n+\t\t\t\t\tif (unlikely(enqueue_and_realloc_cops(j,\n+\t\t\t\t\t\t\tops[j], fetched[j])\n+\t\t\t\t\t\t\t< 0))\n+\t\t\t\t\t\tgoto exit;\n+\n+\t\t\t\t\tnb_inflight_ops[j] += fetched[j];\n+\t\t\t\t\tfetched[j] = 0;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tif (nb_inflight_ops[j] >= MAX_PKT_BURST) {\n+\t\t\t\tif (unlikely(dequeue_and_free_cops(j,\n+\t\t\t\t\t\tops_deq[j],\n+\t\t\t\t\t\t&nb_inflight_ops[j]) < 0))\n+\t\t\t\t\tgoto exit;\n+\t\t\t}\n+\t\t}\n+\t}\n+exit:\n+\trte_mempool_free(info.cop_pool);\n+\trte_mempool_free(info.sess_pool);\n+\treturn ret;\n+}\n+\n+\n+static void\n+unregister_drivers(int socket_num)\n+{\n+\tint ret;\n+\n+\tret = rte_vhost_driver_unregister(options.socket_files[socket_num]);\n+\tif (ret != 0)\n+\t\tRTE_LOG(ERR, USER1,\n+\t\t\t\"Fail to unregister vhost driver for %s.\\n\",\n+\t\t\toptions.socket_files[socket_num]);\n+}\n+\n+int\n+main(int argc, char *argv[])\n+{\n+\tstruct rte_cryptodev_info dev_info;\n+\tstruct rte_mempool *sess_pool;\n+\tuint32_t cryptodev_id;\n+\tuint32_t worker_lcore;\n+\tuint32_t stats_lcore;\n+\tchar name[128];\n+\tuint32_t i = 0;\n+\tint ret;\n+\n+\tret = rte_eal_init(argc, argv);\n+\tif (ret < 0)\n+\t\treturn -1;\n+\targc -= ret;\n+\targv += ret;\n+\n+\tret = vhost_crypto_parse_args(argc, argv);\n+\tif (ret < 0) {\n+\t\trte_exit(EXIT_FAILURE, \"Failed to parse arguments!\\n\");\n+\t}\n+\n+\tworker_lcore = rte_get_next_lcore(0, 1, 0);\n+\tstats_lcore = rte_get_next_lcore(worker_lcore, 1, 0);\n+\tif (worker_lcore == RTE_MAX_LCORE || stats_lcore == RTE_MAX_LCORE)\n+\t\trte_exit(EXIT_FAILURE, \"Not enough lcore\\n\");\n+\n+\tfor (cryptodev_id = 0; cryptodev_id < rte_cryptodev_count();\n+\t\t\tcryptodev_id++) {\n+\t\tuint64_t id = 1ULL << cryptodev_id;\n+\n+\t\tif (id & options.cryptodev_mask)\n+\t\t\tbreak;\n+\t}\n+\n+\tif (cryptodev_id == rte_cryptodev_count()) {\n+\t\tRTE_LOG(ERR, USER1, \"Not enough Cryptodevs\\n\");\n+\t\tgoto error_exit;\n+\t}\n+\n+\trte_cryptodev_info_get(cryptodev_id, &dev_info);\n+\tif (dev_info.max_nb_queue_pairs < NB_VIRTIO_QUEUES) {\n+\t\tRTE_LOG(ERR, USER1, \"Number of queues cannot over %u\",\n+\t\t\t\tdev_info.max_nb_queue_pairs);\n+\t\tgoto error_exit;\n+\t}\n+\n+\tsnprintf(name, 127, \"SESS_POOL_%u\", worker_lcore);\n+\tsess_pool = rte_mempool_create(name, SESSION_MAP_ENTRIES,\n+\t\t\trte_cryptodev_get_private_session_size(\n+\t\t\tcryptodev_id), 64, 0, NULL, NULL, NULL, NULL,\n+\t\t\trte_lcore_to_socket_id(worker_lcore), 0);\n+\tif (!sess_pool) {\n+\t\tRTE_LOG(ERR, USER1, \"Failed to create mempool\");\n+\t\tgoto error_exit;\n+\t}\n+\n+\tinfo.cid = cryptodev_id;\n+\tinfo.sess_pool = sess_pool;\n+\tinfo.lcore_id = worker_lcore;\n+\n+\tif (rte_eal_remote_launch(vhost_crypto_worker, NULL, worker_lcore)\n+\t\t\t< 0) {\n+\t\tRTE_LOG(ERR, USER1, \"Failed to start worker lcore\");\n+\t\tgoto error_exit;\n+\t}\n+\tif (rte_eal_remote_launch(vhost_crypto_stats_worker, NULL, stats_lcore)\n+\t\t\t< 0) {\n+\t\t {\n+\t\tRTE_LOG(ERR, USER1, \"Failed to start stats lcore\");\n+\t\tgoto error_exit;\n+\t}\n+\t}\n+\n+\tfor (i = 0; i < options.nb_sockets; i++) {\n+\t\tif (rte_vhost_driver_register(options.socket_files[i], 0) < 0) {\n+\t\t\tRTE_LOG(ERR, USER1, \"socket %s already exists\\n\",\n+\t\t\t\t\toptions.socket_files[i]);\n+\t\t\tgoto error_exit;\n+\t\t}\n+\n+\t\trte_vhost_driver_callback_register(options.socket_files[i],\n+\t\t\t\t&virtio_crypto_device_ops);\n+\n+\t\tif (rte_vhost_driver_start(options.socket_files[i]) < 0) {\n+\t\t\tRTE_LOG(ERR, USER1, \"failed to start vhost driver.\\n\");\n+\t\t\tgoto error_exit;\n+\t\t}\n+\t}\n+\n+\tRTE_LCORE_FOREACH(worker_lcore)\n+\t\trte_eal_wait_lcore(worker_lcore);\n+\n+\treturn 0;\n+\n+error_exit:\n+\tfor (i = 0; i < options.nb_sockets; i++)\n+\t\tunregister_drivers(i);\n+\n+\trte_mempool_free(info.sess_pool);\n+\n+\treturn -1;\n+}\n+\n",
    "prefixes": [
        "dpdk-dev",
        "RFC",
        "6/6"
    ]
}