4 * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <rte_cryptodev.h>
38 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
39 #include <rte_cryptodev_scheduler.h>
43 #include "cperf_options.h"
44 #include "cperf_test_vector_parsing.h"
45 #include "cperf_test_throughput.h"
46 #include "cperf_test_latency.h"
47 #include "cperf_test_verify.h"
48 #include "cperf_test_pmd_cyclecount.h"
50 #define NUM_SESSIONS 2048
51 #define SESS_MEMPOOL_CACHE_SIZE 64
53 const char *cperf_test_type_strs[] = {
54 [CPERF_TEST_TYPE_THROUGHPUT] = "throughput",
55 [CPERF_TEST_TYPE_LATENCY] = "latency",
56 [CPERF_TEST_TYPE_VERIFY] = "verify",
57 [CPERF_TEST_TYPE_PMDCC] = "pmd-cyclecount"
60 const char *cperf_op_type_strs[] = {
61 [CPERF_CIPHER_ONLY] = "cipher-only",
62 [CPERF_AUTH_ONLY] = "auth-only",
63 [CPERF_CIPHER_THEN_AUTH] = "cipher-then-auth",
64 [CPERF_AUTH_THEN_CIPHER] = "auth-then-cipher",
68 const struct cperf_test cperf_testmap[] = {
69 [CPERF_TEST_TYPE_THROUGHPUT] = {
70 cperf_throughput_test_constructor,
71 cperf_throughput_test_runner,
72 cperf_throughput_test_destructor
74 [CPERF_TEST_TYPE_LATENCY] = {
75 cperf_latency_test_constructor,
76 cperf_latency_test_runner,
77 cperf_latency_test_destructor
79 [CPERF_TEST_TYPE_VERIFY] = {
80 cperf_verify_test_constructor,
81 cperf_verify_test_runner,
82 cperf_verify_test_destructor
84 [CPERF_TEST_TYPE_PMDCC] = {
85 cperf_pmd_cyclecount_test_constructor,
86 cperf_pmd_cyclecount_test_runner,
87 cperf_pmd_cyclecount_test_destructor
92 cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs,
93 struct rte_mempool *session_pool_socket[])
95 uint8_t enabled_cdev_count = 0, nb_lcores, cdev_id;
99 enabled_cdev_count = rte_cryptodev_devices_get(opts->device_type,
100 enabled_cdevs, RTE_CRYPTO_MAX_DEVS);
101 if (enabled_cdev_count == 0) {
102 printf("No crypto devices type %s available\n",
107 nb_lcores = rte_lcore_count() - 1;
109 if (enabled_cdev_count > nb_lcores) {
110 printf("Number of capable crypto devices (%d) "
111 "has to be less or equal to number of slave "
112 "cores (%d)\n", enabled_cdev_count, nb_lcores);
116 /* Create a mempool shared by all the devices */
117 uint32_t max_sess_size = 0, sess_size;
119 for (cdev_id = 0; cdev_id < rte_cryptodev_count(); cdev_id++) {
120 sess_size = rte_cryptodev_get_private_session_size(cdev_id);
121 if (sess_size > max_sess_size)
122 max_sess_size = sess_size;
126 * Calculate number of needed queue pairs, based on the amount
127 * of available number of logical cores and crypto devices.
128 * For instance, if there are 4 cores and 2 crypto devices,
129 * 2 queue pairs will be set up per device.
131 opts->nb_qps = (nb_lcores % enabled_cdev_count) ?
132 (nb_lcores / enabled_cdev_count) + 1 :
133 nb_lcores / enabled_cdev_count;
135 for (i = 0; i < enabled_cdev_count &&
136 i < RTE_CRYPTO_MAX_DEVS; i++) {
137 cdev_id = enabled_cdevs[i];
138 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
140 * If multi-core scheduler is used, limit the number
141 * of queue pairs to 1, as there is no way to know
142 * how many cores are being used by the PMD, and
143 * how many will be available for the application.
145 if (!strcmp((const char *)opts->device_type, "crypto_scheduler") &&
146 rte_cryptodev_scheduler_mode_get(cdev_id) ==
147 CDEV_SCHED_MODE_MULTICORE)
151 struct rte_cryptodev_info cdev_info;
152 uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);
154 rte_cryptodev_info_get(cdev_id, &cdev_info);
155 if (opts->nb_qps > cdev_info.max_nb_queue_pairs) {
156 printf("Number of needed queue pairs is higher "
157 "than the maximum number of queue pairs "
159 printf("Lower the number of cores or increase "
160 "the number of crypto devices\n");
163 struct rte_cryptodev_config conf = {
164 .nb_queue_pairs = opts->nb_qps,
165 .socket_id = socket_id
168 struct rte_cryptodev_qp_conf qp_conf = {
169 .nb_descriptors = opts->nb_descriptors
172 if (session_pool_socket[socket_id] == NULL) {
173 char mp_name[RTE_MEMPOOL_NAMESIZE];
174 struct rte_mempool *sess_mp;
176 snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
177 "sess_mp_%u", socket_id);
179 sess_mp = rte_mempool_create(mp_name,
182 SESS_MEMPOOL_CACHE_SIZE,
187 if (sess_mp == NULL) {
188 printf("Cannot create session pool on socket %d\n",
193 printf("Allocated session pool on socket %d\n", socket_id);
194 session_pool_socket[socket_id] = sess_mp;
197 ret = rte_cryptodev_configure(cdev_id, &conf);
199 printf("Failed to configure cryptodev %u", cdev_id);
203 for (j = 0; j < opts->nb_qps; j++) {
204 ret = rte_cryptodev_queue_pair_setup(cdev_id, j,
206 session_pool_socket[socket_id]);
208 printf("Failed to setup queue pair %u on "
209 "cryptodev %u", j, cdev_id);
214 ret = rte_cryptodev_start(cdev_id);
216 printf("Failed to start device %u: error %d\n",
222 return enabled_cdev_count;
226 cperf_verify_devices_capabilities(struct cperf_options *opts,
227 uint8_t *enabled_cdevs, uint8_t nb_cryptodevs)
229 struct rte_cryptodev_sym_capability_idx cap_idx;
230 const struct rte_cryptodev_symmetric_capability *capability;
235 for (i = 0; i < nb_cryptodevs; i++) {
237 cdev_id = enabled_cdevs[i];
239 if (opts->op_type == CPERF_AUTH_ONLY ||
240 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
241 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
243 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
244 cap_idx.algo.auth = opts->auth_algo;
246 capability = rte_cryptodev_sym_capability_get(cdev_id,
248 if (capability == NULL)
251 ret = rte_cryptodev_sym_capability_check_auth(
260 if (opts->op_type == CPERF_CIPHER_ONLY ||
261 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
262 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
264 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
265 cap_idx.algo.cipher = opts->cipher_algo;
267 capability = rte_cryptodev_sym_capability_get(cdev_id,
269 if (capability == NULL)
272 ret = rte_cryptodev_sym_capability_check_cipher(
280 if (opts->op_type == CPERF_AEAD) {
282 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
283 cap_idx.algo.aead = opts->aead_algo;
285 capability = rte_cryptodev_sym_capability_get(cdev_id,
287 if (capability == NULL)
290 ret = rte_cryptodev_sym_capability_check_aead(
305 cperf_check_test_vector(struct cperf_options *opts,
306 struct cperf_test_vector *test_vec)
308 if (opts->op_type == CPERF_CIPHER_ONLY) {
309 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
310 if (test_vec->plaintext.data == NULL)
312 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
313 if (test_vec->plaintext.data == NULL)
315 if (test_vec->plaintext.length < opts->max_buffer_size)
317 if (test_vec->ciphertext.data == NULL)
319 if (test_vec->ciphertext.length < opts->max_buffer_size)
321 if (test_vec->cipher_iv.data == NULL)
323 if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
325 if (test_vec->cipher_key.data == NULL)
327 if (test_vec->cipher_key.length != opts->cipher_key_sz)
330 } else if (opts->op_type == CPERF_AUTH_ONLY) {
331 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
332 if (test_vec->plaintext.data == NULL)
334 if (test_vec->plaintext.length < opts->max_buffer_size)
336 if (test_vec->auth_key.data == NULL)
338 if (test_vec->auth_key.length != opts->auth_key_sz)
340 if (test_vec->auth_iv.length != opts->auth_iv_sz)
342 /* Auth IV is only required for some algorithms */
343 if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
345 if (test_vec->digest.data == NULL)
347 if (test_vec->digest.length < opts->digest_sz)
351 } else if (opts->op_type == CPERF_CIPHER_THEN_AUTH ||
352 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
353 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
354 if (test_vec->plaintext.data == NULL)
356 if (test_vec->plaintext.length < opts->max_buffer_size)
358 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
359 if (test_vec->plaintext.data == NULL)
361 if (test_vec->plaintext.length < opts->max_buffer_size)
363 if (test_vec->ciphertext.data == NULL)
365 if (test_vec->ciphertext.length < opts->max_buffer_size)
367 if (test_vec->cipher_iv.data == NULL)
369 if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
371 if (test_vec->cipher_key.data == NULL)
373 if (test_vec->cipher_key.length != opts->cipher_key_sz)
376 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
377 if (test_vec->auth_key.data == NULL)
379 if (test_vec->auth_key.length != opts->auth_key_sz)
381 if (test_vec->auth_iv.length != opts->auth_iv_sz)
383 /* Auth IV is only required for some algorithms */
384 if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
386 if (test_vec->digest.data == NULL)
388 if (test_vec->digest.length < opts->digest_sz)
391 } else if (opts->op_type == CPERF_AEAD) {
392 if (test_vec->plaintext.data == NULL)
394 if (test_vec->plaintext.length < opts->max_buffer_size)
396 if (test_vec->ciphertext.data == NULL)
398 if (test_vec->ciphertext.length < opts->max_buffer_size)
400 if (test_vec->aead_iv.data == NULL)
402 if (test_vec->aead_iv.length != opts->aead_iv_sz)
404 if (test_vec->aad.data == NULL)
406 if (test_vec->aad.length != opts->aead_aad_sz)
408 if (test_vec->digest.data == NULL)
410 if (test_vec->digest.length < opts->digest_sz)
417 main(int argc, char **argv)
419 struct cperf_options opts = {0};
420 struct cperf_test_vector *t_vec = NULL;
421 struct cperf_op_fns op_fns;
423 void *ctx[RTE_MAX_LCORE] = { };
424 struct rte_mempool *session_pool_socket[RTE_MAX_NUMA_NODES] = { 0 };
426 int nb_cryptodevs = 0;
427 uint16_t total_nb_qps = 0;
429 uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 };
431 uint8_t buffer_size_idx = 0;
436 /* Initialise DPDK EAL */
437 ret = rte_eal_init(argc, argv);
439 rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
443 cperf_options_default(&opts);
445 ret = cperf_options_parse(&opts, argc, argv);
447 RTE_LOG(ERR, USER1, "Parsing on or more user options failed\n");
451 ret = cperf_options_check(&opts);
454 "Checking on or more user options failed\n");
458 nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs,
459 session_pool_socket);
462 cperf_options_dump(&opts);
464 if (nb_cryptodevs < 1) {
465 RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
471 ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
474 RTE_LOG(ERR, USER1, "Crypto device type does not support "
475 "capabilities requested\n");
479 if (opts.test_file != NULL) {
480 t_vec = cperf_test_vector_get_from_file(&opts);
483 "Failed to create test vector for"
484 " specified file\n");
488 if (cperf_check_test_vector(&opts, t_vec)) {
489 RTE_LOG(ERR, USER1, "Incomplete necessary test vectors"
494 t_vec = cperf_test_vector_get_dummy(&opts);
497 "Failed to create test vector for"
498 " specified algorithms\n");
503 ret = cperf_get_op_functions(&opts, &op_fns);
505 RTE_LOG(ERR, USER1, "Failed to find function ops set for "
506 "specified algorithms combination\n");
511 show_test_vector(t_vec);
513 total_nb_qps = nb_cryptodevs * opts.nb_qps;
516 uint8_t qp_id = 0, cdev_index = 0;
517 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
519 if (i == total_nb_qps)
522 cdev_id = enabled_cdevs[cdev_index];
524 uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);
526 ctx[i] = cperf_testmap[opts.test].constructor(
527 session_pool_socket[socket_id], cdev_id, qp_id,
528 &opts, t_vec, &op_fns);
529 if (ctx[i] == NULL) {
530 RTE_LOG(ERR, USER1, "Test run constructor failed\n");
533 qp_id = (qp_id + 1) % opts.nb_qps;
539 /* Get first size from range or list */
540 if (opts.inc_buffer_size != 0)
541 opts.test_buffer_size = opts.min_buffer_size;
543 opts.test_buffer_size = opts.buffer_size_list[0];
545 while (opts.test_buffer_size <= opts.max_buffer_size) {
547 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
549 if (i == total_nb_qps)
552 rte_eal_remote_launch(cperf_testmap[opts.test].runner,
557 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
559 if (i == total_nb_qps)
561 rte_eal_wait_lcore(lcore_id);
565 /* Get next size from range or list */
566 if (opts.inc_buffer_size != 0)
567 opts.test_buffer_size += opts.inc_buffer_size;
569 if (++buffer_size_idx == opts.buffer_size_count)
571 opts.test_buffer_size = opts.buffer_size_list[buffer_size_idx];
576 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
578 if (i == total_nb_qps)
581 cperf_testmap[opts.test].destructor(ctx[i]);
585 for (i = 0; i < nb_cryptodevs &&
586 i < RTE_CRYPTO_MAX_DEVS; i++)
587 rte_cryptodev_stop(enabled_cdevs[i]);
589 free_test_vector(t_vec, &opts);
596 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
597 if (i == total_nb_qps)
600 cdev_id = enabled_cdevs[i];
602 if (ctx[i] && cperf_testmap[opts.test].destructor)
603 cperf_testmap[opts.test].destructor(ctx[i]);
607 for (i = 0; i < nb_cryptodevs &&
608 i < RTE_CRYPTO_MAX_DEVS; i++)
609 rte_cryptodev_stop(enabled_cdevs[i]);
611 free_test_vector(t_vec, &opts);