app/compress-perf: add incompressible data handling
authorTomasz Jozwiak <tomaszx.jozwiak@intel.com>
Fri, 1 Mar 2019 08:45:10 +0000 (09:45 +0100)
committerAkhil Goyal <akhil.goyal@nxp.com>
Tue, 2 Apr 2019 14:50:24 +0000 (16:50 +0200)
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 <tomaszx.jozwiak@intel.com>
Acked-by: Fiona Trahe <fiona.trahe@intel.com>
app/test-compress-perf/comp_perf_options.h
app/test-compress-perf/comp_perf_options_parse.c
app/test-compress-perf/comp_perf_test_benchmark.c
app/test-compress-perf/comp_perf_test_verify.c
app/test-compress-perf/main.c

index ca96a3c..f87751d 100644 (file)
@@ -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;
index d2b208d..2fb6fb4 100644 (file)
@@ -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;
        }
 
index 9aa2665..5752906 100644 (file)
@@ -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;
index 57a9930..28a0fe8 100644 (file)
@@ -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;
index 4de913e..c2a45d1 100644 (file)
@@ -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");