5 #include <rte_cryptodev.h>
8 #include "cperf_options.h"
9 #include "cperf_test_vector_parsing.h"
10 #include "cperf_test_throughput.h"
11 #include "cperf_test_latency.h"
12 #include "cperf_test_verify.h"
14 const char *cperf_test_type_strs[] = {
15 [CPERF_TEST_TYPE_THROUGHPUT] = "throughput",
16 [CPERF_TEST_TYPE_LATENCY] = "latency",
17 [CPERF_TEST_TYPE_VERIFY] = "verify"
20 const char *cperf_op_type_strs[] = {
21 [CPERF_CIPHER_ONLY] = "cipher-only",
22 [CPERF_AUTH_ONLY] = "auth-only",
23 [CPERF_CIPHER_THEN_AUTH] = "cipher-then-auth",
24 [CPERF_AUTH_THEN_CIPHER] = "auth-then-cipher",
28 const struct cperf_test cperf_testmap[] = {
29 [CPERF_TEST_TYPE_THROUGHPUT] = {
30 cperf_throughput_test_constructor,
31 cperf_throughput_test_runner,
32 cperf_throughput_test_destructor
34 [CPERF_TEST_TYPE_LATENCY] = {
35 cperf_latency_test_constructor,
36 cperf_latency_test_runner,
37 cperf_latency_test_destructor
39 [CPERF_TEST_TYPE_VERIFY] = {
40 cperf_verify_test_constructor,
41 cperf_verify_test_runner,
42 cperf_verify_test_destructor
47 cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs)
49 uint8_t cdev_id, enabled_cdev_count = 0, nb_lcores;
52 enabled_cdev_count = rte_cryptodev_devices_get(opts->device_type,
53 enabled_cdevs, RTE_CRYPTO_MAX_DEVS);
54 if (enabled_cdev_count == 0) {
55 printf("No crypto devices type %s available\n",
60 nb_lcores = rte_lcore_count() - 1;
62 if (enabled_cdev_count > nb_lcores) {
63 printf("Number of capable crypto devices (%d) "
64 "has to be less or equal to number of slave "
65 "cores (%d)\n", enabled_cdev_count, nb_lcores);
69 for (cdev_id = 0; cdev_id < enabled_cdev_count &&
70 cdev_id < RTE_CRYPTO_MAX_DEVS; cdev_id++) {
72 struct rte_cryptodev_config conf = {
74 .socket_id = SOCKET_ID_ANY,
80 struct rte_cryptodev_qp_conf qp_conf = {
81 .nb_descriptors = 2048
84 ret = rte_cryptodev_configure(enabled_cdevs[cdev_id], &conf);
86 printf("Failed to configure cryptodev %u",
87 enabled_cdevs[cdev_id]);
91 ret = rte_cryptodev_queue_pair_setup(enabled_cdevs[cdev_id], 0,
92 &qp_conf, SOCKET_ID_ANY);
94 printf("Failed to setup queue pair %u on "
95 "cryptodev %u", 0, cdev_id);
99 ret = rte_cryptodev_start(enabled_cdevs[cdev_id]);
101 printf("Failed to start device %u: error %d\n",
102 enabled_cdevs[cdev_id], ret);
107 return enabled_cdev_count;
111 cperf_verify_devices_capabilities(struct cperf_options *opts,
112 uint8_t *enabled_cdevs, uint8_t nb_cryptodevs)
114 struct rte_cryptodev_sym_capability_idx cap_idx;
115 const struct rte_cryptodev_symmetric_capability *capability;
120 for (i = 0; i < nb_cryptodevs; i++) {
122 cdev_id = enabled_cdevs[i];
124 if (opts->op_type == CPERF_AUTH_ONLY ||
125 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
126 opts->op_type == CPERF_AUTH_THEN_CIPHER ||
127 opts->op_type == CPERF_AEAD) {
129 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
130 cap_idx.algo.auth = opts->auth_algo;
132 capability = rte_cryptodev_sym_capability_get(cdev_id,
134 if (capability == NULL)
137 ret = rte_cryptodev_sym_capability_check_auth(
140 opts->auth_digest_sz,
146 if (opts->op_type == CPERF_CIPHER_ONLY ||
147 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
148 opts->op_type == CPERF_AUTH_THEN_CIPHER ||
149 opts->op_type == CPERF_AEAD) {
151 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
152 cap_idx.algo.cipher = opts->cipher_algo;
154 capability = rte_cryptodev_sym_capability_get(cdev_id,
156 if (capability == NULL)
159 ret = rte_cryptodev_sym_capability_check_cipher(
172 cperf_check_test_vector(struct cperf_options *opts,
173 struct cperf_test_vector *test_vec)
175 if (opts->op_type == CPERF_CIPHER_ONLY) {
176 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
177 if (test_vec->plaintext.data == NULL)
179 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
180 if (test_vec->plaintext.data == NULL)
182 if (test_vec->plaintext.length < opts->max_buffer_size)
184 if (test_vec->ciphertext.data == NULL)
186 if (test_vec->ciphertext.length < opts->max_buffer_size)
188 if (test_vec->iv.data == NULL)
190 if (test_vec->iv.length != opts->cipher_iv_sz)
192 if (test_vec->cipher_key.data == NULL)
194 if (test_vec->cipher_key.length != opts->cipher_key_sz)
197 } else if (opts->op_type == CPERF_AUTH_ONLY) {
198 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
199 if (test_vec->plaintext.data == NULL)
201 if (test_vec->plaintext.length < opts->max_buffer_size)
203 if (test_vec->auth_key.data == NULL)
205 if (test_vec->auth_key.length != opts->auth_key_sz)
207 if (test_vec->digest.data == NULL)
209 if (test_vec->digest.length < opts->auth_digest_sz)
213 } else if (opts->op_type == CPERF_CIPHER_THEN_AUTH ||
214 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
215 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
216 if (test_vec->plaintext.data == NULL)
218 if (test_vec->plaintext.length < opts->max_buffer_size)
220 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
221 if (test_vec->plaintext.data == NULL)
223 if (test_vec->plaintext.length < opts->max_buffer_size)
225 if (test_vec->ciphertext.data == NULL)
227 if (test_vec->ciphertext.length < opts->max_buffer_size)
229 if (test_vec->iv.data == NULL)
231 if (test_vec->iv.length != opts->cipher_iv_sz)
233 if (test_vec->cipher_key.data == NULL)
235 if (test_vec->cipher_key.length != opts->cipher_key_sz)
238 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
239 if (test_vec->auth_key.data == NULL)
241 if (test_vec->auth_key.length != opts->auth_key_sz)
243 if (test_vec->digest.data == NULL)
245 if (test_vec->digest.length < opts->auth_digest_sz)
248 } else if (opts->op_type == CPERF_AEAD) {
249 if (test_vec->plaintext.data == NULL)
251 if (test_vec->plaintext.length < opts->max_buffer_size)
253 if (test_vec->ciphertext.data == NULL)
255 if (test_vec->ciphertext.length < opts->max_buffer_size)
257 if (test_vec->aad.data == NULL)
259 if (test_vec->aad.length != opts->auth_aad_sz)
261 if (test_vec->digest.data == NULL)
263 if (test_vec->digest.length < opts->auth_digest_sz)
270 main(int argc, char **argv)
272 struct cperf_options opts = {0};
273 struct cperf_test_vector *t_vec = NULL;
274 struct cperf_op_fns op_fns;
276 void *ctx[RTE_MAX_LCORE] = { };
278 int nb_cryptodevs = 0;
280 uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 };
282 uint8_t buffer_size_idx = 0;
287 /* Initialise DPDK EAL */
288 ret = rte_eal_init(argc, argv);
290 rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
294 cperf_options_default(&opts);
296 ret = cperf_options_parse(&opts, argc, argv);
298 RTE_LOG(ERR, USER1, "Parsing on or more user options failed\n");
302 ret = cperf_options_check(&opts);
305 "Checking on or more user options failed\n");
310 cperf_options_dump(&opts);
312 nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs);
313 if (nb_cryptodevs < 1) {
314 RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
320 ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
323 RTE_LOG(ERR, USER1, "Crypto device type does not support "
324 "capabilities requested\n");
328 if (opts.test_file != NULL) {
329 t_vec = cperf_test_vector_get_from_file(&opts);
332 "Failed to create test vector for"
333 " specified file\n");
337 if (cperf_check_test_vector(&opts, t_vec)) {
338 RTE_LOG(ERR, USER1, "Incomplete necessary test vectors"
343 t_vec = cperf_test_vector_get_dummy(&opts);
346 "Failed to create test vector for"
347 " specified algorithms\n");
352 ret = cperf_get_op_functions(&opts, &op_fns);
354 RTE_LOG(ERR, USER1, "Failed to find function ops set for "
355 "specified algorithms combination\n");
360 show_test_vector(t_vec);
363 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
365 if (i == nb_cryptodevs)
368 cdev_id = enabled_cdevs[i];
370 ctx[cdev_id] = cperf_testmap[opts.test].constructor(cdev_id, 0,
371 &opts, t_vec, &op_fns);
372 if (ctx[cdev_id] == NULL) {
373 RTE_LOG(ERR, USER1, "Test run constructor failed\n");
379 /* Get first size from range or list */
380 if (opts.inc_buffer_size != 0)
381 opts.test_buffer_size = opts.min_buffer_size;
383 opts.test_buffer_size = opts.buffer_size_list[0];
385 while (opts.test_buffer_size <= opts.max_buffer_size) {
387 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
389 if (i == nb_cryptodevs)
392 cdev_id = enabled_cdevs[i];
394 rte_eal_remote_launch(cperf_testmap[opts.test].runner,
395 ctx[cdev_id], lcore_id);
398 rte_eal_mp_wait_lcore();
400 /* Get next size from range or list */
401 if (opts.inc_buffer_size != 0)
402 opts.test_buffer_size += opts.inc_buffer_size;
404 if (++buffer_size_idx == opts.buffer_size_count)
406 opts.test_buffer_size = opts.buffer_size_list[buffer_size_idx];
411 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
413 if (i == nb_cryptodevs)
416 cdev_id = enabled_cdevs[i];
418 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
422 free_test_vector(t_vec, &opts);
429 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
430 if (i == nb_cryptodevs)
433 cdev_id = enabled_cdevs[i];
435 if (ctx[cdev_id] && cperf_testmap[opts.test].destructor)
436 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
440 free_test_vector(t_vec, &opts);