From 457b51c88dc2141d99c208510bab7e9fd4566bf6 Mon Sep 17 00:00:00 2001 From: yuzh <1109426275@qq.com> Date: Thu, 9 Oct 2025 17:46:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=A4=9A=E7=A7=8D?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E9=80=89=E6=8B=A9=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KAEZlib/Makefile | 2 + KAEZlib/include/kaezip.h | 33 +++-- KAEZlib/include/kaezip_dev.h | 48 +++++++ KAEZlib/src/kaezip_async_adapter.c | 52 +++++++- KAEZlib/src/kaezip_async_adapter.h | 6 +- KAEZlib/src/v1/kaezip_async_comp.c | 121 +++++++++++++++++- KAEZlib/src/v1/kaezip_async_comp.h | 5 + KAEZlib/src/v1/kaezip_ctx.c | 6 +- KAEZlib/src/v1/kaezip_ctx.h | 3 +- KAEZlib/src/v1/kaezip_deflate.c | 2 +- KAEZlib/src/v1/kaezip_inflate.c | 2 +- KAEZlib/src/v1/kaezip_init.c | 9 +- KAEZlib/src/v1/kaezip_init.h | 2 +- KAEZlib/src/v1/wd_queue_memory.c | 26 +++- KAEZlib/src/v1/wd_queue_memory.h | 4 +- .../perftest/kzip/alg/kaezlib/deflateAsync.c | 8 +- 16 files changed, 285 insertions(+), 44 deletions(-) create mode 100644 KAEZlib/include/kaezip_dev.h diff --git a/KAEZlib/Makefile b/KAEZlib/Makefile index 9fdaad4..16ac5f7 100644 --- a/KAEZlib/Makefile +++ b/KAEZlib/Makefile @@ -106,10 +106,12 @@ install : $(LN) $(ENGINE_INSTALL_PATH)/lib/$(TARGET) $(ENGINE_INSTALL_PATH)/lib/$(SOFTLINK) $(LN) $(ENGINE_INSTALL_PATH)/lib/$(TARGET) $(ENGINE_INSTALL_PATH)/lib/$(SOFTLINK).0 install -m 755 $(WORK_PATH)/include/kaezip.h $(ENGINE_INSTALL_PATH)/include + install -m 755 $(WORK_PATH)/include/kaezip_dev.h $(ENGINE_INSTALL_PATH)/include uninstall : $(RM) $(ENGINE_INSTALL_PATH)/lib/$(SOFTLINK) $(RM) $(ENGINE_INSTALL_PATH)/lib/$(SOFTLINK).0 $(RM) $(ENGINE_INSTALL_PATH)/lib/$(TARGET) $(RM) $(ENGINE_INSTALL_PATH)/include/kaezip.h + $(RM) $(ENGINE_INSTALL_PATH)/include/kaezip_dev.h $(RM) /var/log/kaezip.log $(RM) /var/log/kaezip.log.old \ No newline at end of file diff --git a/KAEZlib/include/kaezip.h b/KAEZlib/include/kaezip.h index aae3f1a..3e9947c 100644 --- a/KAEZlib/include/kaezip.h +++ b/KAEZlib/include/kaezip.h @@ -25,6 +25,8 @@ #include #include #include "zlib.h" +#include "kaezip_dev.h" + #define Z_CALL_SOFT 10 #define VERSION_STRUCT_MAXLEN 100 @@ -103,8 +105,8 @@ extern void setDeflateKaezipCtx(z_streamp strm, unsigned long kaezip_ctx); /** * @brief: block compress async api * @param: sess : session - * @param: src [IN] : input data - * @param: dst [OUT] : output data, only support buf_num == 1 now. + * @param: src [IN] : input data, up to 255 SGES, each physically contiguous and ≤8 MB in size. + * @param: dst [OUT] : output data, up to 255 SGES, each physically contiguous and ≤8 MB in size. * @param: callback [IN] : async callback function,it can not be NULL, must be typedef void (*kaezip_async_callback)(struct kaezip_result *result); * @param: result [IN OUT] : async callback result,it can not be NULL. must be pointer of struct kaezip_result. * @return: 0 success, other fail @@ -121,9 +123,10 @@ int KAEZIP_compress_async_in_session(void *sess, const struct kaezip_buffer_list /** * @brief: Initialize Task Queues and Threads on the KAE Side. * @param: usr_map : function to translate src/dst buf's VA to PA/IOVA + * @param: config : pointer to device configuration structure used to select KAE device * @return: session, NULL if fail */ -void *KAEZIP_create_async_compress_session(iova_map_fn usr_map); +void *KAEZIP_create_async_compress_session(iova_map_fn usr_map, const device_config_t *config); /** * @brief: Destroy session and hardware ctx. @@ -134,9 +137,10 @@ void KAEZIP_destroy_async_compress_session(void *sess); /** * @brief: Initialize Task Queues and Threads on the KAE Side for decompress. * @param: usr_map : function to translate src/dst buf's VA to PA/IOVA + * @param: config : pointer to device configuration structure used to select KAE device * @return: session, NULL if fail */ -void *KAEZIP_create_async_decompress_session(iova_map_fn usr_map); +void *KAEZIP_create_async_decompress_session(iova_map_fn usr_map, const device_config_t *config); /** * @brief: Destroy decompress session and hardware ctx. @@ -147,8 +151,8 @@ void KAEZIP_destroy_async_decompress_session(void *sess); /** * @brief: block decompress async api * @param: sess : session - * @param: src [IN] : input data - * @param: dst [OUT] : output data, only support buf_num == 1 now. + * @param: src [IN] : input data, up to 255 SGES, each physically contiguous and ≤8 MB in size. + * @param: dst [OUT] : output data, up to 255 SGES, each physically contiguous and ≤8 MB in size. * @param: callback [IN] : async callback function,it can not be NULL, must be typedef void (*kaezip_async_callback)(struct kaezip_result *result); * @param: result [IN OUT] : async callback result,it can not be NULL. must be pointer of struct kaezip_result. * @return: 0 success, other fail @@ -163,11 +167,11 @@ void KAEZIP_reset_session(void *sess); /** * @brief: Initialize Task Queues and Threads on the KAE Side with zlib format. -* @param: usr_map : function to translate src/dst buf's VA to PA/IOVA -* @param: level : an integer from 0 to 9 or -1 controlling the level of compression -* @param: windowBits : an integer from 8 to 15 to control the size of sliding window -* @return: session, NULL if fail -*/ + * @param: usr_map : function to translate src/dst buf's VA to PA/IOVA + * @param: level : an integer from 0 to 9 or -1 controlling the level of compression + * @param: windowBits : an integer from 8 to 15 to control the size of sliding window + * @return: session, NULL if fail + */ void *KAEZIP_create_async_compress_session_zlib(iova_map_fn usr_map, int level, int windowBits); /** @@ -176,4 +180,11 @@ void *KAEZIP_create_async_compress_session_zlib(iova_map_fn usr_map, int level, * @return: session, NULL if fail */ void *KAEZIP_create_async_decompress_session_zlib(iova_map_fn usr_map); + +/** + * @brief: retrieve the list of available ZIP accelerator devices. + * @param: num [out] : pointer to store the number of devices. + * @return: pointer to an array of device descriptors. + */ +const struct zip_dev *KAEZIP_get_devices(unsigned int *num); #endif diff --git a/KAEZlib/include/kaezip_dev.h b/KAEZlib/include/kaezip_dev.h new file mode 100644 index 0000000..ace5b61 --- /dev/null +++ b/KAEZlib/include/kaezip_dev.h @@ -0,0 +1,48 @@ +/***************************************************************************** + * @file kaezip_dev.h + * + * This file defines the data structures and constants for KAE ZIP accelerator + * devices, including device descriptors, selection policies, and related macros. + * + *****************************************************************************/ + +#ifndef KAEZIP_DEV_H +#define KAEZIP_DEV_H + +#define MAX_STR_SIZE 512 +#define MAX_DEVICES 10 +#define UACCE_CLASS_PATH "/sys/class/uacce" +#define ZIP_PREFIX "hisi_zip-" + +typedef enum { + KAE_SELECT_AUTO = 0, // NUMA亲和性自动选择 + KAE_SELECT_BY_DEV = 1, // 通过设备指定 + KAE_SELECT_BY_NUMA = 2 // 通过 NUMA 节点指定 +} device_select_policy_t; + +struct zip_dev { + int numa_id; // 所属 NUMA 节点 + char dev_name[256]; // hisi_zip-* + char dev_root[MAX_STR_SIZE]; // /sys/class/uacce/hizi_zip-* + unsigned int hw_id; // 硬件 ID ( - 后面的数字,如 hisi_zip-8) + unsigned int dev_id; // 逻辑 ID ( 0,1,2...) +}; + +typedef struct { + device_select_policy_t policy; + union { + const struct zip_dev *dev; // policy == KAE_SELECT_BY_DEV 时有效 + unsigned int numa_node; // policy == KAE_SELECT_BY_NUMA 时有效 + } param; +} device_config_t; + +#define KAE_CONFIG_AUTO() \ + (device_config_t){ .policy = KAE_SELECT_AUTO } + +#define KAE_CONFIG_BY_DEV(dev_ptr) \ + (device_config_t){ .policy = KAE_SELECT_BY_DEV, .param.dev = (dev_ptr) } + +#define KAE_CONFIG_BY_NUMA(node) \ + (device_config_t){ .policy = KAE_SELECT_BY_NUMA, .param.numa_node = (node) } + +#endif \ No newline at end of file diff --git a/KAEZlib/src/kaezip_async_adapter.c b/KAEZlib/src/kaezip_async_adapter.c index 67f9ec4..c781691 100644 --- a/KAEZlib/src/kaezip_async_adapter.c +++ b/KAEZlib/src/kaezip_async_adapter.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "kaezlib_common.h" #include "kaezip_ctx.h" #include "kaezip.h" @@ -17,6 +18,10 @@ #include "kaezip_log.h" #include "uadk/wd.h" +static struct zip_dev g_devices[MAX_DEVICES]; +static unsigned int g_dev_count = 0; +static atomic_int g_initialized = 0; // 初始化标志 +static pthread_mutex_t g_init_mutex = PTHREAD_MUTEX_INITIALIZER; static void kaezip_dequeue_process(struct kaezip_async_ctrl *ctrl, kaezip_task_queue *task_queue, int budget, int comp_optype, int comp_algtype, compress_async_fn compress_fn) @@ -229,7 +234,7 @@ void KAEZIP_async_polling_in_session(void *sess, int budget) } } -void *KAEZIP_create_async_compress_session(iova_map_fn usr_map) +void *KAEZIP_create_async_compress_session(iova_map_fn usr_map, const device_config_t *config) { kaezip_session *sess = (kaezip_session *)kae_malloc(sizeof(kaezip_session)); int ret = 0; @@ -237,6 +242,11 @@ void *KAEZIP_create_async_compress_session(iova_map_fn usr_map) if (!sess) return NULL; + // check config + if (config != NULL && config->policy == KAE_SELECT_BY_DEV && config->param.dev == NULL) { + return NULL; + } + sess->usr_map = usr_map; sess->comp_optype = WCRYPTO_DEFLATE; sess->comp_algtype = WCRYPTO_RAW_DEFLATE; @@ -245,7 +255,7 @@ void *KAEZIP_create_async_compress_session(iova_map_fn usr_map) free(sess); return NULL; } - ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype, sess->comp_algtype); + ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype, sess->comp_algtype, config); if (ret != 0) { kaezip_task_queue_free(&sess->task_queue); free(sess); @@ -287,7 +297,7 @@ void KAEZIP_reset_session(void *sess) } } -void *KAEZIP_create_async_decompress_session(iova_map_fn usr_map) +void *KAEZIP_create_async_decompress_session(iova_map_fn usr_map, const device_config_t *config) { kaezip_session *sess = (kaezip_session *)kae_malloc(sizeof(kaezip_session)); int ret = 0; @@ -295,6 +305,11 @@ void *KAEZIP_create_async_decompress_session(iova_map_fn usr_map) if (!sess) return NULL; + // check config + if (config != NULL && config->policy == KAE_SELECT_BY_DEV && config->param.dev == NULL) { + return NULL; + } + sess->usr_map = usr_map; sess->comp_optype = WCRYPTO_INFLATE; sess->comp_algtype = WCRYPTO_RAW_DEFLATE; @@ -303,7 +318,7 @@ void *KAEZIP_create_async_decompress_session(iova_map_fn usr_map) free(sess); return NULL; } - ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype, sess->comp_algtype); + ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype, sess->comp_algtype, config); if (ret != 0) { kaezip_task_queue_free(&sess->task_queue); free(sess); @@ -344,7 +359,7 @@ void *KAEZIP_create_async_compress_session_zlib(iova_map_fn usr_map, int level, free(sess); return NULL; } - ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype, sess->comp_algtype); + ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype, sess->comp_algtype, NULL); // generate zlib header kaezip_set_zlib_header(sess->ctrl, level, windowBits); @@ -373,7 +388,7 @@ void *KAEZIP_create_async_decompress_session_zlib(iova_map_fn usr_map) free(sess); return NULL; } - ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype, sess->comp_algtype); + ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype, sess->comp_algtype, NULL); if (ret != 0) { kaezip_task_queue_free(&sess->task_queue); free(sess); @@ -381,4 +396,29 @@ void *KAEZIP_create_async_decompress_session_zlib(iova_map_fn usr_map) } return sess; +} + +const struct zip_dev *KAEZIP_get_devices(unsigned int *num) +{ + // initialized, return without lock + if (atomic_load_explicit(&g_initialized, memory_order_acquire)) { + if (num) { + *num = g_dev_count; + } + return g_dev_count > 0 ? g_devices : NULL; + } + + // not initialized + pthread_mutex_lock(&g_init_mutex); + if (!g_initialized) { + if (scan_hisi_zip_devices(g_devices, &g_dev_count) == 0) { + atomic_store_explicit(&g_initialized, 1, memory_order_release); + } + } + pthread_mutex_unlock(&g_init_mutex); + + if (num) { + *num = g_dev_count; + } + return g_dev_count > 0 ? g_devices : NULL; } \ No newline at end of file diff --git a/KAEZlib/src/kaezip_async_adapter.h b/KAEZlib/src/kaezip_async_adapter.h index 3db150f..80b2681 100644 --- a/KAEZlib/src/kaezip_async_adapter.h +++ b/KAEZlib/src/kaezip_async_adapter.h @@ -83,8 +83,12 @@ int kaezip_async_compress_polling(struct kaezip_async_ctrl *ctrl, int budget); int kaezip_async_is_thread_do_comp_full(struct kaezip_async_ctrl *ctrl); -int kaezip_async_instances_init(struct kaezip_async_ctrl **ctrl, iova_map_fn usr_map, int comp_optype, int comp_algtype); +int kaezip_async_instances_init(struct kaezip_async_ctrl **ctrl, iova_map_fn usr_map, int comp_optype, + int comp_algtype, const device_config_t *config); + void kaezip_async_instances_deinit(struct kaezip_async_ctrl *ctrl); void kaezip_hw_timeout_handle(struct kaezip_async_ctrl *ctrl, int comp_optype, int comp_algtype); void kaezip_set_zlib_header(struct kaezip_async_ctrl *ctrl, int level, int windowBits); + +int scan_hisi_zip_devices(struct zip_dev *g_devices, unsigned int *g_dev_count); #endif \ No newline at end of file diff --git a/KAEZlib/src/v1/kaezip_async_comp.c b/KAEZlib/src/v1/kaezip_async_comp.c index 6ed6833..5bcf6bd 100644 --- a/KAEZlib/src/v1/kaezip_async_comp.c +++ b/KAEZlib/src/v1/kaezip_async_comp.c @@ -466,7 +466,8 @@ void kaezip_ctx_clear(struct kaezip_async_ctrl *ctrl) } } -int kaezip_async_instances_init(struct kaezip_async_ctrl **ctrl, iova_map_fn usr_map, int comp_optype, int comp_algtype) +int kaezip_async_instances_init(struct kaezip_async_ctrl **ctrl, iova_map_fn usr_map, int comp_optype, + int comp_algtype, const device_config_t *config) { struct kaezip_async_ctrl *new_ctrl = (struct kaezip_async_ctrl *)kae_malloc(sizeof(struct kaezip_async_ctrl)); if (!new_ctrl) @@ -478,8 +479,9 @@ int kaezip_async_instances_init(struct kaezip_async_ctrl **ctrl, iova_map_fn usr new_ctrl->usr_map = usr_map; new_ctrl->is_polling = TRUE; + new_ctrl->config = config; for (int i = 0; i < MAX_NUM_IN_COMP; i++) { - new_ctrl->kz_ctx[i] = kaezip_init_v1(kaezip_get_win_size(), is_sgl, comp_optype, comp_algtype); + new_ctrl->kz_ctx[i] = kaezip_init_v1(kaezip_get_win_size(), is_sgl, comp_optype, comp_algtype, config); if (new_ctrl->kz_ctx[i] == NULL) { goto free_kz_ctx; } @@ -593,7 +595,7 @@ void kaezip_hw_timeout_handle(struct kaezip_async_ctrl *ctrl, int comp_optype, i if (ctrl->kz_ctx[i] != NULL) { continue; } - kaezip_ctx_t *kz_ctx = kaezip_init_v1(win_size, is_sgl, comp_optype, comp_algtype); + kaezip_ctx_t *kz_ctx = kaezip_init_v1(win_size, is_sgl, comp_optype, comp_algtype, ctrl->config); if (kz_ctx == NULL) { return; } @@ -611,7 +613,7 @@ static kaezip_ctx_t *kaezip_async_init_ctx(struct kaezip_async_ctrl *ctrl, int c if (unlikely(ctrl->kz_ctx[ctrl->ctx_index] == NULL)) { int is_sgl = (ctrl->usr_map != NULL) ? 1 : 0; - kz_ctx = kaezip_init_v1(kaezip_get_win_size(), is_sgl, comp_optype, comp_algtype); + kz_ctx = kaezip_init_v1(kaezip_get_win_size(), is_sgl, comp_optype, comp_algtype, ctrl->config); while (kz_ctx == NULL) { // 本质来说,这个初始化函数就初始化了其中的kaeConfig,其他是没有的,所以在外面要赋值 struct timespec timeout; if (enter_polling == 0) { @@ -625,7 +627,7 @@ static kaezip_ctx_t *kaezip_async_init_ctx(struct kaezip_async_ctrl *ctrl, int c } (void)kaezip_async_compress_polling(ctrl, 1); - kz_ctx = kaezip_init_v1(kaezip_get_win_size(), is_sgl, comp_optype, comp_algtype); + kz_ctx = kaezip_init_v1(kaezip_get_win_size(), is_sgl, comp_optype, comp_algtype, ctrl->config); } ctrl->kz_ctx[ctrl->ctx_index] = kz_ctx; ctrl->kz_ctx[ctrl->ctx_index]->usr_map = ctrl->usr_map; @@ -874,4 +876,113 @@ int kaezip_compress_async(struct kaezip_async_ctrl *ctrl, const struct kaezip_bu void kaezip_set_zlib_header(struct kaezip_async_ctrl *ctrl, int level, int windowBits) { ctrl->header = kaezip_get_fmt_header_zlib(level, windowBits); +} + +static int parse_hw_id(const char *name, unsigned int *hw_id) +{ + const char *p = name + strlen(ZIP_PREFIX); + char *endptr; + long val; + + if (*p == '\0') { + return -1; + } + + errno = 0; + val = strtol(p, &endptr, 10); + if (errno != 0 || *endptr != '\0' || val < 0 || val > UINT_MAX) { + return -1; + } + *hw_id = (unsigned int)val; + return 0; +} + +static int compare_devs(const void *a, const void *b) +{ + unsigned int id1 = ((const struct zip_dev *)a)->hw_id; + unsigned int id2 = ((const struct zip_dev *)b)->hw_id; + if (id1 < id2) return -1; + if (id1 > id2) return 1; + return 0; +} + +static int read_numa_node(const char *dev_path) +{ + char node_path[MAX_STR_SIZE + 16]; + FILE *fp; + int numa_id = -1; + + // 构建 node_id 文件路径 + snprintf(node_path, MAX_STR_SIZE + 16, "%s/node_id", dev_path); + + fp = fopen(node_path, "r"); + if (!fp) { + return -1; + } + + // 读取一个整数 + if (fscanf(fp, "%d", &numa_id) != 1) { + numa_id = -1; // 读取失败 + } + + fclose(fp); + return numa_id; +} + +int scan_hisi_zip_devices(struct zip_dev *g_devices, unsigned int *g_dev_count) +{ + DIR *dir = opendir(UACCE_CLASS_PATH); + if (!dir) { + fprintf(stderr, "[hisi_zip] Failed to open %s: %s\n", + UACCE_CLASS_PATH, strerror(errno)); + return -1; + } + + struct zip_dev temp_devs[MAX_DEVICES]; + unsigned int count = 0; + struct dirent *entry; + + while ((entry = readdir(dir)) != NULL) { + // 跳过 "." 和 ".." + if (entry->d_name[0] == '.' && + (entry->d_name[1] == '\0' || + (entry->d_name[1] == '.' && entry->d_name[2] == '\0'))) { + continue; + } + + // 检查是否以 "hisi_zip-" 开头 + if (strncmp(entry->d_name, ZIP_PREFIX, strlen(ZIP_PREFIX)) != 0) { + continue; + } + + // 解析数字 ID + unsigned int hw_id; + if (parse_hw_id(entry->d_name, &hw_id) != 0) { + continue; // 跳过非法名称 + } + temp_devs[count].hw_id = hw_id; + + // 保存设备名称及完整路径 + snprintf(temp_devs[count].dev_name, MAX_STR_SIZE, "%s", entry->d_name); + snprintf(temp_devs[count].dev_root, MAX_STR_SIZE, "%s/%s", UACCE_CLASS_PATH, entry->d_name); + + // 保存设备 numa_id + char dev_path[MAX_STR_SIZE]; + snprintf(dev_path, MAX_STR_SIZE, "%s/%s", UACCE_CLASS_PATH, entry->d_name); + temp_devs[count].numa_id = read_numa_node(dev_path); + + count++; + } + + closedir(dir); + + // 按 hw_id 升序排序 + qsort(temp_devs, count, sizeof(struct zip_dev), compare_devs); + // 写入全局缓存 + for (unsigned int i = 0; i < count; i++) { + g_devices[i] = temp_devs[i]; + g_devices[i].dev_id = i; // 分配逻辑 dev_id + } + *g_dev_count = count; + return 0; } \ No newline at end of file diff --git a/KAEZlib/src/v1/kaezip_async_comp.h b/KAEZlib/src/v1/kaezip_async_comp.h index 631fe34..ac7ac3b 100644 --- a/KAEZlib/src/v1/kaezip_async_comp.h +++ b/KAEZlib/src/v1/kaezip_async_comp.h @@ -14,7 +14,9 @@ #include #include #include +#include #include "uadk/v1/wd_sgl.h" +#include "kaezip_dev.h" #define KAE_ZLIB_REBUILD_FAIL -257 #define KAE_ZLIB_SW_RETURN_0_FAIL -256 @@ -95,6 +97,7 @@ struct kaezip_async_ctrl { iova_map_fn usr_map; int is_polling; const char *header; + const device_config_t *config; }; #define KZL_MEMCPY_16(dst, src, size) vst1q_u8((dst), vld1q_u8(src)) @@ -109,4 +112,6 @@ static inline void ZIP_wildCopy16(void* dstPtr, const void* srcPtr, void* dstEnd } int kaezip_async_is_thread_do_comp_full(struct kaezip_async_ctrl *ctrl); + +int scan_hisi_zip_devices(struct zip_dev *g_devices, unsigned int *g_dev_count); #endif diff --git a/KAEZlib/src/v1/kaezip_ctx.c b/KAEZlib/src/v1/kaezip_ctx.c index 23a91a1..6069e84 100644 --- a/KAEZlib/src/v1/kaezip_ctx.c +++ b/KAEZlib/src/v1/kaezip_ctx.c @@ -614,7 +614,7 @@ void kaezip_free_instance(void *arg) #define COMP_OPTYPE_NUM (2) __thread struct kaezip_instance *g_cur_instance[COMP_OPTYPE_NUM]; -kaezip_ctx_t* kaezip_get_ctx(int alg_comp_type, int comp_optype, int win_size, int is_sgl) +kaezip_ctx_t* kaezip_get_ctx(int alg_comp_type, int comp_optype, int win_size, int is_sgl, const device_config_t *config) { KAE_QUEUE_DATA_NODE_S *q_node = NULL; kaezip_ctx_t *kz_ctx = NULL; @@ -629,10 +629,10 @@ kaezip_ctx_t* kaezip_get_ctx(int alg_comp_type, int comp_optype, int win_size, i // check cur_instance if (cur_instance == NULL || cur_instance->q_node->comp_alg_type != alg_comp_type \ || cur_instance->q_node->win_size != win_size || cur_instance->q_node->is_sgl != is_sgl) { - q_node = kaezip_get_node_from_pool(qp, alg_comp_type, comp_optype, win_size, is_sgl); + q_node = kaezip_get_node_from_pool(qp, alg_comp_type, comp_optype, win_size, is_sgl, config); if (q_node == NULL) { kaezip_queue_pool_check_and_release(qp, kaezip_free_instance); - q_node = kaezip_get_node_from_pool(qp, alg_comp_type, comp_optype, win_size, is_sgl); + q_node = kaezip_get_node_from_pool(qp, alg_comp_type, comp_optype, win_size, is_sgl, config); if (q_node == NULL) { kae_free(cur_instance); diff --git a/KAEZlib/src/v1/kaezip_ctx.h b/KAEZlib/src/v1/kaezip_ctx.h index 1530edf..cb488e4 100644 --- a/KAEZlib/src/v1/kaezip_ctx.h +++ b/KAEZlib/src/v1/kaezip_ctx.h @@ -25,6 +25,7 @@ #include #include "wd_queue_memory.h" #include "uadk/v1/wd_comp.h" +#include "kaezip_dev.h" enum kaezip_comp_status { KAEZIP_COMP_INIT = 0, @@ -115,7 +116,7 @@ struct kaezip_instance { typedef struct kaezip_ctx kaezip_ctx_t; -kaezip_ctx_t* kaezip_get_ctx(int alg_comp_type, int comp_optype, int win_size, int is_sgl); +kaezip_ctx_t* kaezip_get_ctx(int alg_comp_type, int comp_optype, int win_size, int is_sgl, const device_config_t *config); void kaezip_put_ctx(kaezip_ctx_t* kz_ctx); void kaezip_init_ctx(kaezip_ctx_t* kz_ctx); void kaezip_free_ctx(kaezip_ctx_t* kz_ctx); diff --git a/KAEZlib/src/v1/kaezip_deflate.c b/KAEZlib/src/v1/kaezip_deflate.c index 6696934..dc543c6 100644 --- a/KAEZlib/src/v1/kaezip_deflate.c +++ b/KAEZlib/src/v1/kaezip_deflate.c @@ -70,7 +70,7 @@ int kz_deflateInit2_v1(z_streamp strm, int level, int win_size, alg; (void)kz_zlib_analy_alg(-15, &alg, &win_size, level); - kaezip_ctx_t* kaezip_ctx = kaezip_get_ctx(alg_comp_type, WCRYPTO_DEFLATE, win_size, 0); + kaezip_ctx_t* kaezip_ctx = kaezip_get_ctx(alg_comp_type, WCRYPTO_DEFLATE, win_size, 0, NULL); if (kaezip_ctx == NULL) { US_ERR("failed to get kaezip ctx, windowbits %d!", windowBits); setDeflateKaezipCtx(strm, 0); diff --git a/KAEZlib/src/v1/kaezip_inflate.c b/KAEZlib/src/v1/kaezip_inflate.c index 941f5ef..ba8153d 100644 --- a/KAEZlib/src/v1/kaezip_inflate.c +++ b/KAEZlib/src/v1/kaezip_inflate.c @@ -210,7 +210,7 @@ int kz_do_inflateInit(z_streamp strm, int alg_comp_type) int win_size, alg; (void)kz_zlib_analy_alg(-15, &alg, &win_size, -1); - kaezip_ctx_t* kaezip_ctx = kaezip_get_ctx(alg_comp_type, WCRYPTO_INFLATE, win_size, 0); + kaezip_ctx_t* kaezip_ctx = kaezip_get_ctx(alg_comp_type, WCRYPTO_INFLATE, win_size, 0, NULL); if (kaezip_ctx == NULL) { US_ERR("failed to get kaezip ctx, alg_comp_type %d!", alg_comp_type); setInflateKaezipCtx(strm, 0); diff --git a/KAEZlib/src/v1/kaezip_init.c b/KAEZlib/src/v1/kaezip_init.c index bc909b3..1492256 100644 --- a/KAEZlib/src/v1/kaezip_init.c +++ b/KAEZlib/src/v1/kaezip_init.c @@ -6,17 +6,18 @@ * @LastEditTime: 2025-07-09 */ -#include "kaezip.h" +// #include "kaezip.h" +#include "kaezip_dev.h" #include "kaezip_init.h" #include "kaezip_log.h" -void *kaezip_init_v1(int win_size, int is_sgl, int comp_type, int comp_algtype) +void *kaezip_init_v1(int win_size, int is_sgl, int comp_type, int comp_algtype, const device_config_t *config) { kaezip_ctx_t *kaezip_ctx = NULL; if (comp_type == WCRYPTO_DEFLATE && comp_algtype == WCRYPTO_RAW_DEFLATE) { - kaezip_ctx = kaezip_get_ctx(WCRYPTO_GZIP, comp_type, win_size, is_sgl); + kaezip_ctx = kaezip_get_ctx(WCRYPTO_GZIP, comp_type, win_size, is_sgl, config); } else { - kaezip_ctx = kaezip_get_ctx(comp_algtype, comp_type, win_size, is_sgl); + kaezip_ctx = kaezip_get_ctx(comp_algtype, comp_type, win_size, is_sgl, config); } if (!kaezip_ctx) { US_ERR("kaezlib failed to get kaezip ctx!"); diff --git a/KAEZlib/src/v1/kaezip_init.h b/KAEZlib/src/v1/kaezip_init.h index 57c110b..d381006 100644 --- a/KAEZlib/src/v1/kaezip_init.h +++ b/KAEZlib/src/v1/kaezip_init.h @@ -11,6 +11,6 @@ #include "kaezip_common.h" -void *kaezip_init_v1(int win_size, int is_sgl, int comp_type, int comp_algtype); +void *kaezip_init_v1(int win_size, int is_sgl, int comp_type, int comp_algtype, const device_config_t *config); #endif \ No newline at end of file diff --git a/KAEZlib/src/v1/wd_queue_memory.c b/KAEZlib/src/v1/wd_queue_memory.c index 240c631..88ad8c9 100644 --- a/KAEZlib/src/v1/wd_queue_memory.c +++ b/KAEZlib/src/v1/wd_queue_memory.c @@ -60,7 +60,7 @@ static int get_numa_mask(int mask) { return 1 << nid; } -struct wd_queue* kaezip_wd_new_queue(int comp_alg_type, int comp_optype, int is_sgl) +struct wd_queue* kaezip_wd_new_queue(int comp_alg_type, int comp_optype, int is_sgl, const device_config_t *config) { struct wd_queue* queue = (struct wd_queue *)kae_malloc(sizeof(struct wd_queue)); if (queue == NULL) { @@ -98,6 +98,20 @@ struct wd_queue* kaezip_wd_new_queue(int comp_alg_type, int comp_optype, int is_ struct wcrypto_paras *priv = (struct wcrypto_paras *)&(queue->capa.priv); priv->direction = comp_optype; + + /* request queue based on config */ + if (config != NULL && config->policy != KAE_SELECT_AUTO) { + switch (config->policy) { + case KAE_SELECT_BY_DEV: + snprintf(queue->dev_path, PATH_STR_SIZE, "%s", config->param.dev->dev_name); + break; + case KAE_SELECT_BY_NUMA: + queue->node_mask = 1 << config->param.numa_node; + break; + default: + break; + } + } int ret = wd_request_queue(queue); if (ret) { US_ERR("request wd queue fail!errno:%d", ret); @@ -288,7 +302,8 @@ void kaezip_free_wd_queue_memory(KAE_QUEUE_DATA_NODE_S *queue_node, kae_release_ US_DEBUG("free wd queue success"); } -static KAE_QUEUE_DATA_NODE_S* kaezip_new_wd_queue_memory(int comp_alg_type, int comp_type, int win_size, int is_sgl) +static KAE_QUEUE_DATA_NODE_S* kaezip_new_wd_queue_memory(int comp_alg_type, int comp_type, int win_size, int is_sgl, + const device_config_t *config) { KAE_QUEUE_DATA_NODE_S *queue_node = NULL; @@ -299,7 +314,7 @@ static KAE_QUEUE_DATA_NODE_S* kaezip_new_wd_queue_memory(int comp_alg_type, int } memset(queue_node, 0, sizeof(KAE_QUEUE_DATA_NODE_S)); - queue_node->kae_wd_queue = kaezip_wd_new_queue(comp_alg_type, comp_type, is_sgl); + queue_node->kae_wd_queue = kaezip_wd_new_queue(comp_alg_type, comp_type, is_sgl, config); if (queue_node->kae_wd_queue == NULL) { US_ERR("new wd queue fail"); goto err; @@ -325,7 +340,8 @@ err: return NULL; } -KAE_QUEUE_DATA_NODE_S* kaezip_get_node_from_pool(KAE_QUEUE_POOL_HEAD_S* pool_head, int comp_alg_type, int comp_type, int win_size, int is_sgl) +KAE_QUEUE_DATA_NODE_S* kaezip_get_node_from_pool(KAE_QUEUE_POOL_HEAD_S* pool_head, int comp_alg_type, int comp_type, + int win_size, int is_sgl, const device_config_t *config) { KAE_QUEUE_DATA_NODE_S *queue_data_node = NULL; @@ -336,7 +352,7 @@ KAE_QUEUE_DATA_NODE_S* kaezip_get_node_from_pool(KAE_QUEUE_POOL_HEAD_S* pool_hea queue_data_node = kaezip_get_queue_data_from_list(pool_head, comp_alg_type, win_size, is_sgl); if (queue_data_node == NULL) { - queue_data_node = kaezip_new_wd_queue_memory(comp_alg_type, comp_type, win_size, is_sgl); + queue_data_node = kaezip_new_wd_queue_memory(comp_alg_type, comp_type, win_size, is_sgl, config); } return queue_data_node; diff --git a/KAEZlib/src/v1/wd_queue_memory.h b/KAEZlib/src/v1/wd_queue_memory.h index d00bbbb..52219f5 100644 --- a/KAEZlib/src/v1/wd_queue_memory.h +++ b/KAEZlib/src/v1/wd_queue_memory.h @@ -26,6 +26,7 @@ #include #include "uadk/v1/wd.h" #include "kaezip_utils.h" +#include "kaezip_dev.h" #define KAE_QUEUE_POOL_MAX_SIZE (512) #define CHECK_QUEUE_TIME_SECONDS (60) // seconds @@ -69,7 +70,8 @@ void *kaezip_dma_map(void *usr, void *va, size_t sz); void kaezip_dma_unmap(void *usr, void *va, void *dma, size_t sz); KAE_QUEUE_POOL_HEAD_S* kaezip_init_queue_pool (int algtype); -KAE_QUEUE_DATA_NODE_S* kaezip_get_node_from_pool(KAE_QUEUE_POOL_HEAD_S* pool_head, int alg_comp_type, int comp_optype, int win_size, int is_sgl); +KAE_QUEUE_DATA_NODE_S* kaezip_get_node_from_pool(KAE_QUEUE_POOL_HEAD_S* pool_head, int alg_comp_type, int comp_optype, + int win_size, int is_sgl, const device_config_t *config); int kaezip_put_node_to_pool (KAE_QUEUE_POOL_HEAD_S* pool_head, KAE_QUEUE_DATA_NODE_S* node_data, kae_release_priv_ctx_cb release_fn); void kaezip_queue_pool_destroy(KAE_QUEUE_POOL_HEAD_S* pool_head, kae_release_priv_ctx_cb release_fn); void kaezip_queue_pool_check_and_release(KAE_QUEUE_POOL_HEAD_S* pool_head, kae_release_priv_ctx_cb release_ectx_fn); diff --git a/scripts/perftest/kzip/alg/kaezlib/deflateAsync.c b/scripts/perftest/kzip/alg/kaezlib/deflateAsync.c index 03733b5..60edaed 100644 --- a/scripts/perftest/kzip/alg/kaezlib/deflateAsync.c +++ b/scripts/perftest/kzip/alg/kaezlib/deflateAsync.c @@ -125,9 +125,9 @@ static int zlib_async_deflate_init(struct compress_ctx *ctx) { if(ctx->sess_count > 1) { for (int i = 0; i < ctx->sess_count; ++i) { if(ctx->compress_or_decompress == 1) { - ctx->sess_array[i].kae_sess = KAEZIP_create_async_compress_session(get_physical_address_wrapper); + ctx->sess_array[i].kae_sess = KAEZIP_create_async_compress_session(get_physical_address_wrapper, NULL); } else { - ctx->sess_array[i].kae_sess = KAEZIP_create_async_decompress_session(get_physical_address_wrapper); + ctx->sess_array[i].kae_sess = KAEZIP_create_async_decompress_session(get_physical_address_wrapper, NULL); } if (!ctx->sess_array[i].kae_sess) { fprintf(stderr, "Failed to create session %d\n", i); @@ -135,9 +135,9 @@ static int zlib_async_deflate_init(struct compress_ctx *ctx) { } } else { if(ctx->compress_or_decompress == 1) { - ctx->sess.kae_sess = KAEZIP_create_async_compress_session(get_physical_address_wrapper); + ctx->sess.kae_sess = KAEZIP_create_async_compress_session(get_physical_address_wrapper, NULL); } else { - ctx->sess.kae_sess = KAEZIP_create_async_decompress_session(get_physical_address_wrapper); + ctx->sess.kae_sess = KAEZIP_create_async_decompress_session(get_physical_address_wrapper, NULL); } } return 0; -- Gitee