1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
5 #include <rte_malloc.h>
8 #include <rte_cycles.h>
9 #include <rte_compressdev.h>
11 #include "comp_perf_test_benchmark.h"
14 main_loop(struct comp_test_data *test_data, uint8_t level,
15 enum rte_comp_xform_type type)
17 uint8_t dev_id = test_data->cdev_id;
18 uint32_t i, iter, num_iter;
19 struct rte_comp_op **ops, **deq_ops;
20 void *priv_xform = NULL;
21 struct rte_comp_xform xform;
22 struct rte_mbuf **input_bufs, **output_bufs;
26 if (test_data == NULL || !test_data->burst_sz) {
28 "Unknown burst size\n");
32 ops = rte_zmalloc_socket(NULL,
33 2 * test_data->total_bufs * sizeof(struct rte_comp_op *),
38 "Can't allocate memory for ops strucures\n");
42 deq_ops = &ops[test_data->total_bufs];
44 if (type == RTE_COMP_COMPRESS) {
45 xform = (struct rte_comp_xform) {
46 .type = RTE_COMP_COMPRESS,
48 .algo = RTE_COMP_ALGO_DEFLATE,
49 .deflate.huffman = test_data->huffman_enc,
51 .window_size = test_data->window_sz,
52 .chksum = RTE_COMP_CHECKSUM_NONE,
53 .hash_algo = RTE_COMP_HASH_ALGO_NONE
56 input_bufs = test_data->decomp_bufs;
57 output_bufs = test_data->comp_bufs;
59 xform = (struct rte_comp_xform) {
60 .type = RTE_COMP_DECOMPRESS,
62 .algo = RTE_COMP_ALGO_DEFLATE,
63 .chksum = RTE_COMP_CHECKSUM_NONE,
64 .window_size = test_data->window_sz,
65 .hash_algo = RTE_COMP_HASH_ALGO_NONE
68 input_bufs = test_data->comp_bufs;
69 output_bufs = test_data->decomp_bufs;
72 /* Create private xform */
73 if (rte_compressdev_private_xform_create(dev_id, &xform,
75 RTE_LOG(ERR, USER1, "Private xform could not be created\n");
80 uint64_t tsc_start, tsc_end, tsc_duration;
82 tsc_start = tsc_end = tsc_duration = 0;
83 tsc_start = rte_rdtsc();
84 num_iter = test_data->num_iter;
86 for (iter = 0; iter < num_iter; iter++) {
87 uint32_t total_ops = test_data->total_bufs;
88 uint32_t remaining_ops = test_data->total_bufs;
89 uint32_t total_deq_ops = 0;
90 uint32_t total_enq_ops = 0;
91 uint16_t ops_unused = 0;
95 while (remaining_ops > 0) {
96 uint16_t num_ops = RTE_MIN(remaining_ops,
98 uint16_t ops_needed = num_ops - ops_unused;
101 * Move the unused operations from the previous
102 * enqueue_burst call to the front, to maintain order
104 if ((ops_unused > 0) && (num_enq > 0)) {
106 ops_unused * sizeof(struct rte_comp_op *);
108 memmove(ops, &ops[num_enq], nb_b_to_mov);
111 /* Allocate compression operations */
112 if (ops_needed && !rte_comp_op_bulk_alloc(
117 "Could not allocate enough operations\n");
121 allocated += ops_needed;
123 for (i = 0; i < ops_needed; i++) {
125 * Calculate next buffer to attach to operation
127 uint32_t buf_id = total_enq_ops + i +
129 uint16_t op_id = ops_unused + i;
130 /* Reset all data in output buffers */
131 struct rte_mbuf *m = output_bufs[buf_id];
133 m->pkt_len = test_data->seg_sz * m->nb_segs;
135 m->data_len = m->buf_len - m->data_off;
138 ops[op_id]->m_src = input_bufs[buf_id];
139 ops[op_id]->m_dst = output_bufs[buf_id];
140 ops[op_id]->src.offset = 0;
141 ops[op_id]->src.length =
142 rte_pktmbuf_pkt_len(input_bufs[buf_id]);
143 ops[op_id]->dst.offset = 0;
144 ops[op_id]->flush_flag = RTE_COMP_FLUSH_FINAL;
145 ops[op_id]->input_chksum = buf_id;
146 ops[op_id]->private_xform = priv_xform;
149 num_enq = rte_compressdev_enqueue_burst(dev_id, 0, ops,
152 struct rte_compressdev_stats stats;
154 rte_compressdev_stats_get(dev_id, &stats);
155 if (stats.enqueue_err_count) {
161 ops_unused = num_ops - num_enq;
162 remaining_ops -= num_enq;
163 total_enq_ops += num_enq;
165 num_deq = rte_compressdev_dequeue_burst(dev_id, 0,
167 test_data->burst_sz);
168 total_deq_ops += num_deq;
170 if (iter == num_iter - 1) {
171 for (i = 0; i < num_deq; i++) {
172 struct rte_comp_op *op = deq_ops[i];
175 RTE_COMP_OP_STATUS_SUCCESS) {
177 "Some operations were not successful\n");
181 struct rte_mbuf *m = op->m_dst;
183 m->pkt_len = op->produced;
184 uint32_t remaining_data = op->produced;
185 uint16_t data_to_append;
187 while (remaining_data > 0) {
189 RTE_MIN(remaining_data,
191 m->data_len = data_to_append;
198 rte_mempool_put_bulk(test_data->op_pool,
199 (void **)deq_ops, num_deq);
200 allocated -= num_deq;
203 /* Dequeue the last operations */
204 while (total_deq_ops < total_ops) {
205 num_deq = rte_compressdev_dequeue_burst(dev_id, 0,
206 deq_ops, test_data->burst_sz);
208 struct rte_compressdev_stats stats;
210 rte_compressdev_stats_get(dev_id, &stats);
211 if (stats.dequeue_err_count) {
217 total_deq_ops += num_deq;
219 if (iter == num_iter - 1) {
220 for (i = 0; i < num_deq; i++) {
221 struct rte_comp_op *op = deq_ops[i];
224 RTE_COMP_OP_STATUS_SUCCESS) {
226 "Some operations were not successful\n");
230 struct rte_mbuf *m = op->m_dst;
232 m->pkt_len = op->produced;
233 uint32_t remaining_data = op->produced;
234 uint16_t data_to_append;
236 while (remaining_data > 0) {
238 RTE_MIN(remaining_data,
240 m->data_len = data_to_append;
247 rte_mempool_put_bulk(test_data->op_pool,
248 (void **)deq_ops, num_deq);
249 allocated -= num_deq;
253 tsc_end = rte_rdtsc();
254 tsc_duration = tsc_end - tsc_start;
256 if (type == RTE_COMP_COMPRESS)
257 test_data->comp_tsc_duration[level] =
258 tsc_duration / num_iter;
260 test_data->decomp_tsc_duration[level] =
261 tsc_duration / num_iter;
264 rte_mempool_put_bulk(test_data->op_pool, (void **)ops, allocated);
265 rte_compressdev_private_xform_free(dev_id, priv_xform);
271 cperf_benchmark(struct comp_test_data *test_data, uint8_t level)
273 int i, ret = EXIT_SUCCESS;
276 * Run the tests twice, discarding the first performance
277 * results, before the cache is warmed up
279 for (i = 0; i < 2; i++) {
280 if (main_loop(test_data, level, RTE_COMP_COMPRESS) < 0) {
286 for (i = 0; i < 2; i++) {
287 if (main_loop(test_data, level, RTE_COMP_DECOMPRESS) < 0) {
293 test_data->comp_tsc_byte =
294 (double)(test_data->comp_tsc_duration[level]) /
295 test_data->input_data_sz;
297 test_data->decomp_tsc_byte =
298 (double)(test_data->decomp_tsc_duration[level]) /
299 test_data->input_data_sz;
301 test_data->comp_gbps = rte_get_tsc_hz() / test_data->comp_tsc_byte * 8 /
304 test_data->decomp_gbps = rte_get_tsc_hz() / test_data->decomp_tsc_byte