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 cperf_benchmark_test_destructor(void *arg)
17 comp_perf_free_memory(
18 &((struct cperf_benchmark_ctx *)arg)->ver.mem);
24 cperf_benchmark_test_constructor(uint8_t dev_id, uint16_t qp_id,
25 struct comp_test_data *options)
27 struct cperf_benchmark_ctx *ctx = NULL;
29 ctx = rte_malloc(NULL, sizeof(struct cperf_benchmark_ctx), 0);
34 ctx->ver.mem.dev_id = dev_id;
35 ctx->ver.mem.qp_id = qp_id;
36 ctx->ver.options = options;
37 ctx->ver.silent = 1; /* ver. part will be silent */
39 if (!comp_perf_allocate_memory(ctx->ver.options, &ctx->ver.mem)
40 && !prepare_bufs(ctx->ver.options, &ctx->ver.mem))
43 cperf_benchmark_test_destructor(ctx);
48 main_loop(struct cperf_benchmark_ctx *ctx, enum rte_comp_xform_type type)
50 struct comp_test_data *test_data = ctx->ver.options;
51 struct cperf_mem_resources *mem = &ctx->ver.mem;
52 uint8_t dev_id = mem->dev_id;
53 uint32_t i, iter, num_iter;
54 struct rte_comp_op **ops, **deq_ops;
55 void *priv_xform = NULL;
56 struct rte_comp_xform xform;
57 struct rte_mbuf **input_bufs, **output_bufs;
62 if (test_data == NULL || !test_data->burst_sz) {
64 "Unknown burst size\n");
68 ops = rte_zmalloc_socket(NULL,
69 2 * mem->total_bufs * sizeof(struct rte_comp_op *),
74 "Can't allocate memory for ops strucures\n");
78 deq_ops = &ops[mem->total_bufs];
80 if (type == RTE_COMP_COMPRESS) {
81 xform = (struct rte_comp_xform) {
82 .type = RTE_COMP_COMPRESS,
84 .algo = RTE_COMP_ALGO_DEFLATE,
85 .deflate.huffman = test_data->huffman_enc,
86 .level = test_data->level,
87 .window_size = test_data->window_sz,
88 .chksum = RTE_COMP_CHECKSUM_NONE,
89 .hash_algo = RTE_COMP_HASH_ALGO_NONE
92 input_bufs = mem->decomp_bufs;
93 output_bufs = mem->comp_bufs;
94 out_seg_sz = test_data->out_seg_sz;
96 xform = (struct rte_comp_xform) {
97 .type = RTE_COMP_DECOMPRESS,
99 .algo = RTE_COMP_ALGO_DEFLATE,
100 .chksum = RTE_COMP_CHECKSUM_NONE,
101 .window_size = test_data->window_sz,
102 .hash_algo = RTE_COMP_HASH_ALGO_NONE
105 input_bufs = mem->comp_bufs;
106 output_bufs = mem->decomp_bufs;
107 out_seg_sz = test_data->seg_sz;
110 /* Create private xform */
111 if (rte_compressdev_private_xform_create(dev_id, &xform,
113 RTE_LOG(ERR, USER1, "Private xform could not be created\n");
118 uint64_t tsc_start, tsc_end, tsc_duration;
120 num_iter = test_data->num_iter;
121 tsc_start = tsc_end = tsc_duration = 0;
122 tsc_start = rte_rdtsc_precise();
124 for (iter = 0; iter < num_iter; iter++) {
125 uint32_t total_ops = mem->total_bufs;
126 uint32_t remaining_ops = mem->total_bufs;
127 uint32_t total_deq_ops = 0;
128 uint32_t total_enq_ops = 0;
129 uint16_t ops_unused = 0;
130 uint16_t num_enq = 0;
131 uint16_t num_deq = 0;
133 while (remaining_ops > 0) {
134 uint16_t num_ops = RTE_MIN(remaining_ops,
135 test_data->burst_sz);
136 uint16_t ops_needed = num_ops - ops_unused;
139 * Move the unused operations from the previous
140 * enqueue_burst call to the front, to maintain order
142 if ((ops_unused > 0) && (num_enq > 0)) {
144 ops_unused * sizeof(struct rte_comp_op *);
146 memmove(ops, &ops[num_enq], nb_b_to_mov);
149 /* Allocate compression operations */
150 if (ops_needed && !rte_comp_op_bulk_alloc(
155 "Could not allocate enough operations\n");
159 allocated += ops_needed;
161 for (i = 0; i < ops_needed; i++) {
163 * Calculate next buffer to attach to operation
165 uint32_t buf_id = total_enq_ops + i +
167 uint16_t op_id = ops_unused + i;
168 /* Reset all data in output buffers */
169 struct rte_mbuf *m = output_bufs[buf_id];
171 m->pkt_len = out_seg_sz * m->nb_segs;
173 m->data_len = m->buf_len - m->data_off;
176 ops[op_id]->m_src = input_bufs[buf_id];
177 ops[op_id]->m_dst = output_bufs[buf_id];
178 ops[op_id]->src.offset = 0;
179 ops[op_id]->src.length =
180 rte_pktmbuf_pkt_len(input_bufs[buf_id]);
181 ops[op_id]->dst.offset = 0;
182 ops[op_id]->flush_flag = RTE_COMP_FLUSH_FINAL;
183 ops[op_id]->input_chksum = buf_id;
184 ops[op_id]->private_xform = priv_xform;
187 if (unlikely(test_data->perf_comp_force_stop))
190 num_enq = rte_compressdev_enqueue_burst(dev_id,
194 struct rte_compressdev_stats stats;
196 rte_compressdev_stats_get(dev_id, &stats);
197 if (stats.enqueue_err_count) {
203 ops_unused = num_ops - num_enq;
204 remaining_ops -= num_enq;
205 total_enq_ops += num_enq;
207 num_deq = rte_compressdev_dequeue_burst(dev_id,
210 test_data->burst_sz);
211 total_deq_ops += num_deq;
213 if (iter == num_iter - 1) {
214 for (i = 0; i < num_deq; i++) {
215 struct rte_comp_op *op = deq_ops[i];
218 RTE_COMP_OP_STATUS_SUCCESS) {
220 "Some operations were not successful\n");
224 struct rte_mbuf *m = op->m_dst;
226 m->pkt_len = op->produced;
227 uint32_t remaining_data = op->produced;
228 uint16_t data_to_append;
230 while (remaining_data > 0) {
232 RTE_MIN(remaining_data,
234 m->data_len = data_to_append;
241 rte_mempool_put_bulk(mem->op_pool,
242 (void **)deq_ops, num_deq);
243 allocated -= num_deq;
246 /* Dequeue the last operations */
247 while (total_deq_ops < total_ops) {
248 if (unlikely(test_data->perf_comp_force_stop))
251 num_deq = rte_compressdev_dequeue_burst(dev_id,
254 test_data->burst_sz);
256 struct rte_compressdev_stats stats;
258 rte_compressdev_stats_get(dev_id, &stats);
259 if (stats.dequeue_err_count) {
265 total_deq_ops += num_deq;
267 if (iter == num_iter - 1) {
268 for (i = 0; i < num_deq; i++) {
269 struct rte_comp_op *op = deq_ops[i];
272 RTE_COMP_OP_STATUS_SUCCESS) {
274 "Some operations were not successful\n");
278 struct rte_mbuf *m = op->m_dst;
280 m->pkt_len = op->produced;
281 uint32_t remaining_data = op->produced;
282 uint16_t data_to_append;
284 while (remaining_data > 0) {
286 RTE_MIN(remaining_data,
288 m->data_len = data_to_append;
295 rte_mempool_put_bulk(mem->op_pool,
296 (void **)deq_ops, num_deq);
297 allocated -= num_deq;
301 tsc_end = rte_rdtsc_precise();
302 tsc_duration = tsc_end - tsc_start;
304 if (type == RTE_COMP_COMPRESS)
305 ctx->comp_tsc_duration[test_data->level] =
306 tsc_duration / num_iter;
308 ctx->decomp_tsc_duration[test_data->level] =
309 tsc_duration / num_iter;
312 rte_mempool_put_bulk(mem->op_pool, (void **)ops, allocated);
313 rte_compressdev_private_xform_free(dev_id, priv_xform);
316 if (test_data->perf_comp_force_stop) {
318 "lcore: %d Perf. test has been aborted by user\n",
326 cperf_benchmark_test_runner(void *test_ctx)
328 struct cperf_benchmark_ctx *ctx = test_ctx;
329 struct comp_test_data *test_data = ctx->ver.options;
330 uint32_t lcore = rte_lcore_id();
331 static rte_atomic16_t display_once = RTE_ATOMIC16_INIT(0);
333 ctx->ver.mem.lcore_id = lcore;
334 int i, ret = EXIT_SUCCESS;
337 * First the verification part is needed
339 if (cperf_verify_test_runner(&ctx->ver)) {
345 * Run the tests twice, discarding the first performance
346 * results, before the cache is warmed up
348 for (i = 0; i < 2; i++) {
349 if (main_loop(ctx, RTE_COMP_COMPRESS) < 0) {
355 for (i = 0; i < 2; i++) {
356 if (main_loop(ctx, RTE_COMP_DECOMPRESS) < 0) {
363 (double)(ctx->comp_tsc_duration[test_data->level]) /
364 test_data->input_data_sz;
366 ctx->decomp_tsc_byte =
367 (double)(ctx->decomp_tsc_duration[test_data->level]) /
368 test_data->input_data_sz;
370 ctx->comp_gbps = rte_get_tsc_hz() / ctx->comp_tsc_byte * 8 /
373 ctx->decomp_gbps = rte_get_tsc_hz() / ctx->decomp_tsc_byte * 8 /
376 if (rte_atomic16_test_and_set(&display_once)) {
377 printf("%12s%6s%12s%17s%15s%16s\n",
378 "lcore id", "Level", "Comp size", "Comp ratio [%]",
379 "Comp [Gbps]", "Decomp [Gbps]");
382 printf("%12u%6u%12zu%17.2f%15.2f%16.2f\n",
383 ctx->ver.mem.lcore_id,
384 test_data->level, ctx->ver.comp_data_sz, ctx->ver.ratio,