Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2019 Intel Corporation
3 : : */
4 : :
5 : : #include <rte_malloc.h>
6 : : #include <rte_eal.h>
7 : : #include <rte_log.h>
8 : : #include <rte_compressdev.h>
9 : :
10 : : #include "comp_perf.h"
11 : : #include "comp_perf_options.h"
12 : : #include "comp_perf_test_throughput.h"
13 : : #include "comp_perf_test_cyclecount.h"
14 : : #include "comp_perf_test_common.h"
15 : : #include "comp_perf_test_verify.h"
16 : :
17 : :
18 : : #define DIV_CEIL(a, b) ((a) / (b) + ((a) % (b) != 0))
19 : :
20 : : struct cperf_buffer_info {
21 : : uint16_t total_segments;
22 : : uint16_t segment_sz;
23 : : uint16_t last_segment_sz;
24 : : uint32_t total_buffs; /*number of buffers = number of ops*/
25 : : uint16_t segments_per_buff;
26 : : uint16_t segments_per_last_buff;
27 : : size_t input_data_sz;
28 : : };
29 : :
30 : : static struct cperf_buffer_info buffer_info;
31 : :
32 : : int
33 : 0 : param_range_check(uint16_t size, const struct rte_param_log2_range *range)
34 : : {
35 : : unsigned int next_size;
36 : :
37 : : /* Check lower/upper bounds */
38 : 0 : if (size < range->min)
39 : : return -1;
40 : :
41 : 0 : if (size > range->max)
42 : : return -1;
43 : :
44 : : /* If range is actually only one value, size is correct */
45 : 0 : if (range->increment == 0)
46 : : return 0;
47 : :
48 : : /* Check if value is one of the supported sizes */
49 : 0 : for (next_size = range->min; next_size <= range->max;
50 : 0 : next_size += range->increment)
51 : 0 : if (size == next_size)
52 : : return 0;
53 : :
54 : : return -1;
55 : : }
56 : :
57 : : static uint32_t
58 : : find_buf_size(uint32_t input_size)
59 : : {
60 : : uint32_t i;
61 : :
62 : : /* From performance point of view the buffer size should be a
63 : : * power of 2 but also should be enough to store incompressible data
64 : : */
65 : :
66 : : /* We're looking for nearest power of 2 buffer size, which is greater
67 : : * than input_size
68 : : */
69 : : uint32_t size =
70 : 0 : !input_size ? MIN_COMPRESSED_BUF_SIZE : (input_size << 1);
71 : :
72 : 0 : for (i = UINT16_MAX + 1; !(i & size); i >>= 1)
73 : : ;
74 : :
75 : : return i > ((UINT16_MAX + 1) >> 1)
76 : 0 : ? (uint32_t)((float)input_size * EXPANSE_RATIO)
77 : 0 : : i;
78 : : }
79 : :
80 : : void
81 : 0 : comp_perf_free_memory(struct comp_test_data *test_data,
82 : : struct cperf_mem_resources *mem)
83 : : {
84 : : uint32_t i;
85 : :
86 : 0 : if (mem->decomp_bufs != NULL)
87 : 0 : for (i = 0; i < mem->total_bufs; i++)
88 : 0 : rte_pktmbuf_free(mem->decomp_bufs[i]);
89 : :
90 : 0 : if (mem->comp_bufs != NULL)
91 : 0 : for (i = 0; i < mem->total_bufs; i++)
92 : 0 : rte_pktmbuf_free(mem->comp_bufs[i]);
93 : :
94 : 0 : rte_free(mem->decomp_bufs);
95 : 0 : rte_free(mem->comp_bufs);
96 : 0 : rte_free(mem->decompressed_data);
97 : 0 : rte_free(mem->compressed_data);
98 : 0 : rte_mempool_free(mem->op_pool);
99 : 0 : rte_mempool_free(mem->decomp_buf_pool);
100 : 0 : rte_mempool_free(mem->comp_buf_pool);
101 : :
102 : : /* external mbuf support */
103 : 0 : if (mem->decomp_memzones != NULL) {
104 : 0 : for (i = 0; i < test_data->total_segs; i++)
105 : 0 : rte_memzone_free(mem->decomp_memzones[i]);
106 : 0 : rte_free(mem->decomp_memzones);
107 : : }
108 : 0 : if (mem->comp_memzones != NULL) {
109 : 0 : for (i = 0; i < test_data->total_segs; i++)
110 : 0 : rte_memzone_free(mem->comp_memzones[i]);
111 : 0 : rte_free(mem->comp_memzones);
112 : : }
113 : 0 : rte_free(mem->decomp_buf_infos);
114 : 0 : rte_free(mem->comp_buf_infos);
115 : 0 : }
116 : :
117 : : static void
118 : 0 : comp_perf_extbuf_free_cb(void *addr __rte_unused, void *opaque __rte_unused)
119 : : {
120 : 0 : }
121 : :
122 : : static const struct rte_memzone *
123 : 0 : comp_perf_make_memzone(const char *name, struct cperf_mem_resources *mem,
124 : : unsigned int number, size_t size)
125 : : {
126 : 0 : unsigned int socket_id = rte_socket_id();
127 : : char mz_name[RTE_MEMZONE_NAMESIZE];
128 : : const struct rte_memzone *memzone;
129 : :
130 : 0 : snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "%s_s%u_d%u_q%u_%d", name,
131 : 0 : socket_id, mem->dev_id, mem->qp_id, number);
132 : 0 : memzone = rte_memzone_lookup(mz_name);
133 : 0 : if (memzone != NULL && memzone->len != size) {
134 : 0 : rte_memzone_free(memzone);
135 : : memzone = NULL;
136 : : }
137 : 0 : if (memzone == NULL) {
138 : 0 : memzone = rte_memzone_reserve_aligned(mz_name, size, socket_id,
139 : : RTE_MEMZONE_IOVA_CONTIG, RTE_CACHE_LINE_SIZE);
140 : 0 : if (memzone == NULL)
141 : 0 : RTE_LOG(ERR, USER1, "Can't allocate memory zone %s\n",
142 : : mz_name);
143 : : }
144 : 0 : return memzone;
145 : : }
146 : :
147 : : static int
148 : 0 : comp_perf_allocate_external_mbufs(struct comp_test_data *test_data,
149 : : struct cperf_mem_resources *mem)
150 : : {
151 : : uint32_t i;
152 : :
153 : 0 : mem->comp_memzones = rte_zmalloc_socket(NULL,
154 : 0 : test_data->total_segs * sizeof(struct rte_memzone *),
155 : 0 : 0, rte_socket_id());
156 : :
157 : 0 : if (mem->comp_memzones == NULL) {
158 : 0 : RTE_LOG(ERR, USER1,
159 : : "Memory to hold the compression memzones could not be allocated\n");
160 : 0 : return -1;
161 : : }
162 : :
163 : 0 : mem->decomp_memzones = rte_zmalloc_socket(NULL,
164 : 0 : test_data->total_segs * sizeof(struct rte_memzone *),
165 : 0 : 0, rte_socket_id());
166 : :
167 : 0 : if (mem->decomp_memzones == NULL) {
168 : 0 : RTE_LOG(ERR, USER1,
169 : : "Memory to hold the decompression memzones could not be allocated\n");
170 : 0 : return -1;
171 : : }
172 : :
173 : 0 : mem->comp_buf_infos = rte_zmalloc_socket(NULL,
174 : 0 : test_data->total_segs * sizeof(struct rte_mbuf_ext_shared_info),
175 : 0 : 0, rte_socket_id());
176 : :
177 : 0 : if (mem->comp_buf_infos == NULL) {
178 : 0 : RTE_LOG(ERR, USER1,
179 : : "Memory to hold the compression buf infos could not be allocated\n");
180 : 0 : return -1;
181 : : }
182 : :
183 : 0 : mem->decomp_buf_infos = rte_zmalloc_socket(NULL,
184 : 0 : test_data->total_segs * sizeof(struct rte_mbuf_ext_shared_info),
185 : 0 : 0, rte_socket_id());
186 : :
187 : 0 : if (mem->decomp_buf_infos == NULL) {
188 : 0 : RTE_LOG(ERR, USER1,
189 : : "Memory to hold the decompression buf infos could not be allocated\n");
190 : 0 : return -1;
191 : : }
192 : :
193 : 0 : for (i = 0; i < test_data->total_segs; i++) {
194 : 0 : mem->comp_memzones[i] = comp_perf_make_memzone("comp", mem,
195 : 0 : i, test_data->out_seg_sz);
196 : 0 : if (mem->comp_memzones[i] == NULL) {
197 : 0 : RTE_LOG(ERR, USER1,
198 : : "Memory to hold the compression memzone could not be allocated\n");
199 : 0 : return -1;
200 : : }
201 : :
202 : 0 : mem->decomp_memzones[i] = comp_perf_make_memzone("decomp", mem,
203 : 0 : i, test_data->seg_sz);
204 : 0 : if (mem->decomp_memzones[i] == NULL) {
205 : 0 : RTE_LOG(ERR, USER1,
206 : : "Memory to hold the decompression memzone could not be allocated\n");
207 : 0 : return -1;
208 : : }
209 : :
210 : 0 : mem->comp_buf_infos[i].free_cb =
211 : : comp_perf_extbuf_free_cb;
212 : 0 : mem->comp_buf_infos[i].fcb_opaque = NULL;
213 : : rte_mbuf_ext_refcnt_set(&mem->comp_buf_infos[i], 1);
214 : :
215 : 0 : mem->decomp_buf_infos[i].free_cb =
216 : : comp_perf_extbuf_free_cb;
217 : 0 : mem->decomp_buf_infos[i].fcb_opaque = NULL;
218 : : rte_mbuf_ext_refcnt_set(&mem->decomp_buf_infos[i], 1);
219 : : }
220 : :
221 : : return 0;
222 : : }
223 : :
224 : : int
225 : 0 : comp_perf_allocate_memory(struct comp_test_data *test_data,
226 : : struct cperf_mem_resources *mem)
227 : : {
228 : : uint16_t comp_mbuf_size;
229 : : uint16_t decomp_mbuf_size;
230 : : size_t comp_data_size;
231 : : size_t decomp_data_size;
232 : : size_t output_data_sz;
233 : :
234 : 0 : test_data->out_seg_sz = find_buf_size(test_data->seg_sz);
235 : :
236 : 0 : if (test_data->test_op & COMPRESS) {
237 : : /*
238 : : * Number of segments for input and output
239 : : * (compression and decompression)
240 : : */
241 : 0 : test_data->total_segs = DIV_CEIL(test_data->input_data_sz,
242 : : test_data->seg_sz);
243 : : } else {
244 : : /*
245 : : * When application does decompression only, input data is
246 : : * compressed and smaller than the output. The expected size of
247 : : * uncompressed data given by the user in segment size argument.
248 : : */
249 : 0 : test_data->total_segs = test_data->max_sgl_segs;
250 : : }
251 : :
252 : 0 : output_data_sz = (size_t) test_data->out_seg_sz * test_data->total_segs;
253 : : output_data_sz =
254 : 0 : RTE_MAX(output_data_sz, (size_t) MIN_COMPRESSED_BUF_SIZE);
255 : :
256 : 0 : if (test_data->use_external_mbufs != 0) {
257 : 0 : if (comp_perf_allocate_external_mbufs(test_data, mem) < 0)
258 : : return -1;
259 : : comp_mbuf_size = 0;
260 : : decomp_mbuf_size = 0;
261 : 0 : } else if (test_data->test_op & COMPRESS) {
262 : 0 : comp_mbuf_size = test_data->out_seg_sz + RTE_PKTMBUF_HEADROOM;
263 : 0 : decomp_mbuf_size = test_data->seg_sz + RTE_PKTMBUF_HEADROOM;
264 : : } else {
265 : 0 : comp_mbuf_size = test_data->seg_sz + RTE_PKTMBUF_HEADROOM;
266 : 0 : decomp_mbuf_size = test_data->out_seg_sz + RTE_PKTMBUF_HEADROOM;
267 : : }
268 : :
269 : 0 : char pool_name[32] = "";
270 : :
271 : 0 : snprintf(pool_name, sizeof(pool_name), "comp_buf_pool_%u_qp_%u",
272 : 0 : mem->dev_id, mem->qp_id);
273 : 0 : mem->comp_buf_pool = rte_pktmbuf_pool_create(pool_name,
274 : : test_data->total_segs,
275 : : 0, 0,
276 : : comp_mbuf_size,
277 : 0 : rte_socket_id());
278 : 0 : if (mem->comp_buf_pool == NULL) {
279 : 0 : RTE_LOG(ERR, USER1, "Mbuf mempool could not be created\n");
280 : 0 : return -1;
281 : : }
282 : :
283 : 0 : snprintf(pool_name, sizeof(pool_name), "decomp_buf_pool_%u_qp_%u",
284 : 0 : mem->dev_id, mem->qp_id);
285 : 0 : mem->decomp_buf_pool = rte_pktmbuf_pool_create(pool_name,
286 : : test_data->total_segs,
287 : : 0, 0,
288 : : decomp_mbuf_size,
289 : 0 : rte_socket_id());
290 : 0 : if (mem->decomp_buf_pool == NULL) {
291 : 0 : RTE_LOG(ERR, USER1, "Mbuf mempool could not be created\n");
292 : 0 : return -1;
293 : : }
294 : :
295 : 0 : mem->total_bufs = DIV_CEIL(test_data->total_segs,
296 : : test_data->max_sgl_segs);
297 : :
298 : 0 : snprintf(pool_name, sizeof(pool_name), "op_pool_%u_qp_%u",
299 : 0 : mem->dev_id, mem->qp_id);
300 : :
301 : : /* one mempool for both src and dst mbufs */
302 : 0 : mem->op_pool = rte_comp_op_pool_create(pool_name,
303 : 0 : mem->total_bufs * 2,
304 : 0 : 0, 0, rte_socket_id());
305 : 0 : if (mem->op_pool == NULL) {
306 : 0 : RTE_LOG(ERR, USER1, "Comp op mempool could not be created\n");
307 : 0 : return -1;
308 : : }
309 : :
310 : 0 : if (test_data->test_op & COMPRESS) {
311 : : /*
312 : : * Compressed data might be a bit larger than input data,
313 : : * if data cannot be compressed
314 : : */
315 : : comp_data_size = output_data_sz;
316 : 0 : decomp_data_size = test_data->input_data_sz;
317 : : } else {
318 : 0 : comp_data_size = test_data->input_data_sz;
319 : : decomp_data_size = output_data_sz;
320 : : }
321 : :
322 : 0 : mem->compressed_data = rte_zmalloc_socket(NULL, comp_data_size, 0,
323 : 0 : rte_socket_id());
324 : 0 : if (mem->compressed_data == NULL) {
325 : 0 : RTE_LOG(ERR, USER1, "Memory to hold the data from the input "
326 : : "file could not be allocated\n");
327 : 0 : return -1;
328 : : }
329 : :
330 : 0 : mem->decompressed_data = rte_zmalloc_socket(NULL, decomp_data_size, 0,
331 : 0 : rte_socket_id());
332 : 0 : if (mem->decompressed_data == NULL) {
333 : 0 : RTE_LOG(ERR, USER1, "Memory to hold the data from the input "
334 : : "file could not be allocated\n");
335 : 0 : return -1;
336 : : }
337 : :
338 : 0 : mem->comp_bufs = rte_zmalloc_socket(NULL,
339 : 0 : mem->total_bufs * sizeof(struct rte_mbuf *),
340 : 0 : 0, rte_socket_id());
341 : 0 : if (mem->comp_bufs == NULL) {
342 : 0 : RTE_LOG(ERR, USER1, "Memory to hold the compression mbufs"
343 : : " could not be allocated\n");
344 : 0 : return -1;
345 : : }
346 : :
347 : 0 : mem->decomp_bufs = rte_zmalloc_socket(NULL,
348 : 0 : mem->total_bufs * sizeof(struct rte_mbuf *),
349 : 0 : 0, rte_socket_id());
350 : 0 : if (mem->decomp_bufs == NULL) {
351 : 0 : RTE_LOG(ERR, USER1, "Memory to hold the decompression mbufs"
352 : : " could not be allocated\n");
353 : 0 : return -1;
354 : : }
355 : :
356 : 0 : buffer_info.total_segments = test_data->total_segs;
357 : 0 : buffer_info.segment_sz = test_data->seg_sz;
358 : 0 : buffer_info.total_buffs = mem->total_bufs;
359 : 0 : buffer_info.segments_per_buff = test_data->max_sgl_segs;
360 : 0 : buffer_info.input_data_sz = test_data->input_data_sz;
361 : :
362 : 0 : return 0;
363 : : }
364 : :
365 : : int
366 : 0 : prepare_bufs(struct comp_test_data *test_data, struct cperf_mem_resources *mem)
367 : : {
368 : 0 : uint32_t remaining_data = test_data->input_data_sz;
369 : : uint32_t remaining_data_decomp = test_data->input_data_sz;
370 : 0 : uint8_t *input_data_ptr = test_data->input_data;
371 : : size_t data_sz = 0;
372 : : uint8_t *data_addr;
373 : : uint32_t i, j;
374 : : uint16_t segs_per_mbuf = 0;
375 : : uint32_t cmz = 0;
376 : : uint32_t dmz = 0;
377 : 0 : bool decompress_only = !!(test_data->test_op == DECOMPRESS);
378 : :
379 : 0 : for (i = 0; i < mem->total_bufs; i++) {
380 : : /* Allocate data in input mbuf and copy data from input file */
381 : 0 : mem->decomp_bufs[i] =
382 : 0 : rte_pktmbuf_alloc(mem->decomp_buf_pool);
383 : 0 : if (mem->decomp_bufs[i] == NULL) {
384 : 0 : RTE_LOG(ERR, USER1, "Could not allocate mbuf\n");
385 : 0 : return -1;
386 : : }
387 : :
388 : 0 : if (test_data->use_external_mbufs != 0) {
389 : 0 : rte_pktmbuf_attach_extbuf(mem->decomp_bufs[i],
390 : 0 : mem->decomp_memzones[dmz]->addr,
391 : 0 : mem->decomp_memzones[dmz]->iova,
392 : 0 : test_data->seg_sz,
393 : 0 : &mem->decomp_buf_infos[dmz]);
394 : 0 : dmz++;
395 : : }
396 : :
397 : 0 : if (!decompress_only)
398 : 0 : data_sz = RTE_MIN(remaining_data, test_data->seg_sz);
399 : : else
400 : 0 : data_sz = test_data->out_seg_sz;
401 : :
402 : 0 : data_addr = (uint8_t *) rte_pktmbuf_append(
403 : : mem->decomp_bufs[i], data_sz);
404 : 0 : if (data_addr == NULL) {
405 : 0 : RTE_LOG(ERR, USER1, "Could not append data\n");
406 : 0 : return -1;
407 : : }
408 : :
409 : 0 : if (!decompress_only) {
410 : : rte_memcpy(data_addr, input_data_ptr, data_sz);
411 : 0 : input_data_ptr += data_sz;
412 : 0 : remaining_data -= data_sz;
413 : : }
414 : :
415 : : /* Already one segment in the mbuf */
416 : : segs_per_mbuf = 1;
417 : :
418 : : /* Chain mbufs if needed for input mbufs */
419 : 0 : while (segs_per_mbuf < test_data->max_sgl_segs
420 : 0 : && remaining_data > 0) {
421 : : struct rte_mbuf *next_seg =
422 : 0 : rte_pktmbuf_alloc(mem->decomp_buf_pool);
423 : :
424 : 0 : if (next_seg == NULL) {
425 : 0 : RTE_LOG(ERR, USER1,
426 : : "Could not allocate mbuf\n");
427 : 0 : return -1;
428 : : }
429 : :
430 : 0 : if (test_data->use_external_mbufs != 0) {
431 : 0 : rte_pktmbuf_attach_extbuf(
432 : : next_seg,
433 : 0 : mem->decomp_memzones[dmz]->addr,
434 : 0 : mem->decomp_memzones[dmz]->iova,
435 : 0 : test_data->seg_sz,
436 : 0 : &mem->decomp_buf_infos[dmz]);
437 : 0 : dmz++;
438 : : }
439 : :
440 : 0 : if (!decompress_only)
441 : 0 : data_sz = RTE_MIN(remaining_data,
442 : : test_data->seg_sz);
443 : : else
444 : 0 : data_sz = test_data->out_seg_sz;
445 : :
446 : 0 : data_addr = (uint8_t *)rte_pktmbuf_append(next_seg,
447 : : data_sz);
448 : :
449 : 0 : if (data_addr == NULL) {
450 : 0 : RTE_LOG(ERR, USER1, "Could not append data\n");
451 : 0 : return -1;
452 : : }
453 : :
454 : 0 : if (!decompress_only) {
455 : : rte_memcpy(data_addr, input_data_ptr, data_sz);
456 : 0 : input_data_ptr += data_sz;
457 : 0 : remaining_data -= data_sz;
458 : : }
459 : :
460 : 0 : if (rte_pktmbuf_chain(mem->decomp_bufs[i],
461 : : next_seg) < 0) {
462 : 0 : RTE_LOG(ERR, USER1, "Could not chain mbufs\n");
463 : 0 : return -1;
464 : : }
465 : 0 : segs_per_mbuf++;
466 : : }
467 : :
468 : : /* Allocate data in output mbuf */
469 : 0 : mem->comp_bufs[i] =
470 : 0 : rte_pktmbuf_alloc(mem->comp_buf_pool);
471 : 0 : if (mem->comp_bufs[i] == NULL) {
472 : 0 : RTE_LOG(ERR, USER1, "Could not allocate mbuf\n");
473 : 0 : return -1;
474 : : }
475 : :
476 : 0 : if (test_data->use_external_mbufs != 0) {
477 : 0 : rte_pktmbuf_attach_extbuf(mem->comp_bufs[i],
478 : 0 : mem->comp_memzones[cmz]->addr,
479 : 0 : mem->comp_memzones[cmz]->iova,
480 : 0 : test_data->out_seg_sz,
481 : 0 : &mem->comp_buf_infos[cmz]);
482 : 0 : cmz++;
483 : : }
484 : :
485 : 0 : if (decompress_only)
486 : 0 : data_sz = RTE_MIN(remaining_data_decomp, test_data->seg_sz);
487 : : else
488 : 0 : data_sz = test_data->out_seg_sz;
489 : :
490 : 0 : data_addr = (uint8_t *) rte_pktmbuf_append(mem->comp_bufs[i],
491 : : data_sz);
492 : 0 : if (data_addr == NULL) {
493 : 0 : RTE_LOG(ERR, USER1, "Could not append data\n");
494 : 0 : return -1;
495 : : }
496 : :
497 : 0 : if (decompress_only) {
498 : : rte_memcpy(data_addr, input_data_ptr, data_sz);
499 : 0 : input_data_ptr += data_sz;
500 : 0 : remaining_data_decomp -= data_sz;
501 : : }
502 : :
503 : : /* Chain mbufs if needed for output mbufs */
504 : 0 : for (j = 1; j < segs_per_mbuf && remaining_data_decomp > 0; j++) {
505 : : struct rte_mbuf *next_seg =
506 : 0 : rte_pktmbuf_alloc(mem->comp_buf_pool);
507 : :
508 : 0 : if (next_seg == NULL) {
509 : 0 : RTE_LOG(ERR, USER1,
510 : : "Could not allocate mbuf\n");
511 : 0 : return -1;
512 : : }
513 : :
514 : 0 : if (test_data->use_external_mbufs != 0) {
515 : 0 : rte_pktmbuf_attach_extbuf(
516 : : next_seg,
517 : 0 : mem->comp_memzones[cmz]->addr,
518 : 0 : mem->comp_memzones[cmz]->iova,
519 : 0 : test_data->out_seg_sz,
520 : 0 : &mem->comp_buf_infos[cmz]);
521 : 0 : cmz++;
522 : : }
523 : :
524 : 0 : if (decompress_only)
525 : 0 : data_sz = RTE_MIN(remaining_data_decomp,
526 : : test_data->seg_sz);
527 : : else
528 : 0 : data_sz = test_data->out_seg_sz;
529 : :
530 : 0 : data_addr = (uint8_t *)rte_pktmbuf_append(next_seg,
531 : : data_sz);
532 : 0 : if (data_addr == NULL) {
533 : 0 : RTE_LOG(ERR, USER1, "Could not append data\n");
534 : 0 : return -1;
535 : : }
536 : :
537 : 0 : if (decompress_only) {
538 : : rte_memcpy(data_addr, input_data_ptr, data_sz);
539 : 0 : input_data_ptr += data_sz;
540 : 0 : remaining_data_decomp -= data_sz;
541 : : }
542 : :
543 : 0 : if (rte_pktmbuf_chain(mem->comp_bufs[i],
544 : : next_seg) < 0) {
545 : 0 : RTE_LOG(ERR, USER1, "Could not chain mbufs\n");
546 : 0 : return -1;
547 : : }
548 : : }
549 : : }
550 : :
551 : 0 : buffer_info.segments_per_last_buff = segs_per_mbuf;
552 : 0 : buffer_info.last_segment_sz = data_sz;
553 : :
554 : 0 : return 0;
555 : : }
556 : :
557 : : void
558 : 0 : print_test_dynamics(const struct comp_test_data *test_data)
559 : : {
560 : 0 : uint32_t opt_total_segs = DIV_CEIL(buffer_info.input_data_sz,
561 : : MAX_SEG_SIZE);
562 : :
563 : 0 : if (buffer_info.total_buffs > 1) {
564 : 0 : if (test_data->test == CPERF_TEST_TYPE_THROUGHPUT) {
565 : : printf("\nWarning: for the current input parameters, number"
566 : : " of ops is higher than one, which may result"
567 : : " in sub-optimal performance.\n");
568 : : printf("To improve the performance (for the current"
569 : : " input data) following parameters are"
570 : : " suggested:\n");
571 : : printf(" * Segment size: %d\n",
572 : : MAX_SEG_SIZE);
573 : : printf(" * Number of segments: %u\n",
574 : : opt_total_segs);
575 : : }
576 : 0 : } else if (buffer_info.total_buffs == 1) {
577 : 0 : printf("\nInfo: there is only one op with %u segments -"
578 : : " the compression ratio is the best.\n",
579 : 0 : buffer_info.segments_per_last_buff);
580 : 0 : if (buffer_info.segment_sz < MAX_SEG_SIZE)
581 : : printf("To reduce compression time, please use"
582 : : " bigger segment size: %d.\n",
583 : : MAX_SEG_SIZE);
584 : 0 : else if (buffer_info.segment_sz == MAX_SEG_SIZE)
585 : : printf("Segment size is optimal for the best"
586 : : " performance.\n");
587 : : } else
588 : : printf("Warning: something wrong happened!!\n");
589 : :
590 : 0 : printf("\nFor the current input parameters (segment size = %u,"
591 : : " maximum segments per SGL = %u):\n",
592 : 0 : buffer_info.segment_sz,
593 : 0 : buffer_info.segments_per_buff);
594 : 0 : printf(" * Total number of buffers: %d\n",
595 : 0 : buffer_info.total_segments);
596 : 0 : printf(" * %u buffer(s) %u bytes long, last buffer %u"
597 : : " byte(s) long\n",
598 : 0 : buffer_info.total_segments - 1,
599 : 0 : buffer_info.segment_sz,
600 : 0 : buffer_info.last_segment_sz);
601 : 0 : printf(" * Number of ops: %u\n", buffer_info.total_buffs);
602 : 0 : printf(" * Total memory allocation: %u\n",
603 : 0 : (buffer_info.total_segments - 1) * buffer_info.segment_sz
604 : 0 : + buffer_info.last_segment_sz);
605 : 0 : if (buffer_info.total_buffs > 1)
606 : 0 : printf(" * %u ops: %u segment(s) in each,"
607 : : " segment size %u\n",
608 : : buffer_info.total_buffs - 1,
609 : 0 : buffer_info.segments_per_buff,
610 : 0 : buffer_info.segment_sz);
611 : 0 : if (buffer_info.segments_per_last_buff > 1) {
612 : 0 : printf(" * 1 op %u segments:\n",
613 : : buffer_info.segments_per_last_buff);
614 : 0 : printf(" o %u segment size %u\n",
615 : 0 : buffer_info.segments_per_last_buff - 1,
616 : 0 : buffer_info.segment_sz);
617 : 0 : printf(" o last segment size %u\n",
618 : 0 : buffer_info.last_segment_sz);
619 : 0 : } else if (buffer_info.segments_per_last_buff == 1) {
620 : 0 : printf(" * 1 op (the last one): %u segment %u"
621 : : " byte(s) long\n\n",
622 : : buffer_info.segments_per_last_buff,
623 : 0 : buffer_info.last_segment_sz);
624 : : }
625 : : printf("\n");
626 : 0 : }
|