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_CRYPTO_MAX_DEVS);
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 ||
122 opts->op_type == CPERF_AEAD) {
124 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
125 cap_idx.algo.auth = opts->auth_algo;
127 capability = rte_cryptodev_sym_capability_get(cdev_id,
129 if (capability == NULL)
132 ret = rte_cryptodev_sym_capability_check_auth(
135 opts->auth_digest_sz,
141 if (opts->op_type == CPERF_CIPHER_ONLY ||
142 opts->op_type == CPERF_CIPHER_THEN_AUTH ||
143 opts->op_type == CPERF_AUTH_THEN_CIPHER ||
144 opts->op_type == CPERF_AEAD) {
146 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
147 cap_idx.algo.cipher = opts->cipher_algo;
149 capability = rte_cryptodev_sym_capability_get(cdev_id,
151 if (capability == NULL)
154 ret = rte_cryptodev_sym_capability_check_cipher(
167 cperf_check_test_vector(struct cperf_options *opts,
168 struct cperf_test_vector *test_vec)
170 if (opts->op_type == CPERF_CIPHER_ONLY) {
171 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
172 if (test_vec->plaintext.data == NULL)
174 } else if (opts->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
175 if (test_vec->plaintext.data == NULL)
177 if (test_vec->plaintext.length != opts->buffer_sz)
179 if (test_vec->ciphertext.data == NULL)
181 if (test_vec->ciphertext.length != opts->buffer_sz)
183 if (test_vec->iv.data == NULL)
185 if (test_vec->iv.length != opts->cipher_iv_sz)
187 if (test_vec->cipher_key.data == NULL)
189 if (test_vec->cipher_key.length != opts->cipher_key_sz)
192 } else if (opts->op_type == CPERF_AUTH_ONLY) {
193 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
194 if (test_vec->plaintext.data == NULL)
196 if (test_vec->plaintext.length != opts->buffer_sz)
198 if (test_vec->auth_key.data == NULL)
200 if (test_vec->auth_key.length != opts->auth_key_sz)
202 if (test_vec->digest.data == NULL)
204 if (test_vec->digest.length != opts->auth_digest_sz)
208 } else if (opts->op_type == CPERF_CIPHER_THEN_AUTH ||
209 opts->op_type == CPERF_AUTH_THEN_CIPHER) {
210 if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
211 if (test_vec->plaintext.data == NULL)
213 if (test_vec->plaintext.length != opts->buffer_sz)
215 } else 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 if (test_vec->ciphertext.data == NULL)
222 if (test_vec->ciphertext.length != opts->buffer_sz)
224 if (test_vec->iv.data == NULL)
226 if (test_vec->iv.length != opts->cipher_iv_sz)
228 if (test_vec->cipher_key.data == NULL)
230 if (test_vec->cipher_key.length != opts->cipher_key_sz)
233 if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
234 if (test_vec->auth_key.data == NULL)
236 if (test_vec->auth_key.length != opts->auth_key_sz)
238 if (test_vec->digest.data == NULL)
240 if (test_vec->digest.length != opts->auth_digest_sz)
243 } else if (opts->op_type == CPERF_AEAD) {
244 if (test_vec->plaintext.data == NULL)
246 if (test_vec->plaintext.length != opts->buffer_sz)
248 if (test_vec->aad.data == NULL)
250 if (test_vec->aad.length != opts->auth_aad_sz)
252 if (test_vec->digest.data == NULL)
254 if (test_vec->digest.length != opts->auth_digest_sz)
261 main(int argc, char **argv)
263 struct cperf_options opts = {0};
264 struct cperf_test_vector *t_vec = NULL;
265 struct cperf_op_fns op_fns;
267 void *ctx[RTE_MAX_LCORE] = { };
269 int nb_cryptodevs = 0;
271 uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 };
276 /* Initialise DPDK EAL */
277 ret = rte_eal_init(argc, argv);
279 rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
283 cperf_options_default(&opts);
285 ret = cperf_options_parse(&opts, argc, argv);
287 RTE_LOG(ERR, USER1, "Parsing on or more user options failed\n");
291 ret = cperf_options_check(&opts);
294 "Checking on or more user options failed\n");
299 cperf_options_dump(&opts);
301 nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs);
302 if (nb_cryptodevs < 1) {
303 RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
309 ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
312 RTE_LOG(ERR, USER1, "Crypto device type does not support "
313 "capabilities requested\n");
317 if (opts.test_file != NULL) {
318 t_vec = cperf_test_vector_get_from_file(&opts);
321 "Failed to create test vector for"
322 " specified file\n");
326 if (cperf_check_test_vector(&opts, t_vec)) {
327 RTE_LOG(ERR, USER1, "Incomplete necessary test vectors"
332 t_vec = cperf_test_vector_get_dummy(&opts);
335 "Failed to create test vector for"
336 " specified algorithms\n");
341 ret = cperf_get_op_functions(&opts, &op_fns);
343 RTE_LOG(ERR, USER1, "Failed to find function ops set for "
344 "specified algorithms combination\n");
349 show_test_vector(t_vec);
352 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
354 if (i == nb_cryptodevs)
357 cdev_id = enabled_cdevs[i];
359 ctx[cdev_id] = cperf_testmap[opts.test].constructor(cdev_id, 0,
360 &opts, t_vec, &op_fns);
361 if (ctx[cdev_id] == NULL) {
362 RTE_LOG(ERR, USER1, "Test run constructor failed\n");
369 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
371 if (i == nb_cryptodevs)
374 cdev_id = enabled_cdevs[i];
376 rte_eal_remote_launch(cperf_testmap[opts.test].runner,
377 ctx[cdev_id], lcore_id);
381 rte_eal_mp_wait_lcore();
384 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
386 if (i == nb_cryptodevs)
389 cdev_id = enabled_cdevs[i];
391 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
395 free_test_vector(t_vec, &opts);
402 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
403 if (i == nb_cryptodevs)
406 cdev_id = enabled_cdevs[i];
408 if (ctx[cdev_id] && cperf_testmap[opts.test].destructor)
409 cperf_testmap[opts.test].destructor(ctx[cdev_id]);
413 free_test_vector(t_vec, &opts);