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>
40 #include "cperf_options.h"
41 #include "cperf_test_vector_parsing.h"
42 #include "cperf_test_throughput.h"
43 #include "cperf_test_latency.h"
44 #include "cperf_test_verify.h"
45 #include "cperf_test_pmd_cyclecount.h"
47 #define NUM_SESSIONS 2048
48 #define SESS_MEMPOOL_CACHE_SIZE 64
50 const char *cperf_test_type_strs[] = {
51 [CPERF_TEST_TYPE_THROUGHPUT] = "throughput",
52 [CPERF_TEST_TYPE_LATENCY] = "latency",
53 [CPERF_TEST_TYPE_VERIFY] = "verify",
54 [CPERF_TEST_TYPE_PMDCC] = "pmd-cyclecount"
57 const char *cperf_op_type_strs[] = {
58 [CPERF_CIPHER_ONLY] = "cipher-only",
59 [CPERF_AUTH_ONLY] = "auth-only",
60 [CPERF_CIPHER_THEN_AUTH] = "cipher-then-auth",
61 [CPERF_AUTH_THEN_CIPHER] = "auth-then-cipher",
65 const struct cperf_test cperf_testmap[] = {
66 [CPERF_TEST_TYPE_THROUGHPUT] = {
67 cperf_throughput_test_constructor,
68 cperf_throughput_test_runner,
69 cperf_throughput_test_destructor
71 [CPERF_TEST_TYPE_LATENCY] = {
72 cperf_latency_test_constructor,
73 cperf_latency_test_runner,
74 cperf_latency_test_destructor
76 [CPERF_TEST_TYPE_VERIFY] = {
77 cperf_verify_test_constructor,
78 cperf_verify_test_runner,
79 cperf_verify_test_destructor
81 [CPERF_TEST_TYPE_PMDCC] = {
82 cperf_pmd_cyclecount_test_constructor,
83 cperf_pmd_cyclecount_test_runner,
84 cperf_pmd_cyclecount_test_destructor
89 cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs,
90 struct rte_mempool *session_pool_socket[])
92 uint8_t enabled_cdev_count = 0, nb_lcores, cdev_id;
96 enabled_cdev_count = rte_cryptodev_devices_get(opts->device_type,
97 enabled_cdevs, RTE_CRYPTO_MAX_DEVS);
98 if (enabled_cdev_count == 0) {
99 printf("No crypto devices type %s available\n",
104 nb_lcores = rte_lcore_count() - 1;
106 if (enabled_cdev_count > nb_lcores) {
107 printf("Number of capable crypto devices (%d) "
108 "has to be less or equal to number of slave "
109 "cores (%d)\n", enabled_cdev_count, nb_lcores);
113 /* Create a mempool shared by all the devices */
114 uint32_t max_sess_size = 0, sess_size;
116 for (cdev_id = 0; cdev_id < rte_cryptodev_count(); cdev_id++) {
117 sess_size = rte_cryptodev_get_private_session_size(cdev_id);
118 if (sess_size > max_sess_size)
119 max_sess_size = sess_size;
122 for (i = 0; i < enabled_cdev_count &&
123 i < RTE_CRYPTO_MAX_DEVS; i++) {
124 cdev_id = enabled_cdevs[i];
125 uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);
127 struct rte_cryptodev_config conf = {
129 .socket_id = socket_id
132 struct rte_cryptodev_qp_conf qp_conf = {
133 .nb_descriptors = opts->nb_descriptors
137 if (session_pool_socket[socket_id] == NULL) {
138 char mp_name[RTE_MEMPOOL_NAMESIZE];
139 struct rte_mempool *sess_mp;
141 snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
142 "sess_mp_%u", socket_id);
144 sess_mp = rte_mempool_create(mp_name,
147 SESS_MEMPOOL_CACHE_SIZE,
152 if (sess_mp == NULL) {
153 printf("Cannot create session pool on socket %d\n",
158 printf("Allocated session pool on socket %d\n", socket_id);
159 session_pool_socket[socket_id] = sess_mp;
162 ret = rte_cryptodev_configure(cdev_id, &conf);
164 printf("Failed to configure cryptodev %u", cdev_id);
168 ret = rte_cryptodev_queue_pair_setup(cdev_id, 0,
170 session_pool_socket[socket_id]);
172 printf("Failed to setup queue pair %u on "
173 "cryptodev %u", 0, cdev_id);
177 ret = rte_cryptodev_start(cdev_id);
179 printf("Failed to start device %u: error %d\n",
185 return enabled_cdev_count;
189 cperf_verify_devices_capabilities(struct cperf_options *opts,
190 uint8_t *enabled_cdevs, uint8_t nb_cryptodevs)
192 struct rte_cryptodev_sym_capability_idx cap_idx;
193 const struct rte_cryptodev_symmetric_capability *capability;
198 for (i = 0; i < nb_cryptodevs; i++) {
200 cdev_id = enabled_cdevs[i];
202 if (opts->op_type == CPERF_AUTH_ONLY ||
203 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
204 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
206 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
207 cap_idx.algo.auth = opts->auth_algo;
209 capability = rte_cryptodev_sym_capability_get(cdev_id,
211 if (capability == NULL)
214 ret = rte_cryptodev_sym_capability_check_auth(
223 if (opts->op_type == CPERF_CIPHER_ONLY ||
224 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
225 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
227 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
228 cap_idx.algo.cipher = opts->cipher_algo;
230 capability = rte_cryptodev_sym_capability_get(cdev_id,
232 if (capability == NULL)
235 ret = rte_cryptodev_sym_capability_check_cipher(
243 if (opts->op_type == CPERF_AEAD) {
245 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
246 cap_idx.algo.aead = opts->aead_algo;
248 capability = rte_cryptodev_sym_capability_get(cdev_id,
250 if (capability == NULL)
253 ret = rte_cryptodev_sym_capability_check_aead(
268 cperf_check_test_vector(struct cperf_options *opts,
269 struct cperf_test_vector *test_vec)
271 if (opts->op_type == CPERF_CIPHER_ONLY) {
272 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
273 if (test_vec->plaintext.data == NULL)
275 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
276 if (test_vec->plaintext.data == NULL)
278 if (test_vec->plaintext.length < opts->max_buffer_size)
280 if (test_vec->ciphertext.data == NULL)
282 if (test_vec->ciphertext.length < opts->max_buffer_size)
284 if (test_vec->cipher_iv.data == NULL)
286 if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
288 if (test_vec->cipher_key.data == NULL)
290 if (test_vec->cipher_key.length != opts->cipher_key_sz)
293 } else if (opts->op_type == CPERF_AUTH_ONLY) {
294 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
295 if (test_vec->plaintext.data == NULL)
297 if (test_vec->plaintext.length < opts->max_buffer_size)
299 if (test_vec->auth_key.data == NULL)
301 if (test_vec->auth_key.length != opts->auth_key_sz)
303 if (test_vec->auth_iv.length != opts->auth_iv_sz)
305 /* Auth IV is only required for some algorithms */
306 if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
308 if (test_vec->digest.data == NULL)
310 if (test_vec->digest.length < opts->digest_sz)
314 } else if (opts->op_type == CPERF_CIPHER_THEN_AUTH ||
315 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
316 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
317 if (test_vec->plaintext.data == NULL)
319 if (test_vec->plaintext.length < opts->max_buffer_size)
321 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
322 if (test_vec->plaintext.data == NULL)
324 if (test_vec->plaintext.length < opts->max_buffer_size)
326 if (test_vec->ciphertext.data == NULL)
328 if (test_vec->ciphertext.length < opts->max_buffer_size)
330 if (test_vec->cipher_iv.data == NULL)
332 if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
334 if (test_vec->cipher_key.data == NULL)
336 if (test_vec->cipher_key.length != opts->cipher_key_sz)
339 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
340 if (test_vec->auth_key.data == NULL)
342 if (test_vec->auth_key.length != opts->auth_key_sz)
344 if (test_vec->auth_iv.length != opts->auth_iv_sz)
346 /* Auth IV is only required for some algorithms */
347 if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
349 if (test_vec->digest.data == NULL)
351 if (test_vec->digest.length < opts->digest_sz)
354 } else if (opts->op_type == CPERF_AEAD) {
355 if (test_vec->plaintext.data == NULL)
357 if (test_vec->plaintext.length < opts->max_buffer_size)
359 if (test_vec->ciphertext.data == NULL)
361 if (test_vec->ciphertext.length < opts->max_buffer_size)
363 if (test_vec->aead_iv.data == NULL)
365 if (test_vec->aead_iv.length != opts->aead_iv_sz)
367 if (test_vec->aad.data == NULL)
369 if (test_vec->aad.length != opts->aead_aad_sz)
371 if (test_vec->digest.data == NULL)
373 if (test_vec->digest.length < opts->digest_sz)
380 main(int argc, char **argv)
382 struct cperf_options opts = {0};
383 struct cperf_test_vector *t_vec = NULL;
384 struct cperf_op_fns op_fns;
386 void *ctx[RTE_MAX_LCORE] = { };
387 struct rte_mempool *session_pool_socket[RTE_MAX_NUMA_NODES] = { 0 };
389 int nb_cryptodevs = 0;
391 uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 };
393 uint8_t buffer_size_idx = 0;
398 /* Initialise DPDK EAL */
399 ret = rte_eal_init(argc, argv);
401 rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
405 cperf_options_default(&opts);
407 ret = cperf_options_parse(&opts, argc, argv);
409 RTE_LOG(ERR, USER1, "Parsing on or more user options failed\n");
413 ret = cperf_options_check(&opts);
416 "Checking on or more user options failed\n");
421 cperf_options_dump(&opts);
423 nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs,
424 session_pool_socket);
425 if (nb_cryptodevs < 1) {
426 RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
432 ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
435 RTE_LOG(ERR, USER1, "Crypto device type does not support "
436 "capabilities requested\n");
440 if (opts.test_file != NULL) {
441 t_vec = cperf_test_vector_get_from_file(&opts);
444 "Failed to create test vector for"
445 " specified file\n");
449 if (cperf_check_test_vector(&opts, t_vec)) {
450 RTE_LOG(ERR, USER1, "Incomplete necessary test vectors"
455 t_vec = cperf_test_vector_get_dummy(&opts);
458 "Failed to create test vector for"
459 " specified algorithms\n");
464 ret = cperf_get_op_functions(&opts, &op_fns);
466 RTE_LOG(ERR, USER1, "Failed to find function ops set for "
467 "specified algorithms combination\n");
472 show_test_vector(t_vec);
475 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
477 if (i == nb_cryptodevs)
480 cdev_id = enabled_cdevs[i];
482 uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);
484 ctx[cdev_id] = cperf_testmap[opts.test].constructor(
485 session_pool_socket[socket_id], cdev_id, 0,
486 &opts, t_vec, &op_fns);
487 if (ctx[cdev_id] == NULL) {
488 RTE_LOG(ERR, USER1, "Test run constructor failed\n");
494 /* Get first size from range or list */
495 if (opts.inc_buffer_size != 0)
496 opts.test_buffer_size = opts.min_buffer_size;
498 opts.test_buffer_size = opts.buffer_size_list[0];
500 while (opts.test_buffer_size <= opts.max_buffer_size) {
502 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
504 if (i == nb_cryptodevs)
507 cdev_id = enabled_cdevs[i];
509 rte_eal_remote_launch(cperf_testmap[opts.test].runner,
510 ctx[cdev_id], lcore_id);
514 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
516 if (i == nb_cryptodevs)
518 rte_eal_wait_lcore(lcore_id);
522 /* Get next size from range or list */
523 if (opts.inc_buffer_size != 0)
524 opts.test_buffer_size += opts.inc_buffer_size;
526 if (++buffer_size_idx == opts.buffer_size_count)
528 opts.test_buffer_size = opts.buffer_size_list[buffer_size_idx];
533 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
535 if (i == nb_cryptodevs)
538 cdev_id = enabled_cdevs[i];
540 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
544 free_test_vector(t_vec, &opts);
551 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
552 if (i == nb_cryptodevs)
555 cdev_id = enabled_cdevs[i];
557 if (ctx[cdev_id] && cperf_testmap[opts.test].destructor)
558 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
562 free_test_vector(t_vec, &opts);