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"
13 const char *cperf_test_type_strs[] = {
14 [CPERF_TEST_TYPE_THROUGHPUT] = "throughput",
15 [CPERF_TEST_TYPE_CYCLECOUNT] = "cycle-count",
16 [CPERF_TEST_TYPE_LATENCY] = "latency"
19 const char *cperf_op_type_strs[] = {
20 [CPERF_CIPHER_ONLY] = "cipher-only",
21 [CPERF_AUTH_ONLY] = "auth-only",
22 [CPERF_CIPHER_THEN_AUTH] = "cipher-then-auth",
23 [CPERF_AUTH_THEN_CIPHER] = "auth-then-cipher",
27 const struct cperf_test cperf_testmap[] = {
28 [CPERF_TEST_TYPE_THROUGHPUT] = {
29 cperf_throughput_test_constructor,
30 cperf_throughput_test_runner,
31 cperf_throughput_test_destructor
33 [CPERF_TEST_TYPE_CYCLECOUNT] = { NULL },
34 [CPERF_TEST_TYPE_LATENCY] = {
35 cperf_latency_test_constructor,
36 cperf_latency_test_runner,
37 cperf_latency_test_destructor
42 cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs)
44 uint8_t cdev_id, enabled_cdev_count = 0, nb_lcores;
47 enabled_cdev_count = rte_cryptodev_devices_get(opts->device_type,
48 enabled_cdevs, RTE_DIM(enabled_cdevs));
49 if (enabled_cdev_count == 0) {
50 printf("No crypto devices type %s available\n",
55 nb_lcores = rte_lcore_count() - 1;
57 if (enabled_cdev_count > nb_lcores) {
58 printf("Number of capable crypto devices (%d) "
59 "has to be less or equal to number of slave "
60 "cores (%d)\n", enabled_cdev_count, nb_lcores);
64 for (cdev_id = 0; cdev_id < enabled_cdev_count &&
65 cdev_id < RTE_CRYPTO_MAX_DEVS; cdev_id++) {
67 struct rte_cryptodev_config conf = {
69 .socket_id = SOCKET_ID_ANY,
75 struct rte_cryptodev_qp_conf qp_conf = {
76 .nb_descriptors = 2048
79 ret = rte_cryptodev_configure(enabled_cdevs[cdev_id], &conf);
81 printf("Failed to configure cryptodev %u",
82 enabled_cdevs[cdev_id]);
86 ret = rte_cryptodev_queue_pair_setup(enabled_cdevs[cdev_id], 0,
87 &qp_conf, SOCKET_ID_ANY);
89 printf("Failed to setup queue pair %u on "
90 "cryptodev %u", 0, cdev_id);
94 ret = rte_cryptodev_start(enabled_cdevs[cdev_id]);
96 printf("Failed to start device %u: error %d\n",
97 enabled_cdevs[cdev_id], ret);
102 return enabled_cdev_count;
106 cperf_verify_devices_capabilities(struct cperf_options *opts,
107 uint8_t *enabled_cdevs, uint8_t nb_cryptodevs)
109 struct rte_cryptodev_sym_capability_idx cap_idx;
110 const struct rte_cryptodev_symmetric_capability *capability;
115 for (i = 0; i < nb_cryptodevs; i++) {
117 cdev_id = enabled_cdevs[i];
119 if (opts->op_type == CPERF_AUTH_ONLY ||
120 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
121 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
123 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
124 cap_idx.algo.auth = opts->auth_algo;
126 capability = rte_cryptodev_sym_capability_get(cdev_id,
128 if (capability == NULL)
131 ret = rte_cryptodev_sym_capability_check_auth(
134 opts->auth_digest_sz,
140 if (opts->op_type == CPERF_CIPHER_ONLY ||
141 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
142 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
144 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
145 cap_idx.algo.cipher = opts->cipher_algo;
147 capability = rte_cryptodev_sym_capability_get(cdev_id,
149 if (capability == NULL)
152 ret = rte_cryptodev_sym_capability_check_cipher(
165 cperf_check_test_vector(struct cperf_options opts,
166 struct cperf_test_vector test_vec)
168 if (opts.op_type == CPERF_CIPHER_ONLY) {
169 if (opts.cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
170 if (test_vec.plaintext.data == NULL)
172 } else if (opts.cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
173 if (test_vec.plaintext.data == NULL)
175 if (test_vec.plaintext.length != opts.buffer_sz)
177 if (test_vec.ciphertext.data == NULL)
179 if (test_vec.ciphertext.length != opts.buffer_sz)
181 if (test_vec.iv.data == NULL)
183 if (test_vec.iv.length != opts.cipher_iv_sz)
185 if (test_vec.cipher_key.data == NULL)
187 if (test_vec.cipher_key.length != opts.cipher_key_sz)
190 } else if (opts.op_type == CPERF_AUTH_ONLY) {
191 if (opts.auth_algo != RTE_CRYPTO_AUTH_NULL) {
192 if (test_vec.plaintext.data == NULL)
194 if (test_vec.plaintext.length != opts.buffer_sz)
196 if (test_vec.auth_key.data == NULL)
198 if (test_vec.auth_key.length != opts.auth_key_sz)
200 if (test_vec.digest.data == NULL)
202 if (test_vec.digest.length != opts.auth_digest_sz)
206 } else if (opts.op_type == CPERF_CIPHER_THEN_AUTH ||
207 opts.op_type == CPERF_AUTH_THEN_CIPHER) {
208 if (opts.cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
209 if (test_vec.plaintext.data == NULL)
211 if (test_vec.plaintext.length != opts.buffer_sz)
213 } else if (opts.cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
214 if (test_vec.plaintext.data == NULL)
216 if (test_vec.plaintext.length != opts.buffer_sz)
218 if (test_vec.ciphertext.data == NULL)
220 if (test_vec.ciphertext.length != opts.buffer_sz)
222 if (test_vec.iv.data == NULL)
224 if (test_vec.iv.length != opts.cipher_iv_sz)
226 if (test_vec.cipher_key.data == NULL)
228 if (test_vec.cipher_key.length != opts.cipher_key_sz)
231 if (opts.auth_algo != RTE_CRYPTO_AUTH_NULL) {
232 if (test_vec.auth_key.data == NULL)
234 if (test_vec.auth_key.length != opts.auth_key_sz)
236 if (test_vec.digest.data == NULL)
238 if (test_vec.digest.length != opts.auth_digest_sz)
241 } else if (opts.op_type == CPERF_AEAD) {
242 if (test_vec.plaintext.data == NULL)
244 if (test_vec.plaintext.length != opts.buffer_sz)
246 if (test_vec.aad.data == NULL)
248 if (test_vec.aad.length != opts.auth_aad_sz)
250 if (test_vec.digest.data == NULL)
252 if (test_vec.digest.length != opts.auth_digest_sz)
259 main(int argc, char **argv)
261 struct cperf_options opts = {0};
262 struct cperf_test_vector *t_vec = NULL;
263 struct cperf_op_fns op_fns;
265 void *ctx[RTE_MAX_LCORE] = { };
269 uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 };
274 /* Initialise DPDK EAL */
275 ret = rte_eal_init(argc, argv);
277 rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
281 cperf_options_default(&opts);
283 ret = cperf_options_parse(&opts, argc, argv);
285 RTE_LOG(ERR, USER1, "Parsing on or more user options failed\n");
289 ret = cperf_options_check(&opts);
292 "Checking on or more user options failed\n");
297 cperf_options_dump(&opts);
299 nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs);
300 if (nb_cryptodevs < 1) {
301 RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
306 ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
309 RTE_LOG(ERR, USER1, "Crypto device type does not support "
310 "capabilities requested\n");
314 if (opts.test_file != NULL) {
315 t_vec = cperf_test_vector_get_from_file(&opts);
318 "Failed to create test vector for"
319 " specified file\n");
323 if (cperf_check_test_vector(opts, *t_vec)) {
324 RTE_LOG(ERR, USER1, "Incomplete necessary test vectors"
329 t_vec = cperf_test_vector_get_dummy(&opts);
332 "Failed to create test vector for"
333 " specified algorithms\n");
338 ret = cperf_get_op_functions(&opts, &op_fns);
340 RTE_LOG(ERR, USER1, "Failed to find function ops set for "
341 "specified algorithms combination\n");
346 show_test_vector(t_vec);
349 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
351 if (i == nb_cryptodevs)
354 cdev_id = enabled_cdevs[i];
356 ctx[cdev_id] = cperf_testmap[opts.test].constructor(cdev_id, 0,
357 &opts, t_vec, &op_fns);
358 if (ctx[cdev_id] == NULL) {
359 RTE_LOG(ERR, USER1, "Test run constructor failed\n");
366 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
368 if (i == nb_cryptodevs)
371 cdev_id = enabled_cdevs[i];
373 rte_eal_remote_launch(cperf_testmap[opts.test].runner,
374 ctx[cdev_id], lcore_id);
378 rte_eal_mp_wait_lcore();
381 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
383 if (i == nb_cryptodevs)
386 cdev_id = enabled_cdevs[i];
388 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
392 free_test_vector(t_vec, &opts);
399 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
401 if (i == nb_cryptodevs)
404 cdev_id = enabled_cdevs[i];
406 if (ctx[cdev_id] && cperf_testmap[opts.test].destructor)
407 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
411 free_test_vector(t_vec, &opts);