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 const char *cperf_test_type_strs[] = {
47 [CPERF_TEST_TYPE_THROUGHPUT] = "throughput",
48 [CPERF_TEST_TYPE_LATENCY] = "latency",
49 [CPERF_TEST_TYPE_VERIFY] = "verify"
52 const char *cperf_op_type_strs[] = {
53 [CPERF_CIPHER_ONLY] = "cipher-only",
54 [CPERF_AUTH_ONLY] = "auth-only",
55 [CPERF_CIPHER_THEN_AUTH] = "cipher-then-auth",
56 [CPERF_AUTH_THEN_CIPHER] = "auth-then-cipher",
60 const struct cperf_test cperf_testmap[] = {
61 [CPERF_TEST_TYPE_THROUGHPUT] = {
62 cperf_throughput_test_constructor,
63 cperf_throughput_test_runner,
64 cperf_throughput_test_destructor
66 [CPERF_TEST_TYPE_LATENCY] = {
67 cperf_latency_test_constructor,
68 cperf_latency_test_runner,
69 cperf_latency_test_destructor
71 [CPERF_TEST_TYPE_VERIFY] = {
72 cperf_verify_test_constructor,
73 cperf_verify_test_runner,
74 cperf_verify_test_destructor
79 cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs)
81 uint8_t cdev_id, enabled_cdev_count = 0, nb_lcores;
84 enabled_cdev_count = rte_cryptodev_devices_get(opts->device_type,
85 enabled_cdevs, RTE_CRYPTO_MAX_DEVS);
86 if (enabled_cdev_count == 0) {
87 printf("No crypto devices type %s available\n",
92 nb_lcores = rte_lcore_count() - 1;
94 if (enabled_cdev_count > nb_lcores) {
95 printf("Number of capable crypto devices (%d) "
96 "has to be less or equal to number of slave "
97 "cores (%d)\n", enabled_cdev_count, nb_lcores);
101 for (cdev_id = 0; cdev_id < enabled_cdev_count &&
102 cdev_id < RTE_CRYPTO_MAX_DEVS; cdev_id++) {
104 struct rte_cryptodev_config conf = {
106 .socket_id = SOCKET_ID_ANY,
112 struct rte_cryptodev_qp_conf qp_conf = {
113 .nb_descriptors = 2048
116 ret = rte_cryptodev_configure(enabled_cdevs[cdev_id], &conf);
118 printf("Failed to configure cryptodev %u",
119 enabled_cdevs[cdev_id]);
123 ret = rte_cryptodev_queue_pair_setup(enabled_cdevs[cdev_id], 0,
124 &qp_conf, SOCKET_ID_ANY);
126 printf("Failed to setup queue pair %u on "
127 "cryptodev %u", 0, cdev_id);
131 ret = rte_cryptodev_start(enabled_cdevs[cdev_id]);
133 printf("Failed to start device %u: error %d\n",
134 enabled_cdevs[cdev_id], ret);
139 return enabled_cdev_count;
143 cperf_verify_devices_capabilities(struct cperf_options *opts,
144 uint8_t *enabled_cdevs, uint8_t nb_cryptodevs)
146 struct rte_cryptodev_sym_capability_idx cap_idx;
147 const struct rte_cryptodev_symmetric_capability *capability;
152 for (i = 0; i < nb_cryptodevs; i++) {
154 cdev_id = enabled_cdevs[i];
156 if (opts->op_type == CPERF_AUTH_ONLY ||
157 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
158 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
160 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
161 cap_idx.algo.auth = opts->auth_algo;
163 capability = rte_cryptodev_sym_capability_get(cdev_id,
165 if (capability == NULL)
168 ret = rte_cryptodev_sym_capability_check_auth(
178 if (opts->op_type == CPERF_CIPHER_ONLY ||
179 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
180 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
182 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
183 cap_idx.algo.cipher = opts->cipher_algo;
185 capability = rte_cryptodev_sym_capability_get(cdev_id,
187 if (capability == NULL)
190 ret = rte_cryptodev_sym_capability_check_cipher(
198 if (opts->op_type == CPERF_AEAD) {
200 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
201 cap_idx.algo.aead = opts->aead_algo;
203 capability = rte_cryptodev_sym_capability_get(cdev_id,
205 if (capability == NULL)
208 ret = rte_cryptodev_sym_capability_check_aead(
223 cperf_check_test_vector(struct cperf_options *opts,
224 struct cperf_test_vector *test_vec)
226 if (opts->op_type == CPERF_CIPHER_ONLY) {
227 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
228 if (test_vec->plaintext.data == NULL)
230 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
231 if (test_vec->plaintext.data == NULL)
233 if (test_vec->plaintext.length < opts->max_buffer_size)
235 if (test_vec->ciphertext.data == NULL)
237 if (test_vec->ciphertext.length < opts->max_buffer_size)
239 if (test_vec->cipher_iv.data == NULL)
241 if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
243 if (test_vec->cipher_key.data == NULL)
245 if (test_vec->cipher_key.length != opts->cipher_key_sz)
248 } else if (opts->op_type == CPERF_AUTH_ONLY) {
249 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
250 if (test_vec->plaintext.data == NULL)
252 if (test_vec->plaintext.length < opts->max_buffer_size)
254 if (test_vec->auth_key.data == NULL)
256 if (test_vec->auth_key.length != opts->auth_key_sz)
258 if (test_vec->auth_iv.length != opts->auth_iv_sz)
260 /* Auth IV is only required for some algorithms */
261 if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
263 if (test_vec->digest.data == NULL)
265 if (test_vec->digest.length < opts->digest_sz)
269 } else if (opts->op_type == CPERF_CIPHER_THEN_AUTH ||
270 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
271 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
272 if (test_vec->plaintext.data == NULL)
274 if (test_vec->plaintext.length < opts->max_buffer_size)
276 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
277 if (test_vec->plaintext.data == NULL)
279 if (test_vec->plaintext.length < opts->max_buffer_size)
281 if (test_vec->ciphertext.data == NULL)
283 if (test_vec->ciphertext.length < opts->max_buffer_size)
285 if (test_vec->cipher_iv.data == NULL)
287 if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
289 if (test_vec->cipher_key.data == NULL)
291 if (test_vec->cipher_key.length != opts->cipher_key_sz)
294 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
295 if (test_vec->auth_key.data == NULL)
297 if (test_vec->auth_key.length != opts->auth_key_sz)
299 if (test_vec->auth_iv.length != opts->auth_iv_sz)
301 /* Auth IV is only required for some algorithms */
302 if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
304 if (test_vec->digest.data == NULL)
306 if (test_vec->digest.length < opts->digest_sz)
309 } else if (opts->op_type == CPERF_AEAD) {
310 if (test_vec->plaintext.data == NULL)
312 if (test_vec->plaintext.length < opts->max_buffer_size)
314 if (test_vec->ciphertext.data == NULL)
316 if (test_vec->ciphertext.length < opts->max_buffer_size)
318 if (test_vec->aead_iv.data == NULL)
320 if (test_vec->aead_iv.length != opts->aead_iv_sz)
322 if (test_vec->aad.data == NULL)
324 if (test_vec->aad.length != opts->aead_aad_sz)
326 if (test_vec->digest.data == NULL)
328 if (test_vec->digest.length < opts->digest_sz)
335 main(int argc, char **argv)
337 struct cperf_options opts = {0};
338 struct cperf_test_vector *t_vec = NULL;
339 struct cperf_op_fns op_fns;
341 void *ctx[RTE_MAX_LCORE] = { };
343 int nb_cryptodevs = 0;
345 uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 };
347 uint8_t buffer_size_idx = 0;
352 /* Initialise DPDK EAL */
353 ret = rte_eal_init(argc, argv);
355 rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
359 cperf_options_default(&opts);
361 ret = cperf_options_parse(&opts, argc, argv);
363 RTE_LOG(ERR, USER1, "Parsing on or more user options failed\n");
367 ret = cperf_options_check(&opts);
370 "Checking on or more user options failed\n");
375 cperf_options_dump(&opts);
377 nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs);
378 if (nb_cryptodevs < 1) {
379 RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
385 ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
388 RTE_LOG(ERR, USER1, "Crypto device type does not support "
389 "capabilities requested\n");
393 if (opts.test_file != NULL) {
394 t_vec = cperf_test_vector_get_from_file(&opts);
397 "Failed to create test vector for"
398 " specified file\n");
402 if (cperf_check_test_vector(&opts, t_vec)) {
403 RTE_LOG(ERR, USER1, "Incomplete necessary test vectors"
408 t_vec = cperf_test_vector_get_dummy(&opts);
411 "Failed to create test vector for"
412 " specified algorithms\n");
417 ret = cperf_get_op_functions(&opts, &op_fns);
419 RTE_LOG(ERR, USER1, "Failed to find function ops set for "
420 "specified algorithms combination\n");
425 show_test_vector(t_vec);
428 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
430 if (i == nb_cryptodevs)
433 cdev_id = enabled_cdevs[i];
435 ctx[cdev_id] = cperf_testmap[opts.test].constructor(cdev_id, 0,
436 &opts, t_vec, &op_fns);
437 if (ctx[cdev_id] == NULL) {
438 RTE_LOG(ERR, USER1, "Test run constructor failed\n");
444 /* Get first size from range or list */
445 if (opts.inc_buffer_size != 0)
446 opts.test_buffer_size = opts.min_buffer_size;
448 opts.test_buffer_size = opts.buffer_size_list[0];
450 while (opts.test_buffer_size <= opts.max_buffer_size) {
452 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
454 if (i == nb_cryptodevs)
457 cdev_id = enabled_cdevs[i];
459 rte_eal_remote_launch(cperf_testmap[opts.test].runner,
460 ctx[cdev_id], lcore_id);
463 rte_eal_mp_wait_lcore();
465 /* Get next size from range or list */
466 if (opts.inc_buffer_size != 0)
467 opts.test_buffer_size += opts.inc_buffer_size;
469 if (++buffer_size_idx == opts.buffer_size_count)
471 opts.test_buffer_size = opts.buffer_size_list[buffer_size_idx];
476 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
478 if (i == nb_cryptodevs)
481 cdev_id = enabled_cdevs[i];
483 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
487 free_test_vector(t_vec, &opts);
494 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
495 if (i == nb_cryptodevs)
498 cdev_id = enabled_cdevs[i];
500 if (ctx[cdev_id] && cperf_testmap[opts.test].destructor)
501 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
505 free_test_vector(t_vec, &opts);