1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
9 #include <rte_malloc.h>
12 #include <rte_compressdev.h>
14 #include "comp_perf.h"
15 #include "comp_perf_options.h"
16 #include "comp_perf_test_common.h"
17 #include "comp_perf_test_cyclecount.h"
18 #include "comp_perf_test_throughput.h"
19 #include "comp_perf_test_verify.h"
21 #define NUM_MAX_XFORMS 16
22 #define NUM_MAX_INFLIGHT_OPS 512
25 const char *comp_perf_test_type_strs[] = {
26 [CPERF_TEST_TYPE_THROUGHPUT] = "throughput",
27 [CPERF_TEST_TYPE_VERIFY] = "verify",
28 [CPERF_TEST_TYPE_PMDCC] = "pmd-cyclecount"
32 static const struct cperf_test cperf_testmap[] = {
33 [CPERF_TEST_TYPE_THROUGHPUT] = {
34 cperf_throughput_test_constructor,
35 cperf_throughput_test_runner,
36 cperf_throughput_test_destructor
39 [CPERF_TEST_TYPE_VERIFY] = {
40 cperf_verify_test_constructor,
41 cperf_verify_test_runner,
42 cperf_verify_test_destructor
45 [CPERF_TEST_TYPE_PMDCC] = {
46 cperf_cyclecount_test_constructor,
47 cperf_cyclecount_test_runner,
48 cperf_cyclecount_test_destructor
52 static struct comp_test_data *test_data;
55 comp_perf_check_capabilities(struct comp_test_data *test_data, uint8_t cdev_id)
57 const struct rte_compressdev_capabilities *cap;
59 cap = rte_compressdev_capability_get(cdev_id,
60 RTE_COMP_ALGO_DEFLATE);
64 "Compress device does not support DEFLATE\n");
68 uint64_t comp_flags = cap->comp_feature_flags;
70 /* Huffman enconding */
71 if (test_data->huffman_enc == RTE_COMP_HUFFMAN_FIXED &&
72 (comp_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0) {
74 "Compress device does not supported Fixed Huffman\n");
78 if (test_data->huffman_enc == RTE_COMP_HUFFMAN_DYNAMIC &&
79 (comp_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0) {
81 "Compress device does not supported Dynamic Huffman\n");
86 if (test_data->window_sz != -1) {
87 if (param_range_check(test_data->window_sz, &cap->window_size)
90 "Compress device does not support "
91 "this window size\n");
95 /* Set window size to PMD maximum if none was specified */
96 test_data->window_sz = cap->window_size.max;
98 /* Check if chained mbufs is supported */
99 if (test_data->max_sgl_segs > 1 &&
100 (comp_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0) {
101 RTE_LOG(INFO, USER1, "Compress device does not support "
102 "chained mbufs. Max SGL segments set to 1\n");
103 test_data->max_sgl_segs = 1;
106 /* Level 0 support */
107 if (test_data->level_lst.min == 0 &&
108 (comp_flags & RTE_COMP_FF_NONCOMPRESSED_BLOCKS) == 0) {
109 RTE_LOG(ERR, USER1, "Compress device does not support "
110 "level 0 (no compression)\n");
118 comp_perf_initialize_compressdev(struct comp_test_data *test_data,
119 uint8_t *enabled_cdevs)
121 uint8_t enabled_cdev_count, nb_lcores, cdev_id;
125 enabled_cdev_count = rte_compressdev_devices_get(test_data->driver_name,
126 enabled_cdevs, RTE_COMPRESS_MAX_DEVS);
127 if (enabled_cdev_count == 0) {
128 RTE_LOG(ERR, USER1, "No compress devices type %s available,"
129 " please check the list of specified devices in EAL section\n",
130 test_data->driver_name);
134 nb_lcores = rte_lcore_count() - 1;
137 * if there are more available than cores.
139 if (enabled_cdev_count > nb_lcores) {
140 if (nb_lcores == 0) {
141 RTE_LOG(ERR, USER1, "Cannot run with 0 cores! Increase the number of cores\n");
144 enabled_cdev_count = nb_lcores;
146 "There's more available devices than cores!"
147 " The number of devices has been aligned to %d cores\n",
152 * Calculate number of needed queue pairs, based on the amount
153 * of available number of logical cores and compression devices.
154 * For instance, if there are 4 cores and 2 compression devices,
155 * 2 queue pairs will be set up per device.
156 * One queue pair per one core.
157 * if e.g.: there're 3 cores and 2 compression devices,
158 * 2 queue pairs will be set up per device but one queue pair
159 * will left unused in the last one device
161 test_data->nb_qps = (nb_lcores % enabled_cdev_count) ?
162 (nb_lcores / enabled_cdev_count) + 1 :
163 nb_lcores / enabled_cdev_count;
165 for (i = 0; i < enabled_cdev_count &&
166 i < RTE_COMPRESS_MAX_DEVS; i++,
167 nb_lcores -= test_data->nb_qps) {
168 cdev_id = enabled_cdevs[i];
170 struct rte_compressdev_info cdev_info;
171 uint8_t socket_id = rte_compressdev_socket_id(cdev_id);
173 rte_compressdev_info_get(cdev_id, &cdev_info);
174 if (cdev_info.max_nb_queue_pairs &&
175 test_data->nb_qps > cdev_info.max_nb_queue_pairs) {
177 "Number of needed queue pairs is higher "
178 "than the maximum number of queue pairs "
181 "Lower the number of cores or increase "
182 "the number of crypto devices\n");
186 if (comp_perf_check_capabilities(test_data, cdev_id) < 0)
189 /* Configure compressdev */
190 struct rte_compressdev_config config = {
191 .socket_id = socket_id,
192 .nb_queue_pairs = nb_lcores > test_data->nb_qps
193 ? test_data->nb_qps : nb_lcores,
194 .max_nb_priv_xforms = NUM_MAX_XFORMS,
198 if (rte_compressdev_configure(cdev_id, &config) < 0) {
199 RTE_LOG(ERR, USER1, "Device configuration failed\n");
203 for (j = 0; j < test_data->nb_qps; j++) {
204 ret = rte_compressdev_queue_pair_setup(cdev_id, j,
205 NUM_MAX_INFLIGHT_OPS, socket_id);
208 "Failed to setup queue pair %u on compressdev %u",
214 ret = rte_compressdev_start(cdev_id);
217 "Failed to start device %u: error %d\n",
223 return enabled_cdev_count;
227 comp_perf_dump_input_data(struct comp_test_data *test_data)
229 FILE *f = fopen(test_data->input_file, "r");
233 RTE_LOG(ERR, USER1, "Input file could not be opened\n");
237 if (fseek(f, 0, SEEK_END) != 0) {
238 RTE_LOG(ERR, USER1, "Size of input could not be calculated\n");
241 size_t actual_file_sz = ftell(f);
242 /* If extended input data size has not been set,
243 * input data size = file size
246 if (test_data->input_data_sz == 0)
247 test_data->input_data_sz = actual_file_sz;
249 if (test_data->input_data_sz <= 0 || actual_file_sz <= 0 ||
250 fseek(f, 0, SEEK_SET) != 0) {
251 RTE_LOG(ERR, USER1, "Size of input could not be calculated\n");
255 test_data->input_data = rte_zmalloc_socket(NULL,
256 test_data->input_data_sz, 0, rte_socket_id());
258 if (test_data->input_data == NULL) {
259 RTE_LOG(ERR, USER1, "Memory to hold the data from the input "
260 "file could not be allocated\n");
264 size_t remaining_data = test_data->input_data_sz;
265 uint8_t *data = test_data->input_data;
267 while (remaining_data > 0) {
268 size_t data_to_read = RTE_MIN(remaining_data, actual_file_sz);
270 if (fread(data, data_to_read, 1, f) != 1) {
271 RTE_LOG(ERR, USER1, "Input file could not be read\n");
274 if (fseek(f, 0, SEEK_SET) != 0) {
276 "Size of input could not be calculated\n");
279 remaining_data -= data_to_read;
280 data += data_to_read;
284 if (test_data->input_data_sz > actual_file_sz)
286 "%zu bytes read from file %s, extending the file %.2f times\n",
287 test_data->input_data_sz, test_data->input_file,
288 (double)test_data->input_data_sz/actual_file_sz);
291 "%zu bytes read from file %s\n",
292 test_data->input_data_sz, test_data->input_file);
302 comp_perf_cleanup_on_signal(int signalNumber __rte_unused)
304 test_data->perf_comp_force_stop = 1;
308 comp_perf_register_cleanup_on_signal(void)
310 signal(SIGTERM, comp_perf_cleanup_on_signal);
311 signal(SIGINT, comp_perf_cleanup_on_signal);
315 main(int argc, char **argv)
317 uint8_t level_idx = 0;
319 void *ctx[RTE_MAX_LCORE] = {};
320 uint8_t enabled_cdevs[RTE_COMPRESS_MAX_DEVS];
321 int nb_compressdevs = 0;
322 uint16_t total_nb_qps = 0;
326 /* Initialise DPDK EAL */
327 ret = rte_eal_init(argc, argv);
329 rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
333 test_data = rte_zmalloc_socket(NULL, sizeof(struct comp_test_data),
336 if (test_data == NULL)
337 rte_exit(EXIT_FAILURE, "Cannot reserve memory in socket %d\n",
340 comp_perf_register_cleanup_on_signal();
343 test_data->cleanup = ST_TEST_DATA;
344 comp_perf_options_default(test_data);
346 if (comp_perf_options_parse(test_data, argc, argv) < 0) {
348 "Parsing one or more user options failed\n");
353 if (comp_perf_options_check(test_data) < 0) {
359 comp_perf_initialize_compressdev(test_data, enabled_cdevs);
361 if (nb_compressdevs < 1) {
366 test_data->cleanup = ST_COMPDEV;
367 if (comp_perf_dump_input_data(test_data) < 0) {
372 test_data->cleanup = ST_INPUT_DATA;
374 if (test_data->level_lst.inc != 0)
375 test_data->level = test_data->level_lst.min;
377 test_data->level = test_data->level_lst.list[0];
379 printf("\nApp uses socket: %u\n", rte_socket_id());
380 printf("Burst size = %u\n", test_data->burst_sz);
381 printf("Input data size = %zu\n", test_data->input_data_sz);
382 if (test_data->test == CPERF_TEST_TYPE_PMDCC)
383 printf("Cycle-count delay = %u [us]\n",
384 test_data->cyclecount_delay);
386 test_data->cleanup = ST_DURING_TEST;
387 total_nb_qps = nb_compressdevs * test_data->nb_qps;
390 uint8_t qp_id = 0, cdev_index = 0;
392 RTE_LCORE_FOREACH_WORKER(lcore_id) {
394 if (i == total_nb_qps)
397 cdev_id = enabled_cdevs[cdev_index];
398 ctx[i] = cperf_testmap[test_data->test].constructor(
401 if (ctx[i] == NULL) {
402 RTE_LOG(ERR, USER1, "Test run constructor failed\n");
405 qp_id = (qp_id + 1) % test_data->nb_qps;
411 print_test_dynamics(test_data);
413 while (test_data->level <= test_data->level_lst.max) {
416 RTE_LCORE_FOREACH_WORKER(lcore_id) {
418 if (i == total_nb_qps)
421 rte_eal_remote_launch(
422 cperf_testmap[test_data->test].runner,
427 RTE_LCORE_FOREACH_WORKER(lcore_id) {
429 if (i == total_nb_qps)
431 ret |= rte_eal_wait_lcore(lcore_id);
435 if (ret != EXIT_SUCCESS)
438 if (test_data->level_lst.inc != 0)
439 test_data->level += test_data->level_lst.inc;
441 if (++level_idx == test_data->level_lst.count)
443 test_data->level = test_data->level_lst.list[level_idx];
448 switch (test_data->cleanup) {
452 RTE_LCORE_FOREACH_WORKER(lcore_id) {
453 if (i == total_nb_qps)
456 if (ctx[i] && cperf_testmap[test_data->test].destructor)
457 cperf_testmap[test_data->test].destructor(
463 rte_free(test_data->input_data);
466 for (i = 0; i < nb_compressdevs &&
467 i < RTE_COMPRESS_MAX_DEVS; i++) {
468 rte_compressdev_stop(enabled_cdevs[i]);
469 rte_compressdev_close(enabled_cdevs[i]);
477 i = rte_eal_cleanup();
480 "Error from rte_eal_cleanup(), %d\n", i);
489 cperf_cyclecount_test_constructor(uint8_t dev_id __rte_unused,
490 uint16_t qp_id __rte_unused,
491 struct comp_test_data *options __rte_unused)
493 RTE_LOG(INFO, USER1, "Cycle count test is not supported yet\n");
498 cperf_cyclecount_test_destructor(void *arg __rte_unused)
500 RTE_LOG(INFO, USER1, "Something wrong happened!!!\n");
504 cperf_cyclecount_test_runner(void *test_ctx __rte_unused)
510 cperf_throughput_test_constructor(uint8_t dev_id __rte_unused,
511 uint16_t qp_id __rte_unused,
512 struct comp_test_data *options __rte_unused)
514 RTE_LOG(INFO, USER1, "Benchmark test is not supported yet\n");
519 cperf_throughput_test_destructor(void *arg __rte_unused)
525 cperf_throughput_test_runner(void *test_ctx __rte_unused)
530 cperf_verify_test_constructor(uint8_t dev_id __rte_unused,
531 uint16_t qp_id __rte_unused,
532 struct comp_test_data *options __rte_unused)
534 RTE_LOG(INFO, USER1, "Verify test is not supported yet\n");
539 cperf_verify_test_destructor(void *arg __rte_unused)
545 cperf_verify_test_runner(void *test_ctx __rte_unused)