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"
46 #define NUM_SESSIONS 2048
47 #define SESS_MEMPOOL_CACHE_SIZE 64
49 const char *cperf_test_type_strs[] = {
50 [CPERF_TEST_TYPE_THROUGHPUT] = "throughput",
51 [CPERF_TEST_TYPE_LATENCY] = "latency",
52 [CPERF_TEST_TYPE_VERIFY] = "verify"
55 const char *cperf_op_type_strs[] = {
56 [CPERF_CIPHER_ONLY] = "cipher-only",
57 [CPERF_AUTH_ONLY] = "auth-only",
58 [CPERF_CIPHER_THEN_AUTH] = "cipher-then-auth",
59 [CPERF_AUTH_THEN_CIPHER] = "auth-then-cipher",
63 const struct cperf_test cperf_testmap[] = {
64 [CPERF_TEST_TYPE_THROUGHPUT] = {
65 cperf_throughput_test_constructor,
66 cperf_throughput_test_runner,
67 cperf_throughput_test_destructor
69 [CPERF_TEST_TYPE_LATENCY] = {
70 cperf_latency_test_constructor,
71 cperf_latency_test_runner,
72 cperf_latency_test_destructor
74 [CPERF_TEST_TYPE_VERIFY] = {
75 cperf_verify_test_constructor,
76 cperf_verify_test_runner,
77 cperf_verify_test_destructor
82 cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs,
83 struct rte_mempool *session_pool_socket[])
85 uint8_t enabled_cdev_count = 0, nb_lcores, cdev_id;
89 enabled_cdev_count = rte_cryptodev_devices_get(opts->device_type,
90 enabled_cdevs, RTE_CRYPTO_MAX_DEVS);
91 if (enabled_cdev_count == 0) {
92 printf("No crypto devices type %s available\n",
97 nb_lcores = rte_lcore_count() - 1;
99 if (enabled_cdev_count > nb_lcores) {
100 printf("Number of capable crypto devices (%d) "
101 "has to be less or equal to number of slave "
102 "cores (%d)\n", enabled_cdev_count, nb_lcores);
106 /* Create a mempool shared by all the devices */
107 uint32_t max_sess_size = 0, sess_size;
109 for (cdev_id = 0; cdev_id < rte_cryptodev_count(); cdev_id++) {
110 sess_size = rte_cryptodev_get_private_session_size(cdev_id);
111 if (sess_size > max_sess_size)
112 max_sess_size = sess_size;
115 for (i = 0; i < enabled_cdev_count &&
116 i < RTE_CRYPTO_MAX_DEVS; i++) {
117 cdev_id = enabled_cdevs[i];
118 uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);
120 struct rte_cryptodev_config conf = {
122 .socket_id = socket_id
125 struct rte_cryptodev_qp_conf qp_conf = {
126 .nb_descriptors = 2048
130 if (session_pool_socket[socket_id] == NULL) {
131 char mp_name[RTE_MEMPOOL_NAMESIZE];
132 struct rte_mempool *sess_mp;
134 snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
135 "sess_mp_%u", socket_id);
137 sess_mp = rte_mempool_create(mp_name,
140 SESS_MEMPOOL_CACHE_SIZE,
145 if (sess_mp == NULL) {
146 printf("Cannot create session pool on socket %d\n",
151 printf("Allocated session pool on socket %d\n", socket_id);
152 session_pool_socket[socket_id] = sess_mp;
155 ret = rte_cryptodev_configure(cdev_id, &conf);
157 printf("Failed to configure cryptodev %u", cdev_id);
161 ret = rte_cryptodev_queue_pair_setup(cdev_id, 0,
163 session_pool_socket[socket_id]);
165 printf("Failed to setup queue pair %u on "
166 "cryptodev %u", 0, cdev_id);
170 ret = rte_cryptodev_start(cdev_id);
172 printf("Failed to start device %u: error %d\n",
178 return enabled_cdev_count;
182 cperf_verify_devices_capabilities(struct cperf_options *opts,
183 uint8_t *enabled_cdevs, uint8_t nb_cryptodevs)
185 struct rte_cryptodev_sym_capability_idx cap_idx;
186 const struct rte_cryptodev_symmetric_capability *capability;
191 for (i = 0; i < nb_cryptodevs; i++) {
193 cdev_id = enabled_cdevs[i];
195 if (opts->op_type == CPERF_AUTH_ONLY ||
196 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
197 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
199 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
200 cap_idx.algo.auth = opts->auth_algo;
202 capability = rte_cryptodev_sym_capability_get(cdev_id,
204 if (capability == NULL)
207 ret = rte_cryptodev_sym_capability_check_auth(
217 if (opts->op_type == CPERF_CIPHER_ONLY ||
218 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
219 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
221 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
222 cap_idx.algo.cipher = opts->cipher_algo;
224 capability = rte_cryptodev_sym_capability_get(cdev_id,
226 if (capability == NULL)
229 ret = rte_cryptodev_sym_capability_check_cipher(
237 if (opts->op_type == CPERF_AEAD) {
239 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
240 cap_idx.algo.aead = opts->aead_algo;
242 capability = rte_cryptodev_sym_capability_get(cdev_id,
244 if (capability == NULL)
247 ret = rte_cryptodev_sym_capability_check_aead(
262 cperf_check_test_vector(struct cperf_options *opts,
263 struct cperf_test_vector *test_vec)
265 if (opts->op_type == CPERF_CIPHER_ONLY) {
266 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
267 if (test_vec->plaintext.data == NULL)
269 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
270 if (test_vec->plaintext.data == NULL)
272 if (test_vec->plaintext.length < opts->max_buffer_size)
274 if (test_vec->ciphertext.data == NULL)
276 if (test_vec->ciphertext.length < opts->max_buffer_size)
278 if (test_vec->cipher_iv.data == NULL)
280 if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
282 if (test_vec->cipher_key.data == NULL)
284 if (test_vec->cipher_key.length != opts->cipher_key_sz)
287 } else if (opts->op_type == CPERF_AUTH_ONLY) {
288 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
289 if (test_vec->plaintext.data == NULL)
291 if (test_vec->plaintext.length < opts->max_buffer_size)
293 if (test_vec->auth_key.data == NULL)
295 if (test_vec->auth_key.length != opts->auth_key_sz)
297 if (test_vec->auth_iv.length != opts->auth_iv_sz)
299 /* Auth IV is only required for some algorithms */
300 if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
302 if (test_vec->digest.data == NULL)
304 if (test_vec->digest.length < opts->digest_sz)
308 } else if (opts->op_type == CPERF_CIPHER_THEN_AUTH ||
309 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
310 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
311 if (test_vec->plaintext.data == NULL)
313 if (test_vec->plaintext.length < opts->max_buffer_size)
315 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
316 if (test_vec->plaintext.data == NULL)
318 if (test_vec->plaintext.length < opts->max_buffer_size)
320 if (test_vec->ciphertext.data == NULL)
322 if (test_vec->ciphertext.length < opts->max_buffer_size)
324 if (test_vec->cipher_iv.data == NULL)
326 if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
328 if (test_vec->cipher_key.data == NULL)
330 if (test_vec->cipher_key.length != opts->cipher_key_sz)
333 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
334 if (test_vec->auth_key.data == NULL)
336 if (test_vec->auth_key.length != opts->auth_key_sz)
338 if (test_vec->auth_iv.length != opts->auth_iv_sz)
340 /* Auth IV is only required for some algorithms */
341 if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
343 if (test_vec->digest.data == NULL)
345 if (test_vec->digest.length < opts->digest_sz)
348 } else if (opts->op_type == CPERF_AEAD) {
349 if (test_vec->plaintext.data == NULL)
351 if (test_vec->plaintext.length < opts->max_buffer_size)
353 if (test_vec->ciphertext.data == NULL)
355 if (test_vec->ciphertext.length < opts->max_buffer_size)
357 if (test_vec->aead_iv.data == NULL)
359 if (test_vec->aead_iv.length != opts->aead_iv_sz)
361 if (test_vec->aad.data == NULL)
363 if (test_vec->aad.length != opts->aead_aad_sz)
365 if (test_vec->digest.data == NULL)
367 if (test_vec->digest.length < opts->digest_sz)
374 main(int argc, char **argv)
376 struct cperf_options opts = {0};
377 struct cperf_test_vector *t_vec = NULL;
378 struct cperf_op_fns op_fns;
380 void *ctx[RTE_MAX_LCORE] = { };
381 struct rte_mempool *session_pool_socket[RTE_MAX_NUMA_NODES] = { 0 };
383 int nb_cryptodevs = 0;
385 uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 };
387 uint8_t buffer_size_idx = 0;
392 /* Initialise DPDK EAL */
393 ret = rte_eal_init(argc, argv);
395 rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
399 cperf_options_default(&opts);
401 ret = cperf_options_parse(&opts, argc, argv);
403 RTE_LOG(ERR, USER1, "Parsing on or more user options failed\n");
407 ret = cperf_options_check(&opts);
410 "Checking on or more user options failed\n");
415 cperf_options_dump(&opts);
417 nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs,
418 session_pool_socket);
419 if (nb_cryptodevs < 1) {
420 RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
426 ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
429 RTE_LOG(ERR, USER1, "Crypto device type does not support "
430 "capabilities requested\n");
434 if (opts.test_file != NULL) {
435 t_vec = cperf_test_vector_get_from_file(&opts);
438 "Failed to create test vector for"
439 " specified file\n");
443 if (cperf_check_test_vector(&opts, t_vec)) {
444 RTE_LOG(ERR, USER1, "Incomplete necessary test vectors"
449 t_vec = cperf_test_vector_get_dummy(&opts);
452 "Failed to create test vector for"
453 " specified algorithms\n");
458 ret = cperf_get_op_functions(&opts, &op_fns);
460 RTE_LOG(ERR, USER1, "Failed to find function ops set for "
461 "specified algorithms combination\n");
466 show_test_vector(t_vec);
469 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
471 if (i == nb_cryptodevs)
474 cdev_id = enabled_cdevs[i];
476 uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);
478 ctx[cdev_id] = cperf_testmap[opts.test].constructor(
479 session_pool_socket[socket_id], cdev_id, 0,
480 &opts, t_vec, &op_fns);
481 if (ctx[cdev_id] == NULL) {
482 RTE_LOG(ERR, USER1, "Test run constructor failed\n");
488 /* Get first size from range or list */
489 if (opts.inc_buffer_size != 0)
490 opts.test_buffer_size = opts.min_buffer_size;
492 opts.test_buffer_size = opts.buffer_size_list[0];
494 while (opts.test_buffer_size <= opts.max_buffer_size) {
496 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
498 if (i == nb_cryptodevs)
501 cdev_id = enabled_cdevs[i];
503 rte_eal_remote_launch(cperf_testmap[opts.test].runner,
504 ctx[cdev_id], lcore_id);
507 rte_eal_mp_wait_lcore();
509 /* Get next size from range or list */
510 if (opts.inc_buffer_size != 0)
511 opts.test_buffer_size += opts.inc_buffer_size;
513 if (++buffer_size_idx == opts.buffer_size_count)
515 opts.test_buffer_size = opts.buffer_size_list[buffer_size_idx];
520 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
522 if (i == nb_cryptodevs)
525 cdev_id = enabled_cdevs[i];
527 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
531 free_test_vector(t_vec, &opts);
538 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
539 if (i == nb_cryptodevs)
542 cdev_id = enabled_cdevs[i];
544 if (ctx[cdev_id] && cperf_testmap[opts.test].destructor)
545 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
549 free_test_vector(t_vec, &opts);