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->buffer_sz)
184 if (test_vec->ciphertext.data == NULL)
186 if (test_vec->ciphertext.length != opts->buffer_sz)
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->buffer_sz)
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->buffer_sz)
220 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
221 if (test_vec->plaintext.data == NULL)
223 if (test_vec->plaintext.length != opts->buffer_sz)
225 if (test_vec->ciphertext.data == NULL)
227 if (test_vec->ciphertext.length != opts->buffer_sz)
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->buffer_sz)
253 if (test_vec->aad.data == NULL)
255 if (test_vec->aad.length != opts->auth_aad_sz)
257 if (test_vec->digest.data == NULL)
259 if (test_vec->digest.length != opts->auth_digest_sz)
266 main(int argc, char **argv)
268 struct cperf_options opts = {0};
269 struct cperf_test_vector *t_vec = NULL;
270 struct cperf_op_fns op_fns;
272 void *ctx[RTE_MAX_LCORE] = { };
274 int nb_cryptodevs = 0;
276 uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 };
281 /* Initialise DPDK EAL */
282 ret = rte_eal_init(argc, argv);
284 rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
288 cperf_options_default(&opts);
290 ret = cperf_options_parse(&opts, argc, argv);
292 RTE_LOG(ERR, USER1, "Parsing on or more user options failed\n");
296 ret = cperf_options_check(&opts);
299 "Checking on or more user options failed\n");
304 cperf_options_dump(&opts);
306 nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs);
307 if (nb_cryptodevs < 1) {
308 RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
314 ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
317 RTE_LOG(ERR, USER1, "Crypto device type does not support "
318 "capabilities requested\n");
322 if (opts.test_file != NULL) {
323 t_vec = cperf_test_vector_get_from_file(&opts);
326 "Failed to create test vector for"
327 " specified file\n");
331 if (cperf_check_test_vector(&opts, t_vec)) {
332 RTE_LOG(ERR, USER1, "Incomplete necessary test vectors"
337 t_vec = cperf_test_vector_get_dummy(&opts);
340 "Failed to create test vector for"
341 " specified algorithms\n");
346 ret = cperf_get_op_functions(&opts, &op_fns);
348 RTE_LOG(ERR, USER1, "Failed to find function ops set for "
349 "specified algorithms combination\n");
354 show_test_vector(t_vec);
357 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
359 if (i == nb_cryptodevs)
362 cdev_id = enabled_cdevs[i];
364 ctx[cdev_id] = cperf_testmap[opts.test].constructor(cdev_id, 0,
365 &opts, t_vec, &op_fns);
366 if (ctx[cdev_id] == NULL) {
367 RTE_LOG(ERR, USER1, "Test run constructor failed\n");
374 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
376 if (i == nb_cryptodevs)
379 cdev_id = enabled_cdevs[i];
381 rte_eal_remote_launch(cperf_testmap[opts.test].runner,
382 ctx[cdev_id], lcore_id);
386 rte_eal_mp_wait_lcore();
389 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
391 if (i == nb_cryptodevs)
394 cdev_id = enabled_cdevs[i];
396 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
400 free_test_vector(t_vec, &opts);
407 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
408 if (i == nb_cryptodevs)
411 cdev_id = enabled_cdevs[i];
413 if (ctx[cdev_id] && cperf_testmap[opts.test].destructor)
414 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
418 free_test_vector(t_vec, &opts);