Add a command line option `algo` to select the compress algorithm supported by the compress API: null (DMA), deflate, lz4 and lzs.
Default for deflate. Signed-off-by: Matan Azrad <ma...@nvidia.com> Signed-off-by: Michael Baum <michae...@nvidia.com> --- app/test-compress-perf/comp_perf_options.h | 3 + .../comp_perf_options_parse.c | 75 +++++++++++++++++++ .../comp_perf_test_cyclecount.c | 11 ++- .../comp_perf_test_throughput.c | 11 ++- .../comp_perf_test_verify.c | 11 ++- app/test-compress-perf/main.c | 55 ++++++++++---- doc/guides/tools/comp_perf.rst | 5 ++ 7 files changed, 148 insertions(+), 23 deletions(-) diff --git a/app/test-compress-perf/comp_perf_options.h b/app/test-compress-perf/comp_perf_options.h index d00b299247..828a7309d8 100644 --- a/app/test-compress-perf/comp_perf_options.h +++ b/app/test-compress-perf/comp_perf_options.h @@ -61,8 +61,11 @@ struct comp_test_data { uint16_t max_sgl_segs; uint32_t total_segs; + uint8_t lz4_flags; enum rte_comp_huffman huffman_enc; enum comp_operation test_op; + enum rte_comp_algorithm test_algo; + int window_sz; struct range_list level_lst; uint8_t level; diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c index 303e714cda..6d8c370fc2 100644 --- a/app/test-compress-perf/comp_perf_options_parse.c +++ b/app/test-compress-perf/comp_perf_options_parse.c @@ -25,7 +25,9 @@ #define CPERF_MAX_SGL_SEGS ("max-num-sgl-segs") #define CPERF_NUM_ITER ("num-iter") #define CPERF_OPTYPE ("operation") +#define CPERF_ALGO ("algo") #define CPERF_HUFFMAN_ENC ("huffman-enc") +#define CPERF_LZ4_FLAGS ("lz4-flags") #define CPERF_LEVEL ("compress-level") #define CPERF_WINDOW_SIZE ("window-sz") #define CPERF_EXTERNAL_MBUFS ("external-mbufs") @@ -56,8 +58,11 @@ usage(char *progname) " compressed/decompressed (default: 10000)\n" " --operation [comp/decomp/comp_and_decomp]: perform test on\n" " compression, decompression or both operations\n" + " --algo [null/deflate/lzs/lz4]: perform test on algorithm\n" + " null(DMA), deflate, lzs or lz4 (default: deflate)\n" " --huffman-enc [fixed/dynamic/default]: Huffman encoding\n" " (default: dynamic)\n" + " --lz4-flags N: flags to configure LZ4 algorithm (default: 0)\n" " --compress-level N: compression level, which could be a single value, list or range\n" " (default: range between 1 and 9)\n" " --window-sz N: base two log value of compression window size\n" @@ -150,6 +155,23 @@ parse_uint16_t(uint16_t *value, const char *arg) return 0; } +static int +parse_uint8_t(uint8_t *value, const char *arg) +{ + uint32_t val = 0; + int ret = parse_uint32_t(&val, arg); + + if (ret < 0) + return ret; + + if (val > UINT8_MAX) + return -ERANGE; + + *value = (uint8_t) val; + + return 0; +} + static int parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc) { @@ -470,6 +492,40 @@ parse_op_type(struct comp_test_data *test_data, const char *arg) return 0; } +static int +parse_algo(struct comp_test_data *test_data, const char *arg) +{ + struct name_id_map algo_namemap[] = { + { + "null", + RTE_COMP_ALGO_NULL + }, + { + "deflate", + RTE_COMP_ALGO_DEFLATE + }, + { + "lzs", + RTE_COMP_ALGO_LZS + }, + { + "lz4", + RTE_COMP_ALGO_LZ4 + } + }; + + int id = get_str_key_id_mapping(algo_namemap, + RTE_DIM(algo_namemap), arg); + if (id < 0) { + RTE_LOG(ERR, USER1, "Invalid algorithm specified\n"); + return -1; + } + + test_data->test_algo = (enum rte_comp_algorithm)id; + + return 0; +} + static int parse_huffman_enc(struct comp_test_data *test_data, const char *arg) { @@ -500,6 +556,19 @@ parse_huffman_enc(struct comp_test_data *test_data, const char *arg) return 0; } +static int +parse_lz4_flags(struct comp_test_data *test_data, const char *arg) +{ + int ret = parse_uint8_t(&test_data->lz4_flags, arg); + + if (ret) { + RTE_LOG(ERR, USER1, "Failed to parse LZ4 flags\n"); + return -1; + } + + return 0; +} + static int parse_level(struct comp_test_data *test_data, const char *arg) { @@ -572,7 +641,9 @@ static struct option lgopts[] = { { CPERF_MAX_SGL_SEGS, required_argument, 0, 0}, { CPERF_NUM_ITER, required_argument, 0, 0 }, { CPERF_OPTYPE, required_argument, 0, 0 }, + { CPERF_ALGO, required_argument, 0, 0 }, { CPERF_HUFFMAN_ENC, required_argument, 0, 0 }, + { CPERF_LZ4_FLAGS, required_argument, 0, 0 }, { CPERF_LEVEL, required_argument, 0, 0 }, { CPERF_WINDOW_SIZE, required_argument, 0, 0 }, { CPERF_EXTERNAL_MBUFS, 0, 0, 0 }, @@ -594,7 +665,9 @@ comp_perf_opts_parse_long(int opt_idx, struct comp_test_data *test_data) { CPERF_MAX_SGL_SEGS, parse_max_num_sgl_segs }, { CPERF_NUM_ITER, parse_num_iter }, { CPERF_OPTYPE, parse_op_type }, + { CPERF_ALGO, parse_algo }, { CPERF_HUFFMAN_ENC, parse_huffman_enc }, + { CPERF_LZ4_FLAGS, parse_lz4_flags }, { CPERF_LEVEL, parse_level }, { CPERF_WINDOW_SIZE, parse_window_sz }, { CPERF_EXTERNAL_MBUFS, parse_external_mbufs }, @@ -647,8 +720,10 @@ comp_perf_options_default(struct comp_test_data *test_data) test_data->pool_sz = 8192; test_data->max_sgl_segs = 16; test_data->num_iter = 10000; + test_data->lz4_flags = 0; test_data->huffman_enc = RTE_COMP_HUFFMAN_DYNAMIC; test_data->test_op = COMPRESS_DECOMPRESS; + test_data->test_algo = RTE_COMP_ALGO_DEFLATE; test_data->window_sz = -1; test_data->level_lst.min = RTE_COMP_LEVEL_MIN; test_data->level_lst.max = RTE_COMP_LEVEL_MAX; diff --git a/app/test-compress-perf/comp_perf_test_cyclecount.c b/app/test-compress-perf/comp_perf_test_cyclecount.c index ce6c4d7605..4d336ec8d6 100644 --- a/app/test-compress-perf/comp_perf_test_cyclecount.c +++ b/app/test-compress-perf/comp_perf_test_cyclecount.c @@ -193,14 +193,17 @@ main_loop(struct cperf_cyclecount_ctx *ctx, enum rte_comp_xform_type type) xform = (struct rte_comp_xform) { .type = RTE_COMP_COMPRESS, .compress = { - .algo = RTE_COMP_ALGO_DEFLATE, - .deflate.huffman = test_data->huffman_enc, + .algo = test_data->test_algo, .level = test_data->level, .window_size = test_data->window_sz, .chksum = RTE_COMP_CHECKSUM_NONE, .hash_algo = RTE_COMP_HASH_ALGO_NONE } }; + if (test_data->test_algo == RTE_COMP_ALGO_DEFLATE) + xform.compress.deflate.huffman = test_data->huffman_enc; + else if (test_data->test_algo == RTE_COMP_ALGO_LZ4) + xform.compress.lz4.flags = test_data->lz4_flags; input_bufs = mem->decomp_bufs; output_bufs = mem->comp_bufs; out_seg_sz = test_data->out_seg_sz; @@ -208,12 +211,14 @@ main_loop(struct cperf_cyclecount_ctx *ctx, enum rte_comp_xform_type type) xform = (struct rte_comp_xform) { .type = RTE_COMP_DECOMPRESS, .decompress = { - .algo = RTE_COMP_ALGO_DEFLATE, + .algo = test_data->test_algo, .chksum = RTE_COMP_CHECKSUM_NONE, .window_size = test_data->window_sz, .hash_algo = RTE_COMP_HASH_ALGO_NONE } }; + if (test_data->test_algo == RTE_COMP_ALGO_LZ4) + xform.decompress.lz4.flags = test_data->lz4_flags; input_bufs = mem->comp_bufs; output_bufs = mem->decomp_bufs; out_seg_sz = test_data->seg_sz; diff --git a/app/test-compress-perf/comp_perf_test_throughput.c b/app/test-compress-perf/comp_perf_test_throughput.c index c9f8237626..1f7072d223 100644 --- a/app/test-compress-perf/comp_perf_test_throughput.c +++ b/app/test-compress-perf/comp_perf_test_throughput.c @@ -84,14 +84,17 @@ main_loop(struct cperf_benchmark_ctx *ctx, enum rte_comp_xform_type type) xform = (struct rte_comp_xform) { .type = RTE_COMP_COMPRESS, .compress = { - .algo = RTE_COMP_ALGO_DEFLATE, - .deflate.huffman = test_data->huffman_enc, + .algo = test_data->test_algo, .level = test_data->level, .window_size = test_data->window_sz, .chksum = RTE_COMP_CHECKSUM_NONE, .hash_algo = RTE_COMP_HASH_ALGO_NONE } }; + if (test_data->test_algo == RTE_COMP_ALGO_DEFLATE) + xform.compress.deflate.huffman = test_data->huffman_enc; + else if (test_data->test_algo == RTE_COMP_ALGO_LZ4) + xform.compress.lz4.flags = test_data->lz4_flags; input_bufs = mem->decomp_bufs; output_bufs = mem->comp_bufs; out_seg_sz = test_data->out_seg_sz; @@ -99,12 +102,14 @@ main_loop(struct cperf_benchmark_ctx *ctx, enum rte_comp_xform_type type) xform = (struct rte_comp_xform) { .type = RTE_COMP_DECOMPRESS, .decompress = { - .algo = RTE_COMP_ALGO_DEFLATE, + .algo = test_data->test_algo, .chksum = RTE_COMP_CHECKSUM_NONE, .window_size = test_data->window_sz, .hash_algo = RTE_COMP_HASH_ALGO_NONE } }; + if (test_data->test_algo == RTE_COMP_ALGO_LZ4) + xform.decompress.lz4.flags = test_data->lz4_flags; input_bufs = mem->comp_bufs; output_bufs = mem->decomp_bufs; out_seg_sz = test_data->seg_sz; diff --git a/app/test-compress-perf/comp_perf_test_verify.c b/app/test-compress-perf/comp_perf_test_verify.c index 7d6b6abecd..7bd18073cf 100644 --- a/app/test-compress-perf/comp_perf_test_verify.c +++ b/app/test-compress-perf/comp_perf_test_verify.c @@ -87,14 +87,17 @@ main_loop(struct cperf_verify_ctx *ctx, enum rte_comp_xform_type type) xform = (struct rte_comp_xform) { .type = RTE_COMP_COMPRESS, .compress = { - .algo = RTE_COMP_ALGO_DEFLATE, - .deflate.huffman = test_data->huffman_enc, + .algo = test_data->test_algo, .level = test_data->level, .window_size = test_data->window_sz, .chksum = RTE_COMP_CHECKSUM_NONE, .hash_algo = RTE_COMP_HASH_ALGO_NONE } }; + if (test_data->test_algo == RTE_COMP_ALGO_DEFLATE) + xform.compress.deflate.huffman = test_data->huffman_enc; + else if (test_data->test_algo == RTE_COMP_ALGO_LZ4) + xform.compress.lz4.flags = test_data->lz4_flags; output_data_ptr = ctx->mem.compressed_data; output_data_sz = &ctx->comp_data_sz; input_bufs = mem->decomp_bufs; @@ -104,12 +107,14 @@ main_loop(struct cperf_verify_ctx *ctx, enum rte_comp_xform_type type) xform = (struct rte_comp_xform) { .type = RTE_COMP_DECOMPRESS, .decompress = { - .algo = RTE_COMP_ALGO_DEFLATE, + .algo = test_data->test_algo, .chksum = RTE_COMP_CHECKSUM_NONE, .window_size = test_data->window_sz, .hash_algo = RTE_COMP_HASH_ALGO_NONE } }; + if (test_data->test_algo == RTE_COMP_ALGO_LZ4) + xform.decompress.lz4.flags = test_data->lz4_flags; output_data_ptr = ctx->mem.decompressed_data; output_data_sz = &ctx->decomp_data_sz; input_bufs = mem->comp_bufs; diff --git a/app/test-compress-perf/main.c b/app/test-compress-perf/main.c index bbb4c7917b..fa366123ed 100644 --- a/app/test-compress-perf/main.c +++ b/app/test-compress-perf/main.c @@ -57,29 +57,56 @@ comp_perf_check_capabilities(struct comp_test_data *test_data, uint8_t cdev_id) { const struct rte_compressdev_capabilities *cap; - cap = rte_compressdev_capability_get(cdev_id, - RTE_COMP_ALGO_DEFLATE); + cap = rte_compressdev_capability_get(cdev_id, test_data->test_algo); if (cap == NULL) { RTE_LOG(ERR, USER1, - "Compress device does not support DEFLATE\n"); + "Compress device does not support %u algorithm\n", + test_data->test_algo); return -1; } uint64_t comp_flags = cap->comp_feature_flags; - /* Huffman encoding */ - if (test_data->huffman_enc == RTE_COMP_HUFFMAN_FIXED && - (comp_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0) { - RTE_LOG(ERR, USER1, - "Compress device does not supported Fixed Huffman\n"); - return -1; - } + /* Algorithm type */ + switch (test_data->test_algo) { + case RTE_COMP_ALGO_DEFLATE: + /* Huffman encoding */ + if (test_data->huffman_enc == RTE_COMP_HUFFMAN_FIXED && + (comp_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0) { + RTE_LOG(ERR, USER1, + "Compress device does not supported Fixed Huffman\n"); + return -1; + } - if (test_data->huffman_enc == RTE_COMP_HUFFMAN_DYNAMIC && - (comp_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0) { - RTE_LOG(ERR, USER1, - "Compress device does not supported Dynamic Huffman\n"); + if (test_data->huffman_enc == RTE_COMP_HUFFMAN_DYNAMIC && + (comp_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0) { + RTE_LOG(ERR, USER1, + "Compress device does not supported Dynamic Huffman\n"); + return -1; + } + break; + case RTE_COMP_ALGO_LZ4: + /* LZ4 flags */ + if ((test_data->lz4_flags & RTE_COMP_LZ4_FLAG_BLOCK_CHECKSUM) && + (comp_flags & RTE_COMP_FF_LZ4_BLOCK_WITH_CHECKSUM) == 0) { + RTE_LOG(ERR, USER1, + "Compress device does not support LZ4 block with checksum\n"); + return -1; + } + + if ((test_data->lz4_flags & + RTE_COMP_LZ4_FLAG_BLOCK_INDEPENDENCE) && + (comp_flags & RTE_COMP_FF_LZ4_BLOCK_INDEPENDENCE) == 0) { + RTE_LOG(ERR, USER1, + "Compress device does not support LZ4 independent blocks\n"); + return -1; + } + break; + case RTE_COMP_ALGO_LZS: + case RTE_COMP_ALGO_NULL: + break; + default: return -1; } diff --git a/doc/guides/tools/comp_perf.rst b/doc/guides/tools/comp_perf.rst index 9d2f4dbe4a..5eb05a095c 100644 --- a/doc/guides/tools/comp_perf.rst +++ b/doc/guides/tools/comp_perf.rst @@ -84,8 +84,13 @@ Application Options ``--operation [comp/decomp/comp_and_decomp]``: perform test on compression, decompression or both operations + ``--algo [null/deflate/lzs/lz4]`` : perform test on algorithm null(DMA), Deflate, lzs or lz4 (default: Deflate) + ``--huffman-enc [fixed/dynamic/default]``: Huffman encoding (default: dynamic) + ``--lz4-flags N``: flags to for LZ4 parameters, + see `LZ4 Frame Descriptor <https://github.com/lz4/lz4/blob/dev/doc/lz4_Frame_format.md#frame-descriptor>`_ (default: no flags) + ``--compress-level N``: compression level, which could be a single value, list or range (default: range between 1 and 9) ``--window-sz N``: base two log value of compression window size (default: max supported by PMD) -- 2.25.1