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 num_enq = rte_compressdev_enqueue_burst(dev_id,
191 struct rte_compressdev_stats stats;
193 rte_compressdev_stats_get(dev_id, &stats);
194 if (stats.enqueue_err_count) {
200 ops_unused = num_ops - num_enq;
201 remaining_ops -= num_enq;
202 total_enq_ops += num_enq;
204 num_deq = rte_compressdev_dequeue_burst(dev_id,
207 test_data->burst_sz);
208 total_deq_ops += num_deq;
210 if (iter == num_iter - 1) {
211 for (i = 0; i < num_deq; i++) {
212 struct rte_comp_op *op = deq_ops[i];
215 RTE_COMP_OP_STATUS_SUCCESS) {
217 "Some operations were not successful\n");
221 struct rte_mbuf *m = op->m_dst;
223 m->pkt_len = op->produced;
224 uint32_t remaining_data = op->produced;
225 uint16_t data_to_append;
227 while (remaining_data > 0) {
229 RTE_MIN(remaining_data,
231 m->data_len = data_to_append;
238 rte_mempool_put_bulk(mem->op_pool,
239 (void **)deq_ops, num_deq);
240 allocated -= num_deq;
243 /* Dequeue the last operations */
244 while (total_deq_ops < total_ops) {
245 num_deq = rte_compressdev_dequeue_burst(dev_id,
248 test_data->burst_sz);
250 struct rte_compressdev_stats stats;
252 rte_compressdev_stats_get(dev_id, &stats);
253 if (stats.dequeue_err_count) {
259 total_deq_ops += num_deq;
261 if (iter == num_iter - 1) {
262 for (i = 0; i < num_deq; i++) {
263 struct rte_comp_op *op = deq_ops[i];
266 RTE_COMP_OP_STATUS_SUCCESS) {
268 "Some operations were not successful\n");
272 struct rte_mbuf *m = op->m_dst;
274 m->pkt_len = op->produced;
275 uint32_t remaining_data = op->produced;
276 uint16_t data_to_append;
278 while (remaining_data > 0) {
280 RTE_MIN(remaining_data,
282 m->data_len = data_to_append;
289 rte_mempool_put_bulk(mem->op_pool,
290 (void **)deq_ops, num_deq);
291 allocated -= num_deq;
295 tsc_end = rte_rdtsc_precise();
296 tsc_duration = tsc_end - tsc_start;
298 if (type == RTE_COMP_COMPRESS)
299 ctx->comp_tsc_duration[test_data->level] =
300 tsc_duration / num_iter;
302 ctx->decomp_tsc_duration[test_data->level] =
303 tsc_duration / num_iter;
306 rte_mempool_put_bulk(mem->op_pool, (void **)ops, allocated);
307 rte_compressdev_private_xform_free(dev_id, priv_xform);
313 cperf_benchmark_test_runner(void *test_ctx)
315 struct cperf_benchmark_ctx *ctx = test_ctx;
316 struct comp_test_data *test_data = ctx->ver.options;
317 uint32_t lcore = rte_lcore_id();
318 static rte_atomic16_t display_once = RTE_ATOMIC16_INIT(0);
320 ctx->ver.mem.lcore_id = lcore;
321 int i, ret = EXIT_SUCCESS;
324 * First the verification part is needed
326 if (cperf_verify_test_runner(&ctx->ver)) {
332 * Run the tests twice, discarding the first performance
333 * results, before the cache is warmed up
335 for (i = 0; i < 2; i++) {
336 if (main_loop(ctx, RTE_COMP_COMPRESS) < 0) {
342 for (i = 0; i < 2; i++) {
343 if (main_loop(ctx, RTE_COMP_DECOMPRESS) < 0) {
350 (double)(ctx->comp_tsc_duration[test_data->level]) /
351 test_data->input_data_sz;
353 ctx->decomp_tsc_byte =
354 (double)(ctx->decomp_tsc_duration[test_data->level]) /
355 test_data->input_data_sz;
357 ctx->comp_gbps = rte_get_tsc_hz() / ctx->comp_tsc_byte * 8 /
360 ctx->decomp_gbps = rte_get_tsc_hz() / ctx->decomp_tsc_byte * 8 /
363 if (rte_atomic16_test_and_set(&display_once)) {
364 printf("%12s%6s%12s%17s%15s%16s\n",
365 "lcore id", "Level", "Comp size", "Comp ratio [%]",
366 "Comp [Gbps]", "Decomp [Gbps]");
369 printf("%12u%6u%12zu%17.2f%15.2f%16.2f\n",
370 ctx->ver.mem.lcore_id,
371 test_data->level, ctx->ver.comp_data_sz, ctx->ver.ratio,