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