examples/performance-thread: fix build with ASan
[dpdk.git] / examples / vhost_crypto / main.c
index cb30f84..dea7dcb 100644 (file)
@@ -46,6 +46,7 @@ struct vhost_crypto_info {
        int vids[MAX_NB_SOCKETS];
        uint32_t nb_vids;
        struct rte_mempool *sess_pool;
+       struct rte_mempool *sess_priv_pool;
        struct rte_mempool *cop_pool;
        uint8_t cid;
        uint32_t qid;
@@ -61,10 +62,16 @@ struct vhost_crypto_options {
        uint32_t guest_polling;
 } options;
 
-#define CONFIG_KEYWORD         "config"
-#define SOCKET_FILE_KEYWORD    "socket-file"
-#define ZERO_COPY_KEYWORD      "zero-copy"
-#define POLLING_KEYWORD                "guest-polling"
+enum {
+#define OPT_CONFIG          "config"
+       OPT_CONFIG_NUM = 256,
+#define OPT_SOCKET_FILE     "socket-file"
+       OPT_SOCKET_FILE_NUM,
+#define OPT_ZERO_COPY       "zero-copy"
+       OPT_ZERO_COPY_NUM,
+#define OPT_POLLING         "guest-polling"
+       OPT_POLLING_NUM,
+};
 
 #define NB_SOCKET_FIELDS       (2)
 
@@ -194,11 +201,11 @@ vhost_crypto_usage(const char *prgname)
 {
        printf("%s [EAL options] --\n"
                "  --%s <lcore>,SOCKET-FILE-PATH\n"
-               "  --%s (lcore,cdev_id,queue_id)[,(lcore,cdev_id,queue_id)]"
+               "  --%s (lcore,cdev_id,queue_id)[,(lcore,cdev_id,queue_id)]\n"
                "  --%s: zero copy\n"
                "  --%s: guest polling\n",
-               prgname, SOCKET_FILE_KEYWORD, CONFIG_KEYWORD,
-               ZERO_COPY_KEYWORD, POLLING_KEYWORD);
+               prgname, OPT_SOCKET_FILE, OPT_CONFIG,
+               OPT_ZERO_COPY, OPT_POLLING);
 }
 
 static int
@@ -209,48 +216,56 @@ vhost_crypto_parse_args(int argc, char **argv)
        char **argvopt;
        int option_index;
        struct option lgopts[] = {
-                       {SOCKET_FILE_KEYWORD, required_argument, 0, 0},
-                       {CONFIG_KEYWORD, required_argument, 0, 0},
-                       {ZERO_COPY_KEYWORD, no_argument, 0, 0},
-                       {POLLING_KEYWORD, no_argument, 0, 0},
-                       {NULL, 0, 0, 0}
+               {OPT_SOCKET_FILE, required_argument,
+                               NULL, OPT_SOCKET_FILE_NUM},
+               {OPT_CONFIG, required_argument,
+                               NULL, OPT_CONFIG_NUM},
+               {OPT_ZERO_COPY, no_argument,
+                               NULL, OPT_ZERO_COPY_NUM},
+               {OPT_POLLING, no_argument,
+                               NULL, OPT_POLLING_NUM},
+               {NULL, 0, 0, 0}
        };
 
        argvopt = argv;
 
-       while ((opt = getopt_long(argc, argvopt, "s:",
+       while ((opt = getopt_long(argc, argvopt, "",
                                  lgopts, &option_index)) != EOF) {
 
+               if (opt == '?') {
+                       vhost_crypto_usage(prgname);
+                       return -1;
+               }
+
                switch (opt) {
-               case 0:
-                       if (strcmp(lgopts[option_index].name,
-                                       SOCKET_FILE_KEYWORD) == 0) {
-                               ret = parse_socket_arg(optarg);
-                               if (ret < 0) {
-                                       vhost_crypto_usage(prgname);
-                                       return ret;
-                               }
-                       } else if (strcmp(lgopts[option_index].name,
-                                       CONFIG_KEYWORD) == 0) {
-                               ret = parse_config(optarg);
-                               if (ret < 0) {
-                                       vhost_crypto_usage(prgname);
-                                       return ret;
-                               }
-                       } else if (strcmp(lgopts[option_index].name,
-                                       ZERO_COPY_KEYWORD) == 0) {
-                               options.zero_copy =
-                                       RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE;
-                       } else if (strcmp(lgopts[option_index].name,
-                                       POLLING_KEYWORD) == 0) {
-                               options.guest_polling = 1;
-                       } else {
+               case OPT_SOCKET_FILE_NUM:
+                       ret = parse_socket_arg(optarg);
+                       if (ret < 0) {
                                vhost_crypto_usage(prgname);
-                               return -EINVAL;
+                               return ret;
                        }
                        break;
+
+               case OPT_CONFIG_NUM:
+                       ret = parse_config(optarg);
+                       if (ret < 0) {
+                               vhost_crypto_usage(prgname);
+                               return ret;
+                       }
+                       break;
+
+               case OPT_ZERO_COPY_NUM:
+                       options.zero_copy =
+                               RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE;
+                       break;
+
+               case OPT_POLLING_NUM:
+                       options.guest_polling = 1;
+                       break;
+
                default:
-                       return -1;
+                       vhost_crypto_usage(prgname);
+                       return -EINVAL;
                }
        }
 
@@ -289,6 +304,7 @@ new_device(int vid)
        }
 
        ret = rte_vhost_crypto_create(vid, info->cid, info->sess_pool,
+                       info->sess_priv_pool,
                        rte_lcore_to_socket_id(options.los[i].lcore_id));
        if (ret) {
                RTE_LOG(ERR, USER1, "Cannot create vhost crypto\n");
@@ -352,12 +368,6 @@ static const struct vhost_device_ops virtio_crypto_device_ops = {
        .destroy_device = destroy_device,
 };
 
-__attribute__((unused))
-static void clrscr(void)
-{
-       system("@cls||clear");
-}
-
 static int
 vhost_crypto_worker(void *arg)
 {
@@ -448,6 +458,7 @@ free_resource(void)
 
                rte_mempool_free(info->cop_pool);
                rte_mempool_free(info->sess_pool);
+               rte_mempool_free(info->sess_priv_pool);
 
                for (j = 0; j < lo->nb_sockets; j++) {
                        rte_vhost_driver_unregister(lo->socket_files[i]);
@@ -458,6 +469,9 @@ free_resource(void)
        }
 
        memset(&options, 0, sizeof(options));
+
+       /* clean up the EAL */
+       rte_eal_cleanup();
 }
 
 int
@@ -519,6 +533,7 @@ main(int argc, char *argv[])
 
                config.nb_queue_pairs = dev_info.max_nb_queue_pairs;
                config.socket_id = rte_lcore_to_socket_id(lo->lcore_id);
+               config.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
 
                ret = rte_cryptodev_configure(info->cid, &config);
                if (ret < 0) {
@@ -528,11 +543,17 @@ main(int argc, char *argv[])
                }
 
                snprintf(name, 127, "SESS_POOL_%u", lo->lcore_id);
-               info->sess_pool = rte_mempool_create(name, SESSION_MAP_ENTRIES,
+               info->sess_pool = rte_cryptodev_sym_session_pool_create(name,
+                               SESSION_MAP_ENTRIES, 0, 0, 0,
+                               rte_lcore_to_socket_id(lo->lcore_id));
+
+               snprintf(name, 127, "SESS_POOL_PRIV_%u", lo->lcore_id);
+               info->sess_priv_pool = rte_mempool_create(name,
+                               SESSION_MAP_ENTRIES,
                                rte_cryptodev_sym_get_private_session_size(
                                info->cid), 64, 0, NULL, NULL, NULL, NULL,
                                rte_lcore_to_socket_id(lo->lcore_id), 0);
-               if (!info->sess_pool) {
+               if (!info->sess_priv_pool || !info->sess_pool) {
                        RTE_LOG(ERR, USER1, "Failed to create mempool");
                        goto error_exit;
                }
@@ -540,7 +561,7 @@ main(int argc, char *argv[])
                snprintf(name, 127, "COPPOOL_%u", lo->lcore_id);
                info->cop_pool = rte_crypto_op_pool_create(name,
                                RTE_CRYPTO_OP_TYPE_SYMMETRIC, NB_MEMPOOL_OBJS,
-                               NB_CACHE_OBJS, 0,
+                               NB_CACHE_OBJS, VHOST_CRYPTO_MAX_IV_LEN,
                                rte_lcore_to_socket_id(lo->lcore_id));
 
                if (!info->cop_pool) {
@@ -553,7 +574,7 @@ main(int argc, char *argv[])
 
                qp_conf.nb_descriptors = NB_CRYPTO_DESCRIPTORS;
                qp_conf.mp_session = info->sess_pool;
-               qp_conf.mp_session_private = info->sess_pool;
+               qp_conf.mp_session_private = info->sess_priv_pool;
 
                for (j = 0; j < dev_info.max_nb_queue_pairs; j++) {
                        ret = rte_cryptodev_queue_pair_setup(info->cid, j,
@@ -584,7 +605,7 @@ main(int argc, char *argv[])
 
                for (j = 0; j < lo->nb_sockets; j++) {
                        ret = rte_vhost_driver_register(lo->socket_files[j],
-                               RTE_VHOST_USER_DEQUEUE_ZERO_COPY);
+                               RTE_VHOST_USER_ASYNC_COPY);
                        if (ret < 0) {
                                RTE_LOG(ERR, USER1, "socket %s already exists\n",
                                        lo->socket_files[j]);
@@ -594,7 +615,8 @@ main(int argc, char *argv[])
                        rte_vhost_driver_callback_register(lo->socket_files[j],
                                &virtio_crypto_device_ops);
 
-                       ret = rte_vhost_driver_start(lo->socket_files[j]);
+                       ret = rte_vhost_crypto_driver_start(
+                                       lo->socket_files[j]);
                        if (ret < 0)  {
                                RTE_LOG(ERR, USER1, "failed to start vhost.\n");
                                goto error_exit;