From: Tomasz Jozwiak Date: Fri, 1 Mar 2019 08:45:10 +0000 (+0100) Subject: app/compress-perf: add incompressible data handling X-Git-Url: http://git.droids-corp.org/?p=dpdk.git;a=commitdiff_plain;h=27cee41700946e98baf32a474bf819152c4dc54c app/compress-perf: add incompressible data handling Currently, compress-perf doesn't respect incompressible data inside one operation. This patch adds such a functionality. Now the output buffer in one operation is big enough to store such a data after compression. Also added segment size checking to pass values in right range. Signed-off-by: Tomasz Jozwiak Acked-by: Fiona Trahe --- diff --git a/app/test-compress-perf/comp_perf_options.h b/app/test-compress-perf/comp_perf_options.h index ca96a3cafb..f87751d878 100644 --- a/app/test-compress-perf/comp_perf_options.h +++ b/app/test-compress-perf/comp_perf_options.h @@ -8,6 +8,10 @@ #define MAX_DRIVER_NAME 64 #define MAX_INPUT_FILE_NAME 64 #define MAX_LIST 32 +#define MIN_COMPRESSED_BUF_SIZE 8 +#define EXPANSE_RATIO 1.05 +#define MAX_MBUF_DATA_SIZE (UINT16_MAX - RTE_PKTMBUF_HEADROOM) +#define MAX_SEG_SIZE ((int)(MAX_MBUF_DATA_SIZE / EXPANSE_RATIO)) enum comp_operation { COMPRESS_ONLY, @@ -38,6 +42,7 @@ struct comp_test_data { struct rte_mempool *op_pool; int8_t cdev_id; uint16_t seg_sz; + uint16_t out_seg_sz; uint16_t burst_sz; uint32_t pool_sz; uint32_t num_iter; diff --git a/app/test-compress-perf/comp_perf_options_parse.c b/app/test-compress-perf/comp_perf_options_parse.c index d2b208de35..2fb6fb48a5 100644 --- a/app/test-compress-perf/comp_perf_options_parse.c +++ b/app/test-compress-perf/comp_perf_options_parse.c @@ -326,8 +326,15 @@ parse_seg_sz(struct comp_test_data *test_data, const char *arg) return -1; } - if (test_data->seg_sz == 0) { - RTE_LOG(ERR, USER1, "Segment size must be higher than 0\n"); + if (test_data->seg_sz < MIN_COMPRESSED_BUF_SIZE) { + RTE_LOG(ERR, USER1, "Segment size must be higher than %d\n", + MIN_COMPRESSED_BUF_SIZE - 1); + return -1; + } + + if (test_data->seg_sz > MAX_SEG_SIZE) { + RTE_LOG(ERR, USER1, "Segment size must be lower than %d\n", + MAX_SEG_SIZE + 1); return -1; } diff --git a/app/test-compress-perf/comp_perf_test_benchmark.c b/app/test-compress-perf/comp_perf_test_benchmark.c index 9aa2665ff2..5752906b3b 100644 --- a/app/test-compress-perf/comp_perf_test_benchmark.c +++ b/app/test-compress-perf/comp_perf_test_benchmark.c @@ -22,6 +22,7 @@ main_loop(struct comp_test_data *test_data, uint8_t level, struct rte_mbuf **input_bufs, **output_bufs; int res = 0; int allocated = 0; + uint32_t out_seg_sz; if (test_data == NULL || !test_data->burst_sz) { RTE_LOG(ERR, USER1, @@ -55,6 +56,7 @@ main_loop(struct comp_test_data *test_data, uint8_t level, }; input_bufs = test_data->decomp_bufs; output_bufs = test_data->comp_bufs; + out_seg_sz = test_data->out_seg_sz; } else { xform = (struct rte_comp_xform) { .type = RTE_COMP_DECOMPRESS, @@ -67,6 +69,7 @@ main_loop(struct comp_test_data *test_data, uint8_t level, }; input_bufs = test_data->comp_bufs; output_bufs = test_data->decomp_bufs; + out_seg_sz = test_data->seg_sz; } /* Create private xform */ @@ -130,7 +133,7 @@ main_loop(struct comp_test_data *test_data, uint8_t level, /* Reset all data in output buffers */ struct rte_mbuf *m = output_bufs[buf_id]; - m->pkt_len = test_data->seg_sz * m->nb_segs; + m->pkt_len = out_seg_sz * m->nb_segs; while (m) { m->data_len = m->buf_len - m->data_off; m = m->next; @@ -187,7 +190,7 @@ main_loop(struct comp_test_data *test_data, uint8_t level, while (remaining_data > 0) { data_to_append = RTE_MIN(remaining_data, - test_data->seg_sz); + out_seg_sz); m->data_len = data_to_append; remaining_data -= data_to_append; @@ -236,7 +239,7 @@ main_loop(struct comp_test_data *test_data, uint8_t level, while (remaining_data > 0) { data_to_append = RTE_MIN(remaining_data, - test_data->seg_sz); + out_seg_sz); m->data_len = data_to_append; remaining_data -= data_to_append; diff --git a/app/test-compress-perf/comp_perf_test_verify.c b/app/test-compress-perf/comp_perf_test_verify.c index 57a9930c2c..28a0fe8731 100644 --- a/app/test-compress-perf/comp_perf_test_verify.c +++ b/app/test-compress-perf/comp_perf_test_verify.c @@ -24,6 +24,7 @@ main_loop(struct comp_test_data *test_data, uint8_t level, struct rte_mbuf **input_bufs, **output_bufs; int res = 0; int allocated = 0; + uint32_t out_seg_sz; if (test_data == NULL || !test_data->burst_sz) { RTE_LOG(ERR, USER1, @@ -57,6 +58,7 @@ main_loop(struct comp_test_data *test_data, uint8_t level, }; input_bufs = test_data->decomp_bufs; output_bufs = test_data->comp_bufs; + out_seg_sz = test_data->out_seg_sz; } else { xform = (struct rte_comp_xform) { .type = RTE_COMP_DECOMPRESS, @@ -69,6 +71,7 @@ main_loop(struct comp_test_data *test_data, uint8_t level, }; input_bufs = test_data->comp_bufs; output_bufs = test_data->decomp_bufs; + out_seg_sz = test_data->seg_sz; } /* Create private xform */ @@ -130,7 +133,7 @@ main_loop(struct comp_test_data *test_data, uint8_t level, /* Reset all data in output buffers */ struct rte_mbuf *m = output_bufs[buf_id]; - m->pkt_len = test_data->seg_sz * m->nb_segs; + m->pkt_len = out_seg_sz * m->nb_segs; while (m) { m->data_len = m->buf_len - m->data_off; m = m->next; @@ -209,7 +212,7 @@ main_loop(struct comp_test_data *test_data, uint8_t level, while (remaining_data > 0) { data_to_append = RTE_MIN(remaining_data, - test_data->seg_sz); + out_seg_sz); m->data_len = data_to_append; remaining_data -= data_to_append; @@ -280,7 +283,7 @@ main_loop(struct comp_test_data *test_data, uint8_t level, while (remaining_data > 0) { data_to_append = RTE_MIN(remaining_data, - test_data->seg_sz); + out_seg_sz); m->data_len = data_to_append; remaining_data -= data_to_append; diff --git a/app/test-compress-perf/main.c b/app/test-compress-perf/main.c index 4de913e401..c2a45d1301 100644 --- a/app/test-compress-perf/main.c +++ b/app/test-compress-perf/main.c @@ -13,8 +13,6 @@ #define NUM_MAX_XFORMS 16 #define NUM_MAX_INFLIGHT_OPS 512 -#define EXPANSE_RATIO 1.05 -#define MIN_COMPRESSED_BUF_SIZE 8 #define DIV_CEIL(a, b) ((a) / (b) + ((a) % (b) != 0)) @@ -117,9 +115,34 @@ comp_perf_check_capabilities(struct comp_test_data *test_data) return 0; } +static uint32_t +find_buf_size(uint32_t input_size) +{ + uint32_t i; + + /* From performance point of view the buffer size should be a + * power of 2 but also should be enough to store incompressible data + */ + + /* We're looking for nearest power of 2 buffer size, which is greather + * than input_size + */ + uint32_t size = + !input_size ? MIN_COMPRESSED_BUF_SIZE : (input_size << 1); + + for (i = UINT16_MAX + 1; !(i & size); i >>= 1) + ; + + return i > ((UINT16_MAX + 1) >> 1) + ? (uint32_t)((float)input_size * EXPANSE_RATIO) + : i; +} + static int comp_perf_allocate_memory(struct comp_test_data *test_data) { + + test_data->out_seg_sz = find_buf_size(test_data->seg_sz); /* Number of segments for input and output * (compression and decompression) */ @@ -127,7 +150,8 @@ comp_perf_allocate_memory(struct comp_test_data *test_data) test_data->seg_sz); test_data->comp_buf_pool = rte_pktmbuf_pool_create("comp_buf_pool", total_segs, - 0, 0, test_data->seg_sz + RTE_PKTMBUF_HEADROOM, + 0, 0, + test_data->out_seg_sz + RTE_PKTMBUF_HEADROOM, rte_socket_id()); if (test_data->comp_buf_pool == NULL) { RTE_LOG(ERR, USER1, "Mbuf mempool could not be created\n"); @@ -396,7 +420,7 @@ prepare_bufs(struct comp_test_data *test_data) } data_addr = (uint8_t *) rte_pktmbuf_append( test_data->comp_bufs[i], - test_data->seg_sz); + test_data->out_seg_sz); if (data_addr == NULL) { RTE_LOG(ERR, USER1, "Could not append data\n"); return -1; @@ -414,7 +438,7 @@ prepare_bufs(struct comp_test_data *test_data) } data_addr = (uint8_t *)rte_pktmbuf_append(next_seg, - test_data->seg_sz); + test_data->out_seg_sz); if (data_addr == NULL) { RTE_LOG(ERR, USER1, "Could not append data\n");