crypto/scheduler: support mode specific option
authorFan Zhang <roy.fan.zhang@intel.com>
Wed, 5 Apr 2017 16:07:09 +0000 (17:07 +0100)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Thu, 20 Apr 2017 09:32:45 +0000 (11:32 +0200)
Some scheduling modes may need extra options to be configured,
this patch adds the function prototype for setting/getting
options.

Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Declan Doherty <declan.doherty@intel.com>
doc/guides/cryptodevs/scheduler.rst
doc/guides/rel_notes/release_17_05.rst
drivers/crypto/scheduler/rte_cryptodev_scheduler.c
drivers/crypto/scheduler/rte_cryptodev_scheduler.h
drivers/crypto/scheduler/rte_cryptodev_scheduler_operations.h
drivers/crypto/scheduler/rte_pmd_crypto_scheduler_version.map
drivers/crypto/scheduler/scheduler_failover.c
drivers/crypto/scheduler/scheduler_pkt_size_distr.c
drivers/crypto/scheduler/scheduler_roundrobin.c

index 0482331..ddc02b4 100644 (file)
@@ -154,6 +154,13 @@ operation:
    its own, by making use of the available CPU cycles to deal with smaller
    crypto workloads.
 
    its own, by making use of the available CPU cycles to deal with smaller
    crypto workloads.
 
+   The threshold is set to 128 bytes by default. It can be updated by calling
+   function **rte_cryptodev_scheduler_option_set**. The parameter of
+   **option_type** must be **CDEV_SCHED_OPTION_THRESHOLD** and **option** should
+   point to a rte_cryptodev_scheduler_threshold_option structure filled with
+   appropriate threshold value. Please NOTE this threshold has be a power-of-2
+   unsigned integer.
+
 *   **CDEV_SCHED_MODE_FAILOVER:**
 
    *Initialization mode parameter*: **fail-over**
 *   **CDEV_SCHED_MODE_FAILOVER:**
 
    *Initialization mode parameter*: **fail-over**
index 25e7144..47efeed 100644 (file)
@@ -269,6 +269,8 @@ New Features
   * Added fail-over scheduling mode, which enqueues crypto operations to a
     primary slave first. Then, any operation that cannot be enqueued is
     enqueued to a secondary slave.
   * Added fail-over scheduling mode, which enqueues crypto operations to a
     primary slave first. Then, any operation that cannot be enqueued is
     enqueued to a secondary slave.
+  * Added mode specific option support, so each scheduleing mode can
+    now be configured individually by the new added API.
 
 * **Updated the QAT PMD.**
 
 
 * **Updated the QAT PMD.**
 
index 31309c5..319dcf0 100644 (file)
@@ -479,6 +479,8 @@ rte_cryptodev_scheduler_load_user_scheduler(uint8_t scheduler_id,
        sched_ctx->ops.scheduler_stop = scheduler->ops->scheduler_stop;
        sched_ctx->ops.slave_attach = scheduler->ops->slave_attach;
        sched_ctx->ops.slave_detach = scheduler->ops->slave_detach;
        sched_ctx->ops.scheduler_stop = scheduler->ops->scheduler_stop;
        sched_ctx->ops.slave_attach = scheduler->ops->slave_attach;
        sched_ctx->ops.slave_detach = scheduler->ops->slave_detach;
+       sched_ctx->ops.option_set = scheduler->ops->option_set;
+       sched_ctx->ops.option_get = scheduler->ops->option_get;
 
        if (sched_ctx->private_ctx)
                rte_free(sched_ctx->private_ctx);
 
        if (sched_ctx->private_ctx)
                rte_free(sched_ctx->private_ctx);
@@ -528,3 +530,64 @@ rte_cryptodev_scheduler_slaves_get(uint8_t scheduler_id, uint8_t *slaves)
 
        return (int)nb_slaves;
 }
 
        return (int)nb_slaves;
 }
+
+int
+rte_cryptodev_scheduler_option_set(uint8_t scheduler_id,
+               enum rte_cryptodev_schedule_option_type option_type,
+               void *option)
+{
+       struct rte_cryptodev *dev = rte_cryptodev_pmd_get_dev(scheduler_id);
+       struct scheduler_ctx *sched_ctx;
+
+       if (option_type == CDEV_SCHED_OPTION_NOT_SET ||
+                       option_type >= CDEV_SCHED_OPTION_COUNT) {
+               CS_LOG_ERR("Invalid option parameter");
+               return -EINVAL;
+       }
+
+       if (!option) {
+               CS_LOG_ERR("Invalid option parameter");
+               return -EINVAL;
+       }
+
+       if (dev->data->dev_started) {
+               CS_LOG_ERR("Illegal operation");
+               return -EBUSY;
+       }
+
+       sched_ctx = dev->data->dev_private;
+
+       RTE_FUNC_PTR_OR_ERR_RET(*sched_ctx->ops.option_set, -ENOTSUP);
+
+       return (*sched_ctx->ops.option_set)(dev, option_type, option);
+}
+
+int
+rte_cryptodev_scheduler_option_get(uint8_t scheduler_id,
+               enum rte_cryptodev_schedule_option_type option_type,
+               void *option)
+{
+       struct rte_cryptodev *dev = rte_cryptodev_pmd_get_dev(scheduler_id);
+       struct scheduler_ctx *sched_ctx;
+
+       if (!dev) {
+               CS_LOG_ERR("Operation not supported");
+               return -ENOTSUP;
+       }
+
+       if (!option) {
+               CS_LOG_ERR("Invalid option parameter");
+               return -EINVAL;
+       }
+
+       if (dev->dev_type != RTE_CRYPTODEV_SCHEDULER_PMD) {
+               CS_LOG_ERR("Operation not supported");
+               return -ENOTSUP;
+       }
+
+       sched_ctx = dev->data->dev_private;
+
+       RTE_FUNC_PTR_OR_ERR_RET(*sched_ctx->ops.option_get, -ENOTSUP);
+
+       return (*sched_ctx->ops.option_get)(dev, option_type, option);
+}
index 3b816d3..4d3de47 100644 (file)
@@ -70,6 +70,23 @@ enum rte_cryptodev_scheduler_mode {
 #define RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN   (64)
 #define RTE_CRYPTODEV_SCHEDULER_DESC_MAX_LEN   (256)
 
 #define RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN   (64)
 #define RTE_CRYPTODEV_SCHEDULER_DESC_MAX_LEN   (256)
 
+/**
+ * Crypto scheduler option types
+ */
+enum rte_cryptodev_schedule_option_type {
+       CDEV_SCHED_OPTION_NOT_SET = 0,
+       CDEV_SCHED_OPTION_THRESHOLD,
+
+       CDEV_SCHED_OPTION_COUNT
+};
+
+/**
+ * Threshold option structure
+ */
+struct rte_cryptodev_scheduler_threshold_option {
+       uint32_t threshold;
+};
+
 struct rte_cryptodev_scheduler;
 
 /**
 struct rte_cryptodev_scheduler;
 
 /**
@@ -205,6 +222,44 @@ rte_cryptodev_scheduler_ordering_get(uint8_t scheduler_id);
 int
 rte_cryptodev_scheduler_slaves_get(uint8_t scheduler_id, uint8_t *slaves);
 
 int
 rte_cryptodev_scheduler_slaves_get(uint8_t scheduler_id, uint8_t *slaves);
 
+/**
+ * Set the mode specific option
+ *
+ * @param dev_id
+ *   The target scheduler device ID
+ * @param option_type
+ *   The option type enumerate
+ * @param option
+ *   The specific mode's option structure
+ *
+ * @return
+ *   - 0 if successful
+ *   - negative integer if otherwise.
+ */
+int
+rte_cryptodev_scheduler_option_set(uint8_t scheduler_id,
+               enum rte_cryptodev_schedule_option_type option_type,
+               void *option);
+
+/**
+ * Set the mode specific option
+ *
+ * @param dev_id
+ *   The target scheduler device ID
+ * @param option_type
+ *   The option type enumerate
+ * @param option
+ *   If successful, the function will write back the current
+ *
+ * @return
+ *   - 0 if successful
+ *   - negative integer if otherwise.
+ */
+int
+rte_cryptodev_scheduler_option_get(uint8_t scheduler_id,
+               enum rte_cryptodev_schedule_option_type option_type,
+               void *option);
+
 typedef uint16_t (*rte_cryptodev_scheduler_burst_enqueue_t)(void *qp_ctx,
                struct rte_crypto_op **ops, uint16_t nb_ops);
 
 typedef uint16_t (*rte_cryptodev_scheduler_burst_enqueue_t)(void *qp_ctx,
                struct rte_crypto_op **ops, uint16_t nb_ops);
 
index 93cf123..42fe9e6 100644 (file)
@@ -53,6 +53,16 @@ typedef int (*rte_cryptodev_scheduler_config_queue_pair)(
 typedef int (*rte_cryptodev_scheduler_create_private_ctx)(
                struct rte_cryptodev *dev);
 
 typedef int (*rte_cryptodev_scheduler_create_private_ctx)(
                struct rte_cryptodev *dev);
 
+typedef int (*rte_cryptodev_scheduler_config_option_set)(
+               struct rte_cryptodev *dev,
+               uint32_t option_type,
+               void *option);
+
+typedef int (*rte_cryptodev_scheduler_config_option_get)(
+               struct rte_cryptodev *dev,
+               uint32_t option_type,
+               void *option);
+
 struct rte_cryptodev_scheduler_ops {
        rte_cryptodev_scheduler_slave_attach_t slave_attach;
        rte_cryptodev_scheduler_slave_attach_t slave_detach;
 struct rte_cryptodev_scheduler_ops {
        rte_cryptodev_scheduler_slave_attach_t slave_attach;
        rte_cryptodev_scheduler_slave_attach_t slave_detach;
@@ -63,6 +73,9 @@ struct rte_cryptodev_scheduler_ops {
        rte_cryptodev_scheduler_config_queue_pair config_queue_pair;
 
        rte_cryptodev_scheduler_create_private_ctx create_private_ctx;
        rte_cryptodev_scheduler_config_queue_pair config_queue_pair;
 
        rte_cryptodev_scheduler_create_private_ctx create_private_ctx;
+
+       rte_cryptodev_scheduler_config_option_set option_set;
+       rte_cryptodev_scheduler_config_option_get option_get;
 };
 
 #ifdef __cplusplus
 };
 
 #ifdef __cplusplus
index de2a554..0a8b471 100644 (file)
@@ -16,6 +16,8 @@ DPDK_17.05 {
 
        rte_cryptodev_scheduler_mode_get;
        rte_cryptodev_scheduler_mode_set;
 
        rte_cryptodev_scheduler_mode_get;
        rte_cryptodev_scheduler_mode_set;
+       rte_cryptodev_scheduler_option_get;
+       rte_cryptodev_scheduler_option_set;
        rte_cryptodev_scheduler_slaves_get;
 
 } DPDK_17.02;
        rte_cryptodev_scheduler_slaves_get;
 
 } DPDK_17.02;
index 6359f04..2471a5f 100644 (file)
@@ -271,6 +271,8 @@ struct rte_cryptodev_scheduler_ops scheduler_fo_ops = {
        scheduler_stop,
        scheduler_config_qp,
        scheduler_create_private_ctx,
        scheduler_stop,
        scheduler_config_qp,
        scheduler_create_private_ctx,
+       NULL,   /* option_set */
+       NULL    /*option_get */
 };
 
 struct rte_cryptodev_scheduler fo_scheduler = {
 };
 
 struct rte_cryptodev_scheduler fo_scheduler = {
index 1066451..94196d9 100644 (file)
@@ -399,6 +399,51 @@ scheduler_create_private_ctx(struct rte_cryptodev *dev)
 
        return 0;
 }
 
        return 0;
 }
+static int
+scheduler_option_set(struct rte_cryptodev *dev, uint32_t option_type,
+               void *option)
+{
+       struct psd_scheduler_ctx *psd_ctx = ((struct scheduler_ctx *)
+                       dev->data->dev_private)->private_ctx;
+       uint32_t threshold;
+
+       if ((enum rte_cryptodev_schedule_option_type)option_type !=
+                       CDEV_SCHED_OPTION_THRESHOLD) {
+               CS_LOG_ERR("Option not supported");
+               return -EINVAL;
+       }
+
+       threshold = ((struct rte_cryptodev_scheduler_threshold_option *)
+                       option)->threshold;
+       if (!rte_is_power_of_2(threshold)) {
+               CS_LOG_ERR("Threshold is not power of 2");
+               return -EINVAL;
+       }
+
+       psd_ctx->threshold = ~(threshold - 1);
+
+       return 0;
+}
+
+static int
+scheduler_option_get(struct rte_cryptodev *dev, uint32_t option_type,
+               void *option)
+{
+       struct psd_scheduler_ctx *psd_ctx = ((struct scheduler_ctx *)
+                       dev->data->dev_private)->private_ctx;
+       struct rte_cryptodev_scheduler_threshold_option *threshold_option;
+
+       if ((enum rte_cryptodev_schedule_option_type)option_type !=
+                       CDEV_SCHED_OPTION_THRESHOLD) {
+               CS_LOG_ERR("Option not supported");
+               return -EINVAL;
+       }
+
+       threshold_option = option;
+       threshold_option->threshold = (~psd_ctx->threshold) + 1;
+
+       return 0;
+}
 
 struct rte_cryptodev_scheduler_ops scheduler_ps_ops = {
        slave_attach,
 
 struct rte_cryptodev_scheduler_ops scheduler_ps_ops = {
        slave_attach,
@@ -407,6 +452,8 @@ struct rte_cryptodev_scheduler_ops scheduler_ps_ops = {
        scheduler_stop,
        scheduler_config_qp,
        scheduler_create_private_ctx,
        scheduler_stop,
        scheduler_config_qp,
        scheduler_create_private_ctx,
+       scheduler_option_set,
+       scheduler_option_get
 };
 
 struct rte_cryptodev_scheduler psd_scheduler = {
 };
 
 struct rte_cryptodev_scheduler psd_scheduler = {
index 1fb6ce7..0116276 100644 (file)
@@ -265,7 +265,9 @@ struct rte_cryptodev_scheduler_ops scheduler_rr_ops = {
        scheduler_start,
        scheduler_stop,
        scheduler_config_qp,
        scheduler_start,
        scheduler_stop,
        scheduler_config_qp,
-       scheduler_create_private_ctx
+       scheduler_create_private_ctx,
+       NULL,   /* option_set */
+       NULL    /* option_get */
 };
 
 struct rte_cryptodev_scheduler scheduler = {
 };
 
 struct rte_cryptodev_scheduler scheduler = {