381 lines
12 KiB
Diff
381 lines
12 KiB
Diff
From 5523680f38335fb8abedd1b6a09d9df9a1078697 Mon Sep 17 00:00:00 2001
|
|
From: Weili Qian <qianweili@huawei.com>
|
|
Date: Mon, 31 Jul 2023 14:50:48 +0800
|
|
Subject: [PATCH 18/26] uadk: add the msg pool depth configuration
|
|
|
|
Add the message pool depth configuration. Users can use
|
|
the 'ctx_msg_num' in 'struct wd_cap_config' to input the
|
|
depth of message pool. If the input value ranges from 1 to 1024,
|
|
the input value is used to initialize async message pool. Otherwise,
|
|
the default value is used to initialize async message pool.
|
|
|
|
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
|
---
|
|
include/wd_alg_common.h | 17 +++++++++++++++++
|
|
include/wd_util.h | 9 ++++++---
|
|
wd_aead.c | 5 ++---
|
|
wd_cipher.c | 3 +--
|
|
wd_comp.c | 6 ++----
|
|
wd_dh.c | 3 +--
|
|
wd_digest.c | 3 +--
|
|
wd_ecc.c | 6 +-----
|
|
wd_rsa.c | 6 +-----
|
|
wd_util.c | 31 ++++++++++++++++++++++++++++---
|
|
wd_zlibwrapper.c | 2 +-
|
|
11 files changed, 61 insertions(+), 30 deletions(-)
|
|
|
|
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h
|
|
index 8a86656..77845a4 100644
|
|
--- a/include/wd_alg_common.h
|
|
+++ b/include/wd_alg_common.h
|
|
@@ -55,6 +55,19 @@ struct wd_ctx {
|
|
__u8 ctx_mode;
|
|
};
|
|
|
|
+/**
|
|
+ * struct wd_cap_config - Capabilities.
|
|
+ * @ctx_msg_num: number of asynchronous msg pools that the user wants to allocate.
|
|
+ * Optional, user can set ctx_msg_num based on the number of requests
|
|
+ * and system memory, 1~1024 is valid. If the value is not set or invalid,
|
|
+ * the default value 1024 is used to initialize msg pools.
|
|
+ * @resv: Reserved data.
|
|
+ */
|
|
+struct wd_cap_config {
|
|
+ __u32 ctx_msg_num;
|
|
+ __u32 resv;
|
|
+};
|
|
+
|
|
/**
|
|
* struct wd_ctx_config - Define a ctx set and its related attributes, which
|
|
* will be used in the scope of current process.
|
|
@@ -62,11 +75,13 @@ struct wd_ctx {
|
|
* @ctxs: Point to a ctx array, length is above ctx_num.
|
|
* @priv: The attributes of ctx defined by user, which is used by user
|
|
* defined scheduler.
|
|
+ * @cap: Capabilities input by user. Support set NULL, use default value initialize.
|
|
*/
|
|
struct wd_ctx_config {
|
|
__u32 ctx_num;
|
|
struct wd_ctx *ctxs;
|
|
void *priv;
|
|
+ struct wd_cap_config *cap;
|
|
};
|
|
|
|
/**
|
|
@@ -89,11 +104,13 @@ struct wd_ctx_nums {
|
|
* @ctx_set_num: Each operation type ctx sets numbers.
|
|
* @bmp: Ctxs distribution. Means users want to run business process on these
|
|
* numa or request ctx from devices located in these numa.
|
|
+ * @cap: Capabilities input by user. Support set NULL, use default value initialize.
|
|
*/
|
|
struct wd_ctx_params {
|
|
__u32 op_type_num;
|
|
struct wd_ctx_nums *ctx_set_num;
|
|
struct bitmask *bmp;
|
|
+ struct wd_cap_config *cap;
|
|
};
|
|
|
|
struct wd_ctx_internal {
|
|
diff --git a/include/wd_util.h b/include/wd_util.h
|
|
index 144ba59..cb07657 100644
|
|
--- a/include/wd_util.h
|
|
+++ b/include/wd_util.h
|
|
@@ -19,6 +19,8 @@
|
|
extern "C" {
|
|
#endif
|
|
|
|
+#define WD_POOL_MAX_ENTRIES 1024
|
|
+
|
|
#define FOREACH_NUMA(i, config, config_numa) \
|
|
for ((i) = 0, (config_numa) = (config)->config_per_numa; \
|
|
(i) < (config)->numa_num; (config_numa)++, (i)++)
|
|
@@ -167,9 +169,9 @@ void wd_clear_ctx_config(struct wd_ctx_config_internal *in);
|
|
void wd_memset_zero(void *data, __u32 size);
|
|
|
|
/*
|
|
- * wd_init_async_request_pool() - Init message pools.
|
|
+ * wd_init_async_request_pool() - Init async message pools.
|
|
* @pool: Pointer of message pool.
|
|
- * @pool_num: Message pool number.
|
|
+ * @config: ctx configuration input by user.
|
|
* @msg_num: Message entry number in one pool.
|
|
* @msg_size: Size of each message entry.
|
|
*
|
|
@@ -186,7 +188,8 @@ void wd_memset_zero(void *data, __u32 size);
|
|
* +-------+-------+----+-------+ -+-
|
|
* |<------- msg_num ---------->|
|
|
*/
|
|
-int wd_init_async_request_pool(struct wd_async_msg_pool *pool, __u32 pool_num,
|
|
+int wd_init_async_request_pool(struct wd_async_msg_pool *pool,
|
|
+ struct wd_ctx_config *config,
|
|
__u32 msg_num, __u32 msg_size);
|
|
|
|
/*
|
|
diff --git a/wd_aead.c b/wd_aead.c
|
|
index 7c3f160..cd0812e 100644
|
|
--- a/wd_aead.c
|
|
+++ b/wd_aead.c
|
|
@@ -21,7 +21,6 @@
|
|
|
|
#define WD_AEAD_CCM_GCM_MIN 4U
|
|
#define WD_AEAD_CCM_GCM_MAX 16
|
|
-#define WD_POOL_MAX_ENTRIES 1024
|
|
|
|
static int g_aead_mac_len[WD_DIGEST_TYPE_MAX] = {
|
|
WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN,
|
|
@@ -429,8 +428,8 @@ static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
|
|
|
|
/* init async request pool */
|
|
ret = wd_init_async_request_pool(&wd_aead_setting.pool,
|
|
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
|
- sizeof(struct wd_aead_msg));
|
|
+ config, WD_POOL_MAX_ENTRIES,
|
|
+ sizeof(struct wd_aead_msg));
|
|
if (ret < 0)
|
|
goto out_clear_sched;
|
|
|
|
diff --git a/wd_cipher.c b/wd_cipher.c
|
|
index adb6496..8acadcd 100644
|
|
--- a/wd_cipher.c
|
|
+++ b/wd_cipher.c
|
|
@@ -20,7 +20,6 @@
|
|
#define AES_KEYSIZE_192 24
|
|
#define AES_KEYSIZE_256 32
|
|
|
|
-#define WD_POOL_MAX_ENTRIES 1024
|
|
#define DES_WEAK_KEY_NUM 16
|
|
|
|
static const unsigned char des_weak_keys[DES_WEAK_KEY_NUM][DES_KEY_SIZE] = {
|
|
@@ -311,7 +310,7 @@ static int wd_cipher_common_init(struct wd_ctx_config *config,
|
|
|
|
/* allocate async pool for every ctx */
|
|
ret = wd_init_async_request_pool(&wd_cipher_setting.pool,
|
|
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
|
+ config, WD_POOL_MAX_ENTRIES,
|
|
sizeof(struct wd_cipher_msg));
|
|
if (ret < 0)
|
|
goto out_clear_sched;
|
|
diff --git a/wd_comp.c b/wd_comp.c
|
|
index 93c3031..a23dee1 100644
|
|
--- a/wd_comp.c
|
|
+++ b/wd_comp.c
|
|
@@ -15,7 +15,6 @@
|
|
#include "drv/wd_comp_drv.h"
|
|
#include "wd_comp.h"
|
|
|
|
-#define WD_POOL_MAX_ENTRIES 1024
|
|
#define HW_CTX_SIZE (64 * 1024)
|
|
#define STREAM_CHUNK (128 * 1024)
|
|
|
|
@@ -130,9 +129,8 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
|
|
if (ret < 0)
|
|
goto out_clear_ctx_config;
|
|
|
|
- /* fix me: sadly find we allocate async pool for every ctx */
|
|
ret = wd_init_async_request_pool(&wd_comp_setting.pool,
|
|
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
|
+ config, WD_POOL_MAX_ENTRIES,
|
|
sizeof(struct wd_comp_msg));
|
|
if (ret < 0)
|
|
goto out_clear_sched;
|
|
@@ -222,7 +220,7 @@ void wd_comp_uninit(void)
|
|
int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params)
|
|
{
|
|
struct wd_ctx_nums comp_ctx_num[WD_DIR_MAX] = {0};
|
|
- struct wd_ctx_params comp_ctx_params;
|
|
+ struct wd_ctx_params comp_ctx_params = {0};
|
|
int ret = -WD_EINVAL;
|
|
bool flag;
|
|
|
|
diff --git a/wd_dh.c b/wd_dh.c
|
|
index 50a1532..97df515 100644
|
|
--- a/wd_dh.c
|
|
+++ b/wd_dh.c
|
|
@@ -15,7 +15,6 @@
|
|
#include "include/drv/wd_dh_drv.h"
|
|
#include "wd_util.h"
|
|
|
|
-#define WD_POOL_MAX_ENTRIES 1024
|
|
#define DH_MAX_KEY_SIZE 512
|
|
#define WD_DH_G2 2
|
|
|
|
@@ -105,7 +104,7 @@ static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sche
|
|
|
|
/* initialize async request pool */
|
|
ret = wd_init_async_request_pool(&wd_dh_setting.pool,
|
|
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
|
+ config, WD_POOL_MAX_ENTRIES,
|
|
sizeof(struct wd_dh_msg));
|
|
if (ret)
|
|
goto out_clear_sched;
|
|
diff --git a/wd_digest.c b/wd_digest.c
|
|
index c5dbeca..9dc4bb3 100644
|
|
--- a/wd_digest.c
|
|
+++ b/wd_digest.c
|
|
@@ -19,7 +19,6 @@
|
|
#define AES_KEYSIZE_192 24
|
|
#define AES_KEYSIZE_256 32
|
|
|
|
-#define WD_POOL_MAX_ENTRIES 1024
|
|
#define DES_WEAK_KEY_NUM 4
|
|
|
|
static __u32 g_digest_mac_len[WD_DIGEST_TYPE_MAX] = {
|
|
@@ -243,7 +242,7 @@ static int wd_digest_init_nolock(struct wd_ctx_config *config,
|
|
|
|
/* allocate async pool for every ctx */
|
|
ret = wd_init_async_request_pool(&wd_digest_setting.pool,
|
|
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
|
+ config, WD_POOL_MAX_ENTRIES,
|
|
sizeof(struct wd_digest_msg));
|
|
if (ret < 0)
|
|
goto out_clear_sched;
|
|
diff --git a/wd_ecc.c b/wd_ecc.c
|
|
index 9f83fea..938e516 100644
|
|
--- a/wd_ecc.c
|
|
+++ b/wd_ecc.c
|
|
@@ -17,9 +17,6 @@
|
|
#include "include/wd_ecc_curve.h"
|
|
#include "wd_ecc.h"
|
|
|
|
-#define WD_POOL_MAX_ENTRIES 1024
|
|
-#define WD_ECC_CTX_MSG_NUM 64
|
|
-#define WD_ECC_MAX_CTX 256
|
|
#define ECC_MAX_HW_BITS 521
|
|
#define ECC_MAX_KEY_SIZE BITS_TO_BYTES(ECC_MAX_HW_BITS)
|
|
#define ECC_MAX_IN_NUM 4
|
|
@@ -169,9 +166,8 @@ static int wd_ecc_common_init(struct wd_ctx_config *config, struct wd_sched *sch
|
|
if (ret < 0)
|
|
goto out_clear_ctx_config;
|
|
|
|
- /* fix me: sadly find we allocate async pool for every ctx */
|
|
ret = wd_init_async_request_pool(&wd_ecc_setting.pool,
|
|
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
|
+ config, WD_POOL_MAX_ENTRIES,
|
|
sizeof(struct wd_ecc_msg));
|
|
if (ret < 0)
|
|
goto out_clear_sched;
|
|
diff --git a/wd_rsa.c b/wd_rsa.c
|
|
index 19a590f..2993637 100644
|
|
--- a/wd_rsa.c
|
|
+++ b/wd_rsa.c
|
|
@@ -15,9 +15,6 @@
|
|
#include "include/drv/wd_rsa_drv.h"
|
|
#include "wd_rsa.h"
|
|
|
|
-#define WD_POOL_MAX_ENTRIES 1024
|
|
-#define WD_HW_EACCESS 62
|
|
-
|
|
#define RSA_MAX_KEY_SIZE 512
|
|
|
|
static __thread __u64 balance;
|
|
@@ -144,9 +141,8 @@ static int wd_rsa_common_init(struct wd_ctx_config *config, struct wd_sched *sch
|
|
if (ret < 0)
|
|
goto out_clear_ctx_config;
|
|
|
|
- /* fix me: sadly find we allocate async pool for every ctx */
|
|
ret = wd_init_async_request_pool(&wd_rsa_setting.pool,
|
|
- config->ctx_num, WD_POOL_MAX_ENTRIES,
|
|
+ config, WD_POOL_MAX_ENTRIES,
|
|
sizeof(struct wd_rsa_msg));
|
|
if (ret < 0)
|
|
goto out_clear_sched;
|
|
diff --git a/wd_util.c b/wd_util.c
|
|
index ef67f1f..937ee2a 100644
|
|
--- a/wd_util.c
|
|
+++ b/wd_util.c
|
|
@@ -310,6 +310,20 @@ void wd_memset_zero(void *data, __u32 size)
|
|
*s++ = 0;
|
|
}
|
|
|
|
+static void get_ctx_msg_num(struct wd_cap_config *cap, __u32 *msg_num)
|
|
+{
|
|
+ if (!cap || !cap->ctx_msg_num)
|
|
+ return;
|
|
+
|
|
+ if (cap->ctx_msg_num > WD_POOL_MAX_ENTRIES) {
|
|
+ WD_INFO("ctx_msg_num %u is invalid, use default value: %u!\n",
|
|
+ cap->ctx_msg_num, *msg_num);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ *msg_num = cap->ctx_msg_num;
|
|
+}
|
|
+
|
|
static int init_msg_pool(struct msg_pool *pool, __u32 msg_num, __u32 msg_size)
|
|
{
|
|
pool->msgs = calloc(1, msg_num * msg_size);
|
|
@@ -335,6 +349,9 @@ static int init_msg_pool(struct msg_pool *pool, __u32 msg_num, __u32 msg_size)
|
|
|
|
static void uninit_msg_pool(struct msg_pool *pool)
|
|
{
|
|
+ if (!pool->msg_num)
|
|
+ return;
|
|
+
|
|
free(pool->msgs);
|
|
free(pool->used);
|
|
pool->msgs = NULL;
|
|
@@ -342,21 +359,27 @@ static void uninit_msg_pool(struct msg_pool *pool)
|
|
memset(pool, 0, sizeof(*pool));
|
|
}
|
|
|
|
-int wd_init_async_request_pool(struct wd_async_msg_pool *pool, __u32 pool_num,
|
|
+int wd_init_async_request_pool(struct wd_async_msg_pool *pool, struct wd_ctx_config *config,
|
|
__u32 msg_num, __u32 msg_size)
|
|
{
|
|
+ __u32 pool_num = config->ctx_num;
|
|
__u32 i, j;
|
|
int ret;
|
|
|
|
pool->pool_num = pool_num;
|
|
|
|
- pool->pools = calloc(1, pool->pool_num * sizeof(struct msg_pool));
|
|
+ pool->pools = calloc(1, pool_num * sizeof(struct msg_pool));
|
|
if (!pool->pools) {
|
|
WD_ERR("failed to alloc memory for async msg pools!\n");
|
|
return -WD_ENOMEM;
|
|
}
|
|
|
|
- for (i = 0; i < pool->pool_num; i++) {
|
|
+ /* If user set valid msg num, use user's. */
|
|
+ get_ctx_msg_num(config->cap, &msg_num);
|
|
+ for (i = 0; i < pool_num; i++) {
|
|
+ if (config->ctxs[i].ctx_mode == CTX_MODE_SYNC)
|
|
+ continue;
|
|
+
|
|
ret = init_msg_pool(&pool->pools[i], msg_num, msg_size);
|
|
if (ret < 0)
|
|
goto err;
|
|
@@ -2089,6 +2112,7 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params,
|
|
/* environment variable is not set, try to use user_ctx_params first */
|
|
if (user_ctx_params) {
|
|
copy_bitmask_to_bitmask(user_ctx_params->bmp, ctx_params->bmp);
|
|
+ ctx_params->cap = user_ctx_params->cap;
|
|
ctx_params->ctx_set_num = user_ctx_params->ctx_set_num;
|
|
ctx_params->op_type_num = user_ctx_params->op_type_num;
|
|
if (ctx_params->op_type_num > (__u32)max_op_type) {
|
|
@@ -2657,6 +2681,7 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs)
|
|
goto out_freesched;
|
|
}
|
|
|
|
+ ctx_config->cap = attrs->ctx_params->cap;
|
|
ret = alg_init_func(ctx_config, alg_sched);
|
|
if (ret)
|
|
goto out_pre_init;
|
|
diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c
|
|
index 29b51fb..4b785ce 100644
|
|
--- a/wd_zlibwrapper.c
|
|
+++ b/wd_zlibwrapper.c
|
|
@@ -40,8 +40,8 @@ static void wd_zlib_unlock(void)
|
|
|
|
static int wd_zlib_uadk_init(void)
|
|
{
|
|
+ struct wd_ctx_params cparams = {0};
|
|
struct wd_ctx_nums *ctx_set_num;
|
|
- struct wd_ctx_params cparams;
|
|
int ret, i;
|
|
|
|
if (zlib_config.status == WD_ZLIB_INIT)
|
|
--
|
|
2.25.1
|
|
|