From: Fan Zhang Date: Mon, 3 Apr 2017 15:33:19 +0000 (+0100) Subject: crypto/scheduler: add more options X-Git-Tag: spdx-start~3706 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=a0e805ee086a87b2a787a4deb139775a01790c7c;p=dpdk.git crypto/scheduler: add more options This patch adds initial mode and ordering enable/disable EAL options to cryptodev scheduler PMD. Signed-off-by: Fan Zhang Acked-by: Declan Doherty --- diff --git a/doc/guides/cryptodevs/scheduler.rst b/doc/guides/cryptodevs/scheduler.rst index d516ba873c..0482331618 100644 --- a/doc/guides/cryptodevs/scheduler.rst +++ b/doc/guides/cryptodevs/scheduler.rst @@ -94,6 +94,14 @@ two calls: here. Multiple cryptodevs can be attached initially by presenting this parameter multiple times. +* mode: Specify the scheduling mode of the PMD. The supported scheduling + mode parameter values are specified in the "Cryptodev Scheduler Modes + Overview" section. + +* ordering: Specify the status of the crypto operations ordering feature. + The value of this parameter can be "enable" or "disable". This feature + is disabled by default. + Example: .. code-block:: console @@ -122,6 +130,8 @@ operation: * **CDEV_SCHED_MODE_ROUNDROBIN:** + *Initialization mode parameter*: **round-robin** + Round-robin mode, which distributes the enqueued burst of crypto ops among its slaves in a round-robin manner. This mode may help to fill the throughput gap between the physical core and the existing cryptodevs @@ -129,6 +139,8 @@ operation: * **CDEV_SCHED_MODE_PKT_SIZE_DISTR:** + *Initialization mode parameter*: **packet-size-distr** + Packet-size based distribution mode, which works with 2 slaves, the primary slave and the secondary slave, and distributes the enqueued crypto operations to them based on their data lengths. A crypto operation will be @@ -144,6 +156,8 @@ operation: * **CDEV_SCHED_MODE_FAILOVER:** + *Initialization mode parameter*: **fail-over** + Fail-over mode, which works with 2 slaves, the primary slave and the secondary slave. In this mode, the scheduler will enqueue the incoming crypto operation burst to the primary slave. When one or more crypto diff --git a/drivers/crypto/scheduler/rte_cryptodev_scheduler.h b/drivers/crypto/scheduler/rte_cryptodev_scheduler.h index 1b522613d0..1da096ba21 100644 --- a/drivers/crypto/scheduler/rte_cryptodev_scheduler.h +++ b/drivers/crypto/scheduler/rte_cryptodev_scheduler.h @@ -45,7 +45,14 @@ extern "C" { #define RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES (8) #endif +/* round-robin scheduling mode */ +#define SCHEDULER_MODE_NAME_ROUND_ROBIN round-robin +/* packet-size based distribution scheduling mode */ +#define SCHEDULER_MODE_NAME_PKT_SIZE_DISTR packet-size-distr +/* fail-over mode */ +#define SCHEDULER_MODE_NAME_FAIL_OVER fail-over /** + * Crypto scheduler PMD operation modes */ enum rte_cryptodev_scheduler_mode { diff --git a/drivers/crypto/scheduler/scheduler_pmd.c b/drivers/crypto/scheduler/scheduler_pmd.c index dc7192f546..f117ed8980 100644 --- a/drivers/crypto/scheduler/scheduler_pmd.c +++ b/drivers/crypto/scheduler/scheduler_pmd.c @@ -45,10 +45,14 @@ struct scheduler_init_params { struct rte_crypto_vdev_init_params def_p; uint32_t nb_slaves; uint8_t slaves[RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES]; + enum rte_cryptodev_scheduler_mode mode; + uint32_t enable_ordering; }; -#define RTE_CRYPTODEV_VDEV_NAME ("name") -#define RTE_CRYPTODEV_VDEV_SLAVE ("slave") +#define RTE_CRYPTODEV_VDEV_NAME ("name") +#define RTE_CRYPTODEV_VDEV_SLAVE ("slave") +#define RTE_CRYPTODEV_VDEV_MODE ("mode") +#define RTE_CRYPTODEV_VDEV_ORDERING ("ordering") #define RTE_CRYPTODEV_VDEV_MAX_NB_QP_ARG ("max_nb_queue_pairs") #define RTE_CRYPTODEV_VDEV_MAX_NB_SESS_ARG ("max_nb_sessions") #define RTE_CRYPTODEV_VDEV_SOCKET_ID ("socket_id") @@ -56,11 +60,32 @@ struct scheduler_init_params { const char *scheduler_valid_params[] = { RTE_CRYPTODEV_VDEV_NAME, RTE_CRYPTODEV_VDEV_SLAVE, + RTE_CRYPTODEV_VDEV_MODE, + RTE_CRYPTODEV_VDEV_ORDERING, RTE_CRYPTODEV_VDEV_MAX_NB_QP_ARG, RTE_CRYPTODEV_VDEV_MAX_NB_SESS_ARG, RTE_CRYPTODEV_VDEV_SOCKET_ID }; +struct scheduler_parse_map { + const char *name; + uint32_t val; +}; + +const struct scheduler_parse_map scheduler_mode_map[] = { + {RTE_STR(SCHEDULER_MODE_NAME_ROUND_ROBIN), + CDEV_SCHED_MODE_ROUNDROBIN}, + {RTE_STR(SCHEDULER_MODE_NAME_PKT_SIZE_DISTR), + CDEV_SCHED_MODE_PKT_SIZE_DISTR}, + {RTE_STR(SCHEDULER_MODE_NAME_FAIL_OVER), + CDEV_SCHED_MODE_FAILOVER} +}; + +const struct scheduler_parse_map scheduler_ordering_map[] = { + {"enable", 1}, + {"disable", 0} +}; + static int attach_init_slaves(uint8_t scheduler_id, const uint8_t *slaves, const uint8_t nb_slaves) @@ -79,8 +104,7 @@ attach_init_slaves(uint8_t scheduler_id, return status; } - RTE_LOG(INFO, PMD, " Attached slave cryptodev %s\n", - dev->data->name); + RTE_LOG(INFO, PMD, " Attached Slave %s\n", dev->data->name); } return 0; @@ -93,9 +117,11 @@ cryptodev_scheduler_create(const char *name, char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN] = {0}; struct rte_cryptodev *dev; struct scheduler_ctx *sched_ctx; + uint32_t i; + int ret; if (init_params->def_p.name[0] == '\0') { - int ret = rte_cryptodev_pmd_create_dev_name( + ret = rte_cryptodev_pmd_create_dev_name( crypto_dev_name, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); @@ -124,8 +150,46 @@ cryptodev_scheduler_create(const char *name, sched_ctx->max_nb_queue_pairs = init_params->def_p.max_nb_queue_pairs; - return attach_init_slaves(dev->data->dev_id, init_params->slaves, + ret = attach_init_slaves(dev->data->dev_id, init_params->slaves, init_params->nb_slaves); + if (ret < 0) { + rte_cryptodev_pmd_release_device(dev); + return ret; + } + + if (init_params->mode > CDEV_SCHED_MODE_USERDEFINED && + init_params->mode < CDEV_SCHED_MODE_COUNT) { + ret = rte_crpytodev_scheduler_mode_set(dev->data->dev_id, + init_params->mode); + if (ret < 0) { + rte_cryptodev_pmd_release_device(dev); + return ret; + } + + for (i = 0; i < RTE_DIM(scheduler_mode_map); i++) { + if (scheduler_mode_map[i].val != sched_ctx->mode) + continue; + + RTE_LOG(INFO, PMD, " Scheduling mode = %s\n", + scheduler_mode_map[i].name); + break; + } + } + + sched_ctx->reordering_enabled = init_params->enable_ordering; + + for (i = 0; i < RTE_DIM(scheduler_ordering_map); i++) { + if (scheduler_ordering_map[i].val != + sched_ctx->reordering_enabled) + continue; + + RTE_LOG(INFO, PMD, " Packet ordering = %s\n", + scheduler_ordering_map[i].name); + + break; + } + + return 0; } static int @@ -183,7 +247,7 @@ parse_integer_arg(const char *key __rte_unused, *i = atoi(value); if (*i < 0) { CS_LOG_ERR("Argument has to be positive.\n"); - return -1; + return -EINVAL; } return 0; @@ -200,7 +264,7 @@ parse_name_arg(const char *key __rte_unused, CS_LOG_ERR("Invalid name %s, should be less than " "%u bytes.\n", value, RTE_CRYPTODEV_NAME_MAX_LEN - 1); - return -1; + return -EINVAL; } strncpy(params->name, value, RTE_CRYPTODEV_NAME_MAX_LEN); @@ -219,12 +283,12 @@ parse_slave_arg(const char *key __rte_unused, if (!dev) { RTE_LOG(ERR, PMD, "Invalid slave name %s.\n", value); - return -1; + return -EINVAL; } if (param->nb_slaves >= RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES - 1) { CS_LOG_ERR("Too many slaves.\n"); - return -1; + return -ENOMEM; } param->slaves[param->nb_slaves] = dev->data->dev_id; @@ -233,6 +297,52 @@ parse_slave_arg(const char *key __rte_unused, return 0; } +static int +parse_mode_arg(const char *key __rte_unused, + const char *value, void *extra_args) +{ + struct scheduler_init_params *param = extra_args; + uint32_t i; + + for (i = 0; i < RTE_DIM(scheduler_mode_map); i++) { + if (strcmp(value, scheduler_mode_map[i].name) == 0) { + param->mode = (enum rte_cryptodev_scheduler_mode) + scheduler_mode_map[i].val; + break; + } + } + + if (i == RTE_DIM(scheduler_mode_map)) { + CS_LOG_ERR("Unrecognized input.\n"); + return -EINVAL; + } + + return 0; +} + +static int +parse_ordering_arg(const char *key __rte_unused, + const char *value, void *extra_args) +{ + struct scheduler_init_params *param = extra_args; + uint32_t i; + + for (i = 0; i < RTE_DIM(scheduler_ordering_map); i++) { + if (strcmp(value, scheduler_ordering_map[i].name) == 0) { + param->enable_ordering = + scheduler_ordering_map[i].val; + break; + } + } + + if (i == RTE_DIM(scheduler_ordering_map)) { + CS_LOG_ERR("Unrecognized input.\n"); + return -EINVAL; + } + + return 0; +} + static int scheduler_parse_init_params(struct scheduler_init_params *params, const char *input_args) @@ -280,6 +390,16 @@ scheduler_parse_init_params(struct scheduler_init_params *params, if (ret < 0) goto free_kvlist; + ret = rte_kvargs_process(kvlist, RTE_CRYPTODEV_VDEV_MODE, + &parse_mode_arg, params); + if (ret < 0) + goto free_kvlist; + + ret = rte_kvargs_process(kvlist, RTE_CRYPTODEV_VDEV_ORDERING, + &parse_ordering_arg, params); + if (ret < 0) + goto free_kvlist; + if (params->def_p.socket_id >= number_of_sockets()) { CDEV_LOG_ERR("Invalid socket id specified to create " "the virtual crypto device on"); @@ -303,7 +423,9 @@ cryptodev_scheduler_probe(const char *name, const char *input_args) "" }, .nb_slaves = 0, - .slaves = {0} + .slaves = {0}, + .mode = CDEV_SCHED_MODE_NOT_SET, + .enable_ordering = 0 }; scheduler_parse_init_params(&init_params, input_args);