1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2017 Intel Corporation
9 #include <rte_cryptodev.h>
10 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
11 #include <rte_cryptodev_scheduler.h>
15 #include "cperf_options.h"
16 #include "cperf_test_vector_parsing.h"
17 #include "cperf_test_throughput.h"
18 #include "cperf_test_latency.h"
19 #include "cperf_test_verify.h"
20 #include "cperf_test_pmd_cyclecount.h"
22 #define NUM_SESSIONS 2048
23 #define SESS_MEMPOOL_CACHE_SIZE 64
25 const char *cperf_test_type_strs[] = {
26 [CPERF_TEST_TYPE_THROUGHPUT] = "throughput",
27 [CPERF_TEST_TYPE_LATENCY] = "latency",
28 [CPERF_TEST_TYPE_VERIFY] = "verify",
29 [CPERF_TEST_TYPE_PMDCC] = "pmd-cyclecount"
32 const char *cperf_op_type_strs[] = {
33 [CPERF_CIPHER_ONLY] = "cipher-only",
34 [CPERF_AUTH_ONLY] = "auth-only",
35 [CPERF_CIPHER_THEN_AUTH] = "cipher-then-auth",
36 [CPERF_AUTH_THEN_CIPHER] = "auth-then-cipher",
40 const struct cperf_test cperf_testmap[] = {
41 [CPERF_TEST_TYPE_THROUGHPUT] = {
42 cperf_throughput_test_constructor,
43 cperf_throughput_test_runner,
44 cperf_throughput_test_destructor
46 [CPERF_TEST_TYPE_LATENCY] = {
47 cperf_latency_test_constructor,
48 cperf_latency_test_runner,
49 cperf_latency_test_destructor
51 [CPERF_TEST_TYPE_VERIFY] = {
52 cperf_verify_test_constructor,
53 cperf_verify_test_runner,
54 cperf_verify_test_destructor
56 [CPERF_TEST_TYPE_PMDCC] = {
57 cperf_pmd_cyclecount_test_constructor,
58 cperf_pmd_cyclecount_test_runner,
59 cperf_pmd_cyclecount_test_destructor
64 cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs,
65 struct rte_mempool *session_pool_socket[])
67 uint8_t enabled_cdev_count = 0, nb_lcores, cdev_id;
71 enabled_cdev_count = rte_cryptodev_devices_get(opts->device_type,
72 enabled_cdevs, RTE_CRYPTO_MAX_DEVS);
73 if (enabled_cdev_count == 0) {
74 printf("No crypto devices type %s available\n",
79 nb_lcores = rte_lcore_count() - 1;
81 if (enabled_cdev_count > nb_lcores) {
82 printf("Number of capable crypto devices (%d) "
83 "has to be less or equal to number of slave "
84 "cores (%d)\n", enabled_cdev_count, nb_lcores);
88 /* Create a mempool shared by all the devices */
89 uint32_t max_sess_size = 0, sess_size;
91 for (cdev_id = 0; cdev_id < rte_cryptodev_count(); cdev_id++) {
92 sess_size = rte_cryptodev_get_private_session_size(cdev_id);
93 if (sess_size > max_sess_size)
94 max_sess_size = sess_size;
98 * Calculate number of needed queue pairs, based on the amount
99 * of available number of logical cores and crypto devices.
100 * For instance, if there are 4 cores and 2 crypto devices,
101 * 2 queue pairs will be set up per device.
103 opts->nb_qps = (nb_lcores % enabled_cdev_count) ?
104 (nb_lcores / enabled_cdev_count) + 1 :
105 nb_lcores / enabled_cdev_count;
107 for (i = 0; i < enabled_cdev_count &&
108 i < RTE_CRYPTO_MAX_DEVS; i++) {
109 cdev_id = enabled_cdevs[i];
110 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
112 * If multi-core scheduler is used, limit the number
113 * of queue pairs to 1, as there is no way to know
114 * how many cores are being used by the PMD, and
115 * how many will be available for the application.
117 if (!strcmp((const char *)opts->device_type, "crypto_scheduler") &&
118 rte_cryptodev_scheduler_mode_get(cdev_id) ==
119 CDEV_SCHED_MODE_MULTICORE)
123 struct rte_cryptodev_info cdev_info;
124 uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);
126 rte_cryptodev_info_get(cdev_id, &cdev_info);
127 if (opts->nb_qps > cdev_info.max_nb_queue_pairs) {
128 printf("Number of needed queue pairs is higher "
129 "than the maximum number of queue pairs "
131 printf("Lower the number of cores or increase "
132 "the number of crypto devices\n");
135 struct rte_cryptodev_config conf = {
136 .nb_queue_pairs = opts->nb_qps,
137 .socket_id = socket_id
140 struct rte_cryptodev_qp_conf qp_conf = {
141 .nb_descriptors = opts->nb_descriptors
144 if (session_pool_socket[socket_id] == NULL) {
145 char mp_name[RTE_MEMPOOL_NAMESIZE];
146 struct rte_mempool *sess_mp;
148 snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
149 "sess_mp_%u", socket_id);
151 sess_mp = rte_mempool_create(mp_name,
154 SESS_MEMPOOL_CACHE_SIZE,
159 if (sess_mp == NULL) {
160 printf("Cannot create session pool on socket %d\n",
165 printf("Allocated session pool on socket %d\n", socket_id);
166 session_pool_socket[socket_id] = sess_mp;
169 ret = rte_cryptodev_configure(cdev_id, &conf);
171 printf("Failed to configure cryptodev %u", cdev_id);
175 for (j = 0; j < opts->nb_qps; j++) {
176 ret = rte_cryptodev_queue_pair_setup(cdev_id, j,
178 session_pool_socket[socket_id]);
180 printf("Failed to setup queue pair %u on "
181 "cryptodev %u", j, cdev_id);
186 ret = rte_cryptodev_start(cdev_id);
188 printf("Failed to start device %u: error %d\n",
194 return enabled_cdev_count;
198 cperf_verify_devices_capabilities(struct cperf_options *opts,
199 uint8_t *enabled_cdevs, uint8_t nb_cryptodevs)
201 struct rte_cryptodev_sym_capability_idx cap_idx;
202 const struct rte_cryptodev_symmetric_capability *capability;
207 for (i = 0; i < nb_cryptodevs; i++) {
209 cdev_id = enabled_cdevs[i];
211 if (opts->op_type == CPERF_AUTH_ONLY ||
212 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
213 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
215 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
216 cap_idx.algo.auth = opts->auth_algo;
218 capability = rte_cryptodev_sym_capability_get(cdev_id,
220 if (capability == NULL)
223 ret = rte_cryptodev_sym_capability_check_auth(
232 if (opts->op_type == CPERF_CIPHER_ONLY ||
233 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
234 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
236 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
237 cap_idx.algo.cipher = opts->cipher_algo;
239 capability = rte_cryptodev_sym_capability_get(cdev_id,
241 if (capability == NULL)
244 ret = rte_cryptodev_sym_capability_check_cipher(
252 if (opts->op_type == CPERF_AEAD) {
254 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
255 cap_idx.algo.aead = opts->aead_algo;
257 capability = rte_cryptodev_sym_capability_get(cdev_id,
259 if (capability == NULL)
262 ret = rte_cryptodev_sym_capability_check_aead(
277 cperf_check_test_vector(struct cperf_options *opts,
278 struct cperf_test_vector *test_vec)
280 if (opts->op_type == CPERF_CIPHER_ONLY) {
281 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
282 if (test_vec->plaintext.data == NULL)
284 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
285 if (test_vec->plaintext.data == NULL)
287 if (test_vec->plaintext.length < opts->max_buffer_size)
289 if (test_vec->ciphertext.data == NULL)
291 if (test_vec->ciphertext.length < opts->max_buffer_size)
293 if (test_vec->cipher_iv.data == NULL)
295 if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
297 if (test_vec->cipher_key.data == NULL)
299 if (test_vec->cipher_key.length != opts->cipher_key_sz)
302 } else if (opts->op_type == CPERF_AUTH_ONLY) {
303 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
304 if (test_vec->plaintext.data == NULL)
306 if (test_vec->plaintext.length < opts->max_buffer_size)
308 if (test_vec->auth_key.data == NULL)
310 if (test_vec->auth_key.length != opts->auth_key_sz)
312 if (test_vec->auth_iv.length != opts->auth_iv_sz)
314 /* Auth IV is only required for some algorithms */
315 if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
317 if (test_vec->digest.data == NULL)
319 if (test_vec->digest.length < opts->digest_sz)
323 } else if (opts->op_type == CPERF_CIPHER_THEN_AUTH ||
324 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
325 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
326 if (test_vec->plaintext.data == NULL)
328 if (test_vec->plaintext.length < opts->max_buffer_size)
330 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
331 if (test_vec->plaintext.data == NULL)
333 if (test_vec->plaintext.length < opts->max_buffer_size)
335 if (test_vec->ciphertext.data == NULL)
337 if (test_vec->ciphertext.length < opts->max_buffer_size)
339 if (test_vec->cipher_iv.data == NULL)
341 if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
343 if (test_vec->cipher_key.data == NULL)
345 if (test_vec->cipher_key.length != opts->cipher_key_sz)
348 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
349 if (test_vec->auth_key.data == NULL)
351 if (test_vec->auth_key.length != opts->auth_key_sz)
353 if (test_vec->auth_iv.length != opts->auth_iv_sz)
355 /* Auth IV is only required for some algorithms */
356 if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
358 if (test_vec->digest.data == NULL)
360 if (test_vec->digest.length < opts->digest_sz)
363 } else if (opts->op_type == CPERF_AEAD) {
364 if (test_vec->plaintext.data == NULL)
366 if (test_vec->plaintext.length < opts->max_buffer_size)
368 if (test_vec->ciphertext.data == NULL)
370 if (test_vec->ciphertext.length < opts->max_buffer_size)
372 if (test_vec->aead_iv.data == NULL)
374 if (test_vec->aead_iv.length != opts->aead_iv_sz)
376 if (test_vec->aad.data == NULL)
378 if (test_vec->aad.length != opts->aead_aad_sz)
380 if (test_vec->digest.data == NULL)
382 if (test_vec->digest.length < opts->digest_sz)
389 main(int argc, char **argv)
391 struct cperf_options opts = {0};
392 struct cperf_test_vector *t_vec = NULL;
393 struct cperf_op_fns op_fns;
395 void *ctx[RTE_MAX_LCORE] = { };
396 struct rte_mempool *session_pool_socket[RTE_MAX_NUMA_NODES] = { 0 };
398 int nb_cryptodevs = 0;
399 uint16_t total_nb_qps = 0;
401 uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 };
403 uint8_t buffer_size_idx = 0;
408 /* Initialise DPDK EAL */
409 ret = rte_eal_init(argc, argv);
411 rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
415 cperf_options_default(&opts);
417 ret = cperf_options_parse(&opts, argc, argv);
419 RTE_LOG(ERR, USER1, "Parsing on or more user options failed\n");
423 ret = cperf_options_check(&opts);
426 "Checking on or more user options failed\n");
430 nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs,
431 session_pool_socket);
434 cperf_options_dump(&opts);
436 if (nb_cryptodevs < 1) {
437 RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
443 ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
446 RTE_LOG(ERR, USER1, "Crypto device type does not support "
447 "capabilities requested\n");
451 if (opts.test_file != NULL) {
452 t_vec = cperf_test_vector_get_from_file(&opts);
455 "Failed to create test vector for"
456 " specified file\n");
460 if (cperf_check_test_vector(&opts, t_vec)) {
461 RTE_LOG(ERR, USER1, "Incomplete necessary test vectors"
466 t_vec = cperf_test_vector_get_dummy(&opts);
469 "Failed to create test vector for"
470 " specified algorithms\n");
475 ret = cperf_get_op_functions(&opts, &op_fns);
477 RTE_LOG(ERR, USER1, "Failed to find function ops set for "
478 "specified algorithms combination\n");
483 show_test_vector(t_vec);
485 total_nb_qps = nb_cryptodevs * opts.nb_qps;
488 uint8_t qp_id = 0, cdev_index = 0;
489 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
491 if (i == total_nb_qps)
494 cdev_id = enabled_cdevs[cdev_index];
496 uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);
498 ctx[i] = cperf_testmap[opts.test].constructor(
499 session_pool_socket[socket_id], cdev_id, qp_id,
500 &opts, t_vec, &op_fns);
501 if (ctx[i] == NULL) {
502 RTE_LOG(ERR, USER1, "Test run constructor failed\n");
505 qp_id = (qp_id + 1) % opts.nb_qps;
511 /* Get first size from range or list */
512 if (opts.inc_buffer_size != 0)
513 opts.test_buffer_size = opts.min_buffer_size;
515 opts.test_buffer_size = opts.buffer_size_list[0];
517 while (opts.test_buffer_size <= opts.max_buffer_size) {
519 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
521 if (i == total_nb_qps)
524 rte_eal_remote_launch(cperf_testmap[opts.test].runner,
529 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
531 if (i == total_nb_qps)
533 rte_eal_wait_lcore(lcore_id);
537 /* Get next size from range or list */
538 if (opts.inc_buffer_size != 0)
539 opts.test_buffer_size += opts.inc_buffer_size;
541 if (++buffer_size_idx == opts.buffer_size_count)
543 opts.test_buffer_size = opts.buffer_size_list[buffer_size_idx];
548 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
550 if (i == total_nb_qps)
553 cperf_testmap[opts.test].destructor(ctx[i]);
557 for (i = 0; i < nb_cryptodevs &&
558 i < RTE_CRYPTO_MAX_DEVS; i++)
559 rte_cryptodev_stop(enabled_cdevs[i]);
561 free_test_vector(t_vec, &opts);
568 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
569 if (i == total_nb_qps)
572 cdev_id = enabled_cdevs[i];
574 if (ctx[i] && cperf_testmap[opts.test].destructor)
575 cperf_testmap[opts.test].destructor(ctx[i]);
579 for (i = 0; i < nb_cryptodevs &&
580 i < RTE_CRYPTO_MAX_DEVS; i++)
581 rte_cryptodev_stop(enabled_cdevs[i]);
583 free_test_vector(t_vec, &opts);