Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2016-2017 Intel Corporation
3 : : */
4 : :
5 : : #include <stdio.h>
6 : : #include <stdlib.h>
7 : : #include <unistd.h>
8 : :
9 : : #include <rte_malloc.h>
10 : : #include <rte_random.h>
11 : : #include <rte_eal.h>
12 : : #include <rte_errno.h>
13 : : #include <rte_cryptodev.h>
14 : : #ifdef RTE_CRYPTO_SCHEDULER
15 : : #include <rte_cryptodev_scheduler.h>
16 : : #endif
17 : :
18 : : #include "cperf.h"
19 : : #include "cperf_options.h"
20 : : #include "cperf_test_vector_parsing.h"
21 : : #include "cperf_test_common.h"
22 : : #include "cperf_test_throughput.h"
23 : : #include "cperf_test_latency.h"
24 : : #include "cperf_test_verify.h"
25 : : #include "cperf_test_pmd_cyclecount.h"
26 : :
27 : : static struct {
28 : : struct rte_mempool *sess_mp;
29 : : } session_pool_socket[RTE_MAX_NUMA_NODES];
30 : :
31 : : const char *cperf_test_type_strs[] = {
32 : : [CPERF_TEST_TYPE_THROUGHPUT] = "throughput",
33 : : [CPERF_TEST_TYPE_LATENCY] = "latency",
34 : : [CPERF_TEST_TYPE_VERIFY] = "verify",
35 : : [CPERF_TEST_TYPE_PMDCC] = "pmd-cyclecount"
36 : : };
37 : :
38 : : const char *cperf_op_type_strs[] = {
39 : : [CPERF_CIPHER_ONLY] = "cipher-only",
40 : : [CPERF_AUTH_ONLY] = "auth-only",
41 : : [CPERF_CIPHER_THEN_AUTH] = "cipher-then-auth",
42 : : [CPERF_AUTH_THEN_CIPHER] = "auth-then-cipher",
43 : : [CPERF_AEAD] = "aead",
44 : : [CPERF_PDCP] = "pdcp",
45 : : [CPERF_DOCSIS] = "docsis",
46 : : [CPERF_IPSEC] = "ipsec",
47 : : [CPERF_ASYM_MODEX] = "modex",
48 : : [CPERF_ASYM_SECP256R1] = "ecdsa_p256r1",
49 : : [CPERF_ASYM_ED25519] = "eddsa_25519",
50 : : [CPERF_ASYM_SM2] = "sm2",
51 : : [CPERF_TLS] = "tls-record"
52 : : };
53 : :
54 : : const struct cperf_test cperf_testmap[] = {
55 : : [CPERF_TEST_TYPE_THROUGHPUT] = {
56 : : cperf_throughput_test_constructor,
57 : : cperf_throughput_test_runner,
58 : : cperf_throughput_test_destructor
59 : : },
60 : : [CPERF_TEST_TYPE_LATENCY] = {
61 : : cperf_latency_test_constructor,
62 : : cperf_latency_test_runner,
63 : : cperf_latency_test_destructor
64 : : },
65 : : [CPERF_TEST_TYPE_VERIFY] = {
66 : : cperf_verify_test_constructor,
67 : : cperf_verify_test_runner,
68 : : cperf_verify_test_destructor
69 : : },
70 : : [CPERF_TEST_TYPE_PMDCC] = {
71 : : cperf_pmd_cyclecount_test_constructor,
72 : : cperf_pmd_cyclecount_test_runner,
73 : : cperf_pmd_cyclecount_test_destructor
74 : : }
75 : : };
76 : :
77 : : static int
78 : 0 : create_asym_op_pool_socket(int32_t socket_id, uint32_t nb_sessions)
79 : : {
80 : : char mp_name[RTE_MEMPOOL_NAMESIZE];
81 : : struct rte_mempool *mpool = NULL;
82 : :
83 : 0 : if (session_pool_socket[socket_id].sess_mp == NULL) {
84 : : snprintf(mp_name, RTE_MEMPOOL_NAMESIZE, "perf_asym_sess_pool%u",
85 : : socket_id);
86 : 0 : mpool = rte_cryptodev_asym_session_pool_create(mp_name,
87 : : nb_sessions, 0, 0, socket_id);
88 : 0 : if (mpool == NULL) {
89 : : printf("Cannot create pool \"%s\" on socket %d\n",
90 : : mp_name, socket_id);
91 : 0 : return -ENOMEM;
92 : : }
93 : 0 : session_pool_socket[socket_id].sess_mp = mpool;
94 : : }
95 : : return 0;
96 : : }
97 : :
98 : : static int
99 : 0 : fill_session_pool_socket(int32_t socket_id, uint32_t session_priv_size,
100 : : uint32_t nb_sessions)
101 : : {
102 : : char mp_name[RTE_MEMPOOL_NAMESIZE];
103 : : struct rte_mempool *sess_mp;
104 : :
105 : 0 : if (session_pool_socket[socket_id].sess_mp == NULL) {
106 : :
107 : : snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
108 : : "sess_mp_%u", socket_id);
109 : :
110 : 0 : sess_mp = rte_cryptodev_sym_session_pool_create(mp_name,
111 : : nb_sessions, session_priv_size, 0, 0,
112 : : socket_id);
113 : :
114 : 0 : if (sess_mp == NULL) {
115 : : printf("Cannot create pool \"%s\" on socket %d\n",
116 : : mp_name, socket_id);
117 : 0 : return -ENOMEM;
118 : : }
119 : :
120 : : printf("Allocated pool \"%s\" on socket %d\n",
121 : : mp_name, socket_id);
122 : 0 : session_pool_socket[socket_id].sess_mp = sess_mp;
123 : : }
124 : :
125 : : return 0;
126 : : }
127 : :
128 : : static int
129 : 0 : cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs)
130 : : {
131 : : uint8_t enabled_cdev_count = 0, nb_lcores, cdev_id;
132 : : uint32_t sessions_needed = 0;
133 : : unsigned int i, j;
134 : : int ret;
135 : :
136 : 0 : enabled_cdev_count = rte_cryptodev_devices_get(opts->device_type,
137 : : enabled_cdevs, RTE_CRYPTO_MAX_DEVS);
138 : 0 : if (enabled_cdev_count == 0) {
139 : : printf("No crypto devices type %s available\n",
140 : : opts->device_type);
141 : 0 : return -EINVAL;
142 : : }
143 : :
144 : 0 : nb_lcores = rte_lcore_count() - 1;
145 : :
146 : 0 : if (nb_lcores < 1) {
147 : 0 : RTE_LOG(ERR, USER1,
148 : : "Number of enabled cores need to be higher than 1\n");
149 : 0 : return -EINVAL;
150 : : }
151 : :
152 : : /*
153 : : * Use less number of devices,
154 : : * if there are more available than cores.
155 : : */
156 : : if (enabled_cdev_count > nb_lcores)
157 : : enabled_cdev_count = nb_lcores;
158 : :
159 : : /* Create a mempool shared by all the devices */
160 : : uint32_t max_sess_size = 0, sess_size;
161 : :
162 : 0 : for (cdev_id = 0; cdev_id < rte_cryptodev_count(); cdev_id++) {
163 : 0 : sess_size = rte_cryptodev_sym_get_private_session_size(cdev_id);
164 : : if (sess_size > max_sess_size)
165 : : max_sess_size = sess_size;
166 : : }
167 : : #ifdef RTE_LIB_SECURITY
168 : 0 : for (cdev_id = 0; cdev_id < rte_cryptodev_count(); cdev_id++) {
169 : 0 : sess_size = rte_security_session_get_size(
170 : : rte_cryptodev_get_sec_ctx(cdev_id));
171 : : if (sess_size > max_sess_size)
172 : : max_sess_size = sess_size;
173 : : }
174 : : #endif
175 : : /*
176 : : * Calculate number of needed queue pairs, based on the amount
177 : : * of available number of logical cores and crypto devices.
178 : : * For instance, if there are 4 cores and 2 crypto devices,
179 : : * 2 queue pairs will be set up per device.
180 : : */
181 : 0 : opts->nb_qps = (nb_lcores % enabled_cdev_count) ?
182 : 0 : (nb_lcores / enabled_cdev_count) + 1 :
183 : : nb_lcores / enabled_cdev_count;
184 : :
185 : 0 : for (i = 0; i < enabled_cdev_count &&
186 : 0 : i < RTE_CRYPTO_MAX_DEVS; i++) {
187 : 0 : cdev_id = enabled_cdevs[i];
188 : : #ifdef RTE_CRYPTO_SCHEDULER
189 : : /*
190 : : * If multi-core scheduler is used, limit the number
191 : : * of queue pairs to 1, as there is no way to know
192 : : * how many cores are being used by the PMD, and
193 : : * how many will be available for the application.
194 : : */
195 : 0 : if (!strcmp((const char *)opts->device_type, "crypto_scheduler") &&
196 : 0 : rte_cryptodev_scheduler_mode_get(cdev_id) ==
197 : : CDEV_SCHED_MODE_MULTICORE)
198 : 0 : opts->nb_qps = 1;
199 : : #endif
200 : :
201 : : struct rte_cryptodev_info cdev_info;
202 : 0 : int socket_id = rte_cryptodev_socket_id(cdev_id);
203 : :
204 : : /* Use the first socket if SOCKET_ID_ANY is returned. */
205 : 0 : if (socket_id == SOCKET_ID_ANY)
206 : : socket_id = 0;
207 : :
208 : 0 : rte_cryptodev_info_get(cdev_id, &cdev_info);
209 : :
210 : 0 : if (cperf_is_asym_test(opts)) {
211 : 0 : if ((cdev_info.feature_flags &
212 : : RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) == 0)
213 : 0 : continue;
214 : : }
215 : :
216 : 0 : if (opts->nb_qps > cdev_info.max_nb_queue_pairs) {
217 : : printf("Number of needed queue pairs is higher "
218 : : "than the maximum number of queue pairs "
219 : : "per device.\n");
220 : : printf("Lower the number of cores or increase "
221 : : "the number of crypto devices\n");
222 : 0 : return -EINVAL;
223 : : }
224 : 0 : struct rte_cryptodev_config conf = {
225 : : .nb_queue_pairs = opts->nb_qps,
226 : : .socket_id = socket_id,
227 : : };
228 : :
229 : 0 : switch (opts->op_type) {
230 : 0 : case CPERF_ASYM_SECP256R1:
231 : : case CPERF_ASYM_ED25519:
232 : : case CPERF_ASYM_SM2:
233 : : case CPERF_ASYM_MODEX:
234 : 0 : conf.ff_disable |= (RTE_CRYPTODEV_FF_SECURITY |
235 : : RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO);
236 : 0 : break;
237 : 0 : case CPERF_CIPHER_ONLY:
238 : : case CPERF_AUTH_ONLY:
239 : : case CPERF_CIPHER_THEN_AUTH:
240 : : case CPERF_AUTH_THEN_CIPHER:
241 : : case CPERF_AEAD:
242 : 0 : conf.ff_disable |= RTE_CRYPTODEV_FF_SECURITY;
243 : : /* Fall through */
244 : 0 : case CPERF_PDCP:
245 : : case CPERF_DOCSIS:
246 : : case CPERF_IPSEC:
247 : : case CPERF_TLS:
248 : : /* Fall through */
249 : : default:
250 : 0 : conf.ff_disable |= RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO;
251 : : }
252 : :
253 : 0 : struct rte_cryptodev_qp_conf qp_conf = {
254 : 0 : .nb_descriptors = opts->nb_descriptors,
255 : : .priority = RTE_CRYPTODEV_QP_PRIORITY_HIGHEST
256 : : };
257 : :
258 : : /**
259 : : * Device info specifies the min headroom and tailroom
260 : : * requirement for the crypto PMD. This need to be honoured
261 : : * by the application, while creating mbuf.
262 : : */
263 : 0 : if (opts->headroom_sz < cdev_info.min_mbuf_headroom_req) {
264 : : /* Update headroom */
265 : 0 : opts->headroom_sz = cdev_info.min_mbuf_headroom_req;
266 : : }
267 : 0 : if (opts->tailroom_sz < cdev_info.min_mbuf_tailroom_req) {
268 : : /* Update tailroom */
269 : 0 : opts->tailroom_sz = cdev_info.min_mbuf_tailroom_req;
270 : : }
271 : :
272 : : /* Update segment size to include headroom & tailroom */
273 : 0 : opts->segment_sz += (opts->headroom_sz + opts->tailroom_sz);
274 : :
275 : 0 : uint32_t dev_max_nb_sess = cdev_info.sym.max_nb_sessions;
276 : 0 : if (!strcmp((const char *)opts->device_type,
277 : : "crypto_scheduler")) {
278 : : #ifdef RTE_CRYPTO_SCHEDULER
279 : 0 : uint32_t nb_workers =
280 : 0 : rte_cryptodev_scheduler_workers_get(cdev_id,
281 : : NULL);
282 : : /* scheduler session header per lcore + 1 session per worker qp */
283 : 0 : sessions_needed = nb_lcores + enabled_cdev_count *
284 : 0 : opts->nb_qps * nb_workers;
285 : : #endif
286 : : } else
287 : 0 : sessions_needed = enabled_cdev_count * opts->nb_qps;
288 : :
289 : : /*
290 : : * A single session is required per queue pair
291 : : * in each device
292 : : */
293 : 0 : if (dev_max_nb_sess != 0 && dev_max_nb_sess < opts->nb_qps) {
294 : 0 : RTE_LOG(ERR, USER1,
295 : : "Device does not support at least "
296 : : "%u sessions\n", opts->nb_qps);
297 : 0 : return -ENOTSUP;
298 : : }
299 : :
300 : 0 : if (cperf_is_asym_test(opts))
301 : 0 : ret = create_asym_op_pool_socket(socket_id,
302 : : sessions_needed);
303 : : else
304 : 0 : ret = fill_session_pool_socket(socket_id, max_sess_size,
305 : : sessions_needed);
306 : 0 : if (ret < 0)
307 : 0 : return ret;
308 : :
309 : 0 : qp_conf.mp_session = session_pool_socket[socket_id].sess_mp;
310 : :
311 : 0 : if (cperf_is_asym_test(opts))
312 : 0 : qp_conf.mp_session = NULL;
313 : :
314 : 0 : ret = rte_cryptodev_configure(cdev_id, &conf);
315 : 0 : if (ret < 0) {
316 : : printf("Failed to configure cryptodev %u", cdev_id);
317 : 0 : return -EINVAL;
318 : : }
319 : :
320 : 0 : for (j = 0; j < opts->nb_qps; j++) {
321 : 0 : if ((1 << j) & opts->low_prio_qp_mask)
322 : 0 : qp_conf.priority = RTE_CRYPTODEV_QP_PRIORITY_LOWEST;
323 : :
324 : 0 : ret = rte_cryptodev_queue_pair_setup(cdev_id, j,
325 : : &qp_conf, socket_id);
326 : 0 : if (ret < 0) {
327 : : printf("Failed to setup queue pair %u on "
328 : : "cryptodev %u", j, cdev_id);
329 : 0 : return -EINVAL;
330 : : }
331 : : }
332 : :
333 : 0 : ret = rte_cryptodev_start(cdev_id);
334 : 0 : if (ret < 0) {
335 : : printf("Failed to start device %u: error %d\n",
336 : : cdev_id, ret);
337 : 0 : return -EPERM;
338 : : }
339 : : }
340 : :
341 : 0 : return enabled_cdev_count;
342 : : }
343 : :
344 : : static int
345 : 0 : cperf_verify_devices_capabilities(struct cperf_options *opts,
346 : : uint8_t *enabled_cdevs, uint8_t nb_cryptodevs)
347 : : {
348 : : struct rte_cryptodev_sym_capability_idx cap_idx;
349 : : const struct rte_cryptodev_symmetric_capability *capability;
350 : : struct rte_cryptodev_asym_capability_idx asym_cap_idx;
351 : : const struct rte_cryptodev_asymmetric_xform_capability *asym_capability;
352 : :
353 : :
354 : : uint8_t i, cdev_id;
355 : : int ret;
356 : :
357 : 0 : for (i = 0; i < nb_cryptodevs; i++) {
358 : :
359 : 0 : cdev_id = enabled_cdevs[i];
360 : :
361 : 0 : if (opts->op_type == CPERF_ASYM_MODEX) {
362 : 0 : asym_cap_idx.type = RTE_CRYPTO_ASYM_XFORM_MODEX;
363 : 0 : asym_capability = rte_cryptodev_asym_capability_get(
364 : : cdev_id, &asym_cap_idx);
365 : 0 : if (asym_capability == NULL)
366 : : return -1;
367 : :
368 : 0 : ret = rte_cryptodev_asym_xform_capability_check_modlen(
369 : 0 : asym_capability, opts->modex_data->modulus.len);
370 : 0 : if (ret != 0)
371 : 0 : return ret;
372 : :
373 : : }
374 : :
375 : 0 : if (opts->op_type == CPERF_ASYM_SECP256R1) {
376 : 0 : asym_cap_idx.type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
377 : 0 : asym_capability = rte_cryptodev_asym_capability_get(cdev_id, &asym_cap_idx);
378 : 0 : if (asym_capability == NULL)
379 : : return -1;
380 : :
381 : 0 : if (!rte_cryptodev_asym_xform_capability_check_optype(asym_capability,
382 : : opts->asym_op_type))
383 : : return -1;
384 : :
385 : 0 : if (asym_capability->internal_rng != 0) {
386 : 0 : opts->secp256r1_data->k.data = NULL;
387 : 0 : opts->secp256r1_data->k.length = 0;
388 : : }
389 : : }
390 : :
391 : 0 : if (opts->op_type == CPERF_ASYM_ED25519) {
392 : 0 : asym_cap_idx.type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
393 : 0 : asym_capability = rte_cryptodev_asym_capability_get(cdev_id, &asym_cap_idx);
394 : 0 : if (asym_capability == NULL)
395 : : return -1;
396 : :
397 : 0 : if (!rte_cryptodev_asym_xform_capability_check_optype(asym_capability,
398 : : opts->asym_op_type))
399 : : return -1;
400 : : }
401 : :
402 : 0 : if (opts->op_type == CPERF_ASYM_SM2) {
403 : 0 : asym_cap_idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
404 : 0 : asym_capability = rte_cryptodev_asym_capability_get(cdev_id, &asym_cap_idx);
405 : 0 : if (asym_capability == NULL)
406 : : return -1;
407 : :
408 : 0 : if (!rte_cryptodev_asym_xform_capability_check_optype(asym_capability,
409 : : opts->asym_op_type))
410 : : return -1;
411 : :
412 : 0 : if (rte_cryptodev_asym_xform_capability_check_hash(asym_capability,
413 : : RTE_CRYPTO_AUTH_SM3)) {
414 : 0 : opts->asym_hash_alg = RTE_CRYPTO_AUTH_SM3;
415 : 0 : if (opts->asym_op_type == RTE_CRYPTO_ASYM_OP_SIGN ||
416 : : opts->asym_op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
417 : 0 : opts->sm2_data->message.data = sm2_perf_data.message.data;
418 : 0 : opts->sm2_data->message.length =
419 : 0 : sm2_perf_data.message.length;
420 : 0 : opts->sm2_data->id.data = sm2_perf_data.id.data;
421 : 0 : opts->sm2_data->id.length = sm2_perf_data.id.length;
422 : : }
423 : : } else {
424 : 0 : opts->asym_hash_alg = RTE_CRYPTO_AUTH_NULL;
425 : 0 : if (opts->asym_op_type == RTE_CRYPTO_ASYM_OP_SIGN ||
426 : : opts->asym_op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
427 : 0 : opts->sm2_data->message.data = sm2_perf_data.digest.data;
428 : 0 : opts->sm2_data->message.length =
429 : 0 : sm2_perf_data.digest.length;
430 : 0 : opts->sm2_data->id.data = NULL;
431 : 0 : opts->sm2_data->id.length = 0;
432 : : }
433 : : }
434 : 0 : if (asym_capability->internal_rng != 0) {
435 : 0 : opts->sm2_data->k.data = NULL;
436 : 0 : opts->sm2_data->k.length = 0;
437 : : }
438 : 0 : if (opts->asym_op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
439 : 0 : opts->sm2_data->message.data = sm2_perf_data.message.data;
440 : 0 : opts->sm2_data->message.length = sm2_perf_data.message.length;
441 : 0 : opts->sm2_data->cipher.data = sm2_perf_data.cipher.data;
442 : 0 : opts->sm2_data->cipher.length = sm2_perf_data.cipher.length;
443 : 0 : } else if (opts->asym_op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
444 : 0 : opts->sm2_data->cipher.data = sm2_perf_data.cipher.data;
445 : 0 : opts->sm2_data->cipher.length = sm2_perf_data.cipher.length;
446 : 0 : opts->sm2_data->message.data = sm2_perf_data.message.data;
447 : 0 : opts->sm2_data->message.length = sm2_perf_data.message.length;
448 : 0 : } else if (opts->asym_op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
449 : 0 : opts->sm2_data->sign_r.data = sm2_perf_data.sign_r.data;
450 : 0 : opts->sm2_data->sign_r.length = sm2_perf_data.sign_r.length;
451 : 0 : opts->sm2_data->sign_s.data = sm2_perf_data.sign_s.data;
452 : 0 : opts->sm2_data->sign_s.length = sm2_perf_data.sign_s.length;
453 : 0 : } else if (opts->asym_op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
454 : 0 : opts->sm2_data->sign_r.data = sm2_perf_data.sign_r.data;
455 : 0 : opts->sm2_data->sign_r.length = sm2_perf_data.sign_r.length;
456 : 0 : opts->sm2_data->sign_s.data = sm2_perf_data.sign_s.data;
457 : 0 : opts->sm2_data->sign_s.length = sm2_perf_data.sign_s.length;
458 : : }
459 : : }
460 : :
461 : 0 : if (opts->op_type == CPERF_AUTH_ONLY ||
462 : 0 : opts->op_type == CPERF_CIPHER_THEN_AUTH ||
463 : : opts->op_type == CPERF_AUTH_THEN_CIPHER) {
464 : :
465 : 0 : cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
466 : 0 : cap_idx.algo.auth = opts->auth_algo;
467 : :
468 : 0 : capability = rte_cryptodev_sym_capability_get(cdev_id,
469 : : &cap_idx);
470 : 0 : if (capability == NULL)
471 : : return -1;
472 : :
473 : 0 : ret = rte_cryptodev_sym_capability_check_auth(
474 : : capability,
475 : 0 : opts->auth_key_sz,
476 : 0 : opts->digest_sz,
477 : 0 : opts->auth_iv_sz);
478 : 0 : if (ret != 0)
479 : 0 : return ret;
480 : : }
481 : :
482 : 0 : if (opts->op_type == CPERF_CIPHER_ONLY ||
483 : 0 : opts->op_type == CPERF_CIPHER_THEN_AUTH ||
484 : : opts->op_type == CPERF_AUTH_THEN_CIPHER) {
485 : :
486 : 0 : cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
487 : 0 : cap_idx.algo.cipher = opts->cipher_algo;
488 : :
489 : 0 : capability = rte_cryptodev_sym_capability_get(cdev_id,
490 : : &cap_idx);
491 : 0 : if (capability == NULL)
492 : : return -1;
493 : :
494 : 0 : ret = rte_cryptodev_sym_capability_check_cipher(
495 : : capability,
496 : 0 : opts->cipher_key_sz,
497 : 0 : opts->cipher_iv_sz);
498 : 0 : if (ret != 0)
499 : 0 : return ret;
500 : : }
501 : :
502 : 0 : if (opts->op_type == CPERF_AEAD) {
503 : :
504 : 0 : cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
505 : 0 : cap_idx.algo.aead = opts->aead_algo;
506 : :
507 : 0 : capability = rte_cryptodev_sym_capability_get(cdev_id,
508 : : &cap_idx);
509 : 0 : if (capability == NULL)
510 : : return -1;
511 : :
512 : 0 : ret = rte_cryptodev_sym_capability_check_aead(
513 : : capability,
514 : 0 : opts->aead_key_sz,
515 : 0 : opts->digest_sz,
516 : 0 : opts->aead_aad_sz,
517 : 0 : opts->aead_iv_sz);
518 : 0 : if (ret != 0)
519 : 0 : return ret;
520 : : }
521 : : }
522 : :
523 : : return 0;
524 : : }
525 : :
526 : : static int
527 : 0 : cperf_check_test_vector(struct cperf_options *opts,
528 : : struct cperf_test_vector *test_vec)
529 : : {
530 : 0 : if (opts->op_type == CPERF_CIPHER_ONLY) {
531 : 0 : if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
532 : 0 : if (test_vec->plaintext.data == NULL)
533 : 0 : return -1;
534 : : } else {
535 : 0 : if (test_vec->plaintext.data == NULL)
536 : : return -1;
537 : 0 : if (test_vec->plaintext.length < opts->max_buffer_size)
538 : : return -1;
539 : 0 : if (test_vec->ciphertext.data == NULL)
540 : : return -1;
541 : 0 : if (test_vec->ciphertext.length < opts->max_buffer_size)
542 : : return -1;
543 : : /* Cipher IV is only required for some algorithms */
544 : 0 : if (opts->cipher_iv_sz &&
545 : 0 : test_vec->cipher_iv.data == NULL)
546 : : return -1;
547 : 0 : if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
548 : : return -1;
549 : 0 : if (test_vec->cipher_key.data == NULL)
550 : : return -1;
551 : 0 : if (test_vec->cipher_key.length != opts->cipher_key_sz)
552 : 0 : return -1;
553 : : }
554 : 0 : } else if (opts->op_type == CPERF_AUTH_ONLY) {
555 : 0 : if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
556 : 0 : if (test_vec->plaintext.data == NULL)
557 : : return -1;
558 : 0 : if (test_vec->plaintext.length < opts->max_buffer_size)
559 : : return -1;
560 : : /* Auth key is only required for some algorithms */
561 : 0 : if (opts->auth_key_sz &&
562 : 0 : test_vec->auth_key.data == NULL)
563 : : return -1;
564 : 0 : if (test_vec->auth_key.length != opts->auth_key_sz)
565 : : return -1;
566 : 0 : if (test_vec->auth_iv.length != opts->auth_iv_sz)
567 : : return -1;
568 : : /* Auth IV is only required for some algorithms */
569 : 0 : if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
570 : : return -1;
571 : 0 : if (test_vec->digest.data == NULL)
572 : : return -1;
573 : 0 : if (test_vec->digest.length < opts->digest_sz)
574 : 0 : return -1;
575 : : }
576 : :
577 : 0 : } else if (opts->op_type == CPERF_CIPHER_THEN_AUTH ||
578 : : opts->op_type == CPERF_AUTH_THEN_CIPHER) {
579 : 0 : if (opts->cipher_algo == RTE_CRYPTO_CIPHER_NULL) {
580 : 0 : if (test_vec->plaintext.data == NULL)
581 : : return -1;
582 : 0 : if (test_vec->plaintext.length < opts->max_buffer_size)
583 : : return -1;
584 : : } else {
585 : 0 : if (test_vec->plaintext.data == NULL)
586 : : return -1;
587 : 0 : if (test_vec->plaintext.length < opts->max_buffer_size)
588 : : return -1;
589 : 0 : if (test_vec->ciphertext.data == NULL)
590 : : return -1;
591 : 0 : if (test_vec->ciphertext.length < opts->max_buffer_size)
592 : : return -1;
593 : 0 : if (test_vec->cipher_iv.data == NULL)
594 : : return -1;
595 : 0 : if (test_vec->cipher_iv.length != opts->cipher_iv_sz)
596 : : return -1;
597 : 0 : if (test_vec->cipher_key.data == NULL)
598 : : return -1;
599 : 0 : if (test_vec->cipher_key.length != opts->cipher_key_sz)
600 : : return -1;
601 : : }
602 : 0 : if (opts->auth_algo != RTE_CRYPTO_AUTH_NULL) {
603 : 0 : if (test_vec->auth_key.data == NULL)
604 : : return -1;
605 : 0 : if (test_vec->auth_key.length != opts->auth_key_sz)
606 : : return -1;
607 : 0 : if (test_vec->auth_iv.length != opts->auth_iv_sz)
608 : : return -1;
609 : : /* Auth IV is only required for some algorithms */
610 : 0 : if (opts->auth_iv_sz && test_vec->auth_iv.data == NULL)
611 : : return -1;
612 : 0 : if (test_vec->digest.data == NULL)
613 : : return -1;
614 : 0 : if (test_vec->digest.length < opts->digest_sz)
615 : 0 : return -1;
616 : : }
617 : 0 : } else if (opts->op_type == CPERF_AEAD) {
618 : 0 : if (test_vec->plaintext.data == NULL)
619 : : return -1;
620 : 0 : if (test_vec->plaintext.length < opts->max_buffer_size)
621 : : return -1;
622 : 0 : if (test_vec->ciphertext.data == NULL)
623 : : return -1;
624 : 0 : if (test_vec->ciphertext.length < opts->max_buffer_size)
625 : : return -1;
626 : 0 : if (test_vec->aead_key.data == NULL)
627 : : return -1;
628 : 0 : if (test_vec->aead_key.length != opts->aead_key_sz)
629 : : return -1;
630 : 0 : if (test_vec->aead_iv.data == NULL)
631 : : return -1;
632 : 0 : if (test_vec->aead_iv.length != opts->aead_iv_sz)
633 : : return -1;
634 : 0 : if (test_vec->aad.data == NULL)
635 : : return -1;
636 : 0 : if (test_vec->aad.length != opts->aead_aad_sz)
637 : : return -1;
638 : 0 : if (test_vec->digest.data == NULL)
639 : : return -1;
640 : 0 : if (test_vec->digest.length < opts->digest_sz)
641 : 0 : return -1;
642 : : }
643 : : return 0;
644 : : }
645 : :
646 : : int
647 : 0 : main(int argc, char **argv)
648 : : {
649 : 0 : struct cperf_options opts = {0};
650 : : struct cperf_test_vector *t_vec = NULL;
651 : : struct cperf_op_fns op_fns;
652 : 0 : void *ctx[RTE_MAX_LCORE] = { };
653 : : int nb_cryptodevs = 0;
654 : : uint16_t total_nb_qps = 0;
655 : : uint8_t cdev_id, i;
656 : 0 : uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 };
657 : :
658 : : uint8_t buffer_size_idx = 0;
659 : :
660 : : int ret;
661 : : uint32_t lcore_id;
662 : : bool cap_unsupported = false;
663 : :
664 : : /* Initialise DPDK EAL */
665 : 0 : ret = rte_eal_init(argc, argv);
666 : 0 : if (ret < 0)
667 : 0 : rte_exit(EXIT_FAILURE, "Invalid EAL arguments!\n");
668 : 0 : argc -= ret;
669 : 0 : argv += ret;
670 : :
671 : 0 : cperf_options_default(&opts);
672 : :
673 : 0 : ret = cperf_options_parse(&opts, argc, argv);
674 : 0 : if (ret) {
675 : 0 : RTE_LOG(ERR, USER1, "Parsing one or more user options failed\n");
676 : 0 : goto err;
677 : : }
678 : :
679 : 0 : ret = cperf_options_check(&opts);
680 : 0 : if (ret) {
681 : 0 : RTE_LOG(ERR, USER1,
682 : : "Checking one or more user options failed\n");
683 : 0 : goto err;
684 : : }
685 : :
686 : 0 : nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs);
687 : :
688 : 0 : if (!opts.silent)
689 : 0 : cperf_options_dump(&opts);
690 : :
691 : 0 : if (nb_cryptodevs < 1) {
692 : 0 : RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
693 : : "device type\n");
694 : : nb_cryptodevs = 0;
695 : 0 : goto err;
696 : : }
697 : :
698 : 0 : ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
699 : : nb_cryptodevs);
700 : 0 : if (ret) {
701 : 0 : RTE_LOG(ERR, USER1, "Crypto device type does not support "
702 : : "capabilities requested\n");
703 : : cap_unsupported = true;
704 : 0 : goto err;
705 : : }
706 : :
707 : 0 : if (opts.test_file != NULL) {
708 : 0 : t_vec = cperf_test_vector_get_from_file(&opts);
709 : 0 : if (t_vec == NULL) {
710 : 0 : RTE_LOG(ERR, USER1,
711 : : "Failed to create test vector for"
712 : : " specified file\n");
713 : 0 : goto err;
714 : : }
715 : :
716 : 0 : if (cperf_check_test_vector(&opts, t_vec)) {
717 : 0 : RTE_LOG(ERR, USER1, "Incomplete necessary test vectors"
718 : : "\n");
719 : 0 : goto err;
720 : : }
721 : : } else {
722 : 0 : t_vec = cperf_test_vector_get_dummy(&opts);
723 : 0 : if (t_vec == NULL) {
724 : 0 : RTE_LOG(ERR, USER1,
725 : : "Failed to create test vector for"
726 : : " specified algorithms\n");
727 : 0 : goto err;
728 : : }
729 : : }
730 : :
731 : 0 : ret = cperf_get_op_functions(&opts, &op_fns);
732 : 0 : if (ret) {
733 : 0 : RTE_LOG(ERR, USER1, "Failed to find function ops set for "
734 : : "specified algorithms combination\n");
735 : 0 : goto err;
736 : : }
737 : :
738 : 0 : if (!opts.silent && opts.test != CPERF_TEST_TYPE_THROUGHPUT &&
739 : : opts.test != CPERF_TEST_TYPE_LATENCY)
740 : 0 : show_test_vector(t_vec);
741 : :
742 : 0 : total_nb_qps = nb_cryptodevs * opts.nb_qps;
743 : :
744 : : i = 0;
745 : : uint8_t qp_id = 0, cdev_index = 0;
746 : :
747 : 0 : void *sess = NULL;
748 : :
749 : 0 : RTE_LCORE_FOREACH_WORKER(lcore_id) {
750 : :
751 : 0 : if (i == total_nb_qps)
752 : : break;
753 : :
754 : 0 : cdev_id = enabled_cdevs[cdev_index];
755 : :
756 : 0 : int socket_id = rte_cryptodev_socket_id(cdev_id);
757 : :
758 : : /* Use the first socket if SOCKET_ID_ANY is returned. */
759 : 0 : if (socket_id == SOCKET_ID_ANY)
760 : : socket_id = 0;
761 : :
762 : 0 : ctx[i] = cperf_testmap[opts.test].constructor(
763 : : session_pool_socket[socket_id].sess_mp,
764 : : cdev_id, qp_id,
765 : : &opts, t_vec, &op_fns, &sess);
766 : :
767 : : /*
768 : : * If sess was NULL, the constructor will have set it to a newly
769 : : * created session. This means future calls to constructors will
770 : : * provide this session, sharing it across all qps. If session
771 : : * sharing is not enabled, re-set sess to NULL, to prevent this.
772 : : */
773 : 0 : if (!opts.shared_session)
774 : 0 : sess = NULL;
775 : :
776 : 0 : if (ctx[i] == NULL) {
777 : 0 : RTE_LOG(ERR, USER1, "Test run constructor failed\n");
778 : 0 : goto err;
779 : : }
780 : :
781 : 0 : qp_id = (qp_id + 1) % opts.nb_qps;
782 : 0 : if (qp_id == 0) {
783 : 0 : cdev_index++;
784 : : /* If next qp is on a new cdev, don't share the session
785 : : * - it shouldn't be shared across different cdevs.
786 : : */
787 : 0 : sess = NULL;
788 : : }
789 : 0 : i++;
790 : : }
791 : :
792 : 0 : if (opts.imix_distribution_count != 0) {
793 : 0 : uint8_t buffer_size_count = opts.buffer_size_count;
794 : 0 : uint16_t distribution_total[buffer_size_count];
795 : : uint32_t op_idx;
796 : : uint32_t test_average_size = 0;
797 : : const uint32_t *buffer_size_list = opts.buffer_size_list;
798 : : const uint32_t *imix_distribution_list = opts.imix_distribution_list;
799 : :
800 : 0 : opts.imix_buffer_sizes = rte_malloc(NULL,
801 : 0 : sizeof(uint32_t) * opts.pool_sz,
802 : : 0);
803 : : /*
804 : : * Calculate accumulated distribution of
805 : : * probabilities per packet size
806 : : */
807 : 0 : distribution_total[0] = imix_distribution_list[0];
808 : 0 : for (i = 1; i < buffer_size_count; i++)
809 : 0 : distribution_total[i] = imix_distribution_list[i] +
810 : 0 : distribution_total[i-1];
811 : :
812 : : /* Calculate a random sequence of packet sizes, based on distribution */
813 : 0 : for (op_idx = 0; op_idx < opts.pool_sz; op_idx++) {
814 : 0 : uint16_t random_number = rte_rand() %
815 : 0 : distribution_total[buffer_size_count - 1];
816 : 0 : for (i = 0; i < buffer_size_count; i++)
817 : 0 : if (random_number < distribution_total[i])
818 : : break;
819 : :
820 : 0 : opts.imix_buffer_sizes[op_idx] = buffer_size_list[i];
821 : : }
822 : :
823 : : /* Calculate average buffer size for the IMIX distribution */
824 : 0 : for (i = 0; i < buffer_size_count; i++)
825 : 0 : test_average_size += buffer_size_list[i] *
826 : 0 : imix_distribution_list[i];
827 : :
828 : 0 : opts.test_buffer_size = test_average_size /
829 : 0 : distribution_total[buffer_size_count - 1];
830 : :
831 : : i = 0;
832 : 0 : RTE_LCORE_FOREACH_WORKER(lcore_id) {
833 : :
834 : 0 : if (i == total_nb_qps)
835 : : break;
836 : :
837 : 0 : rte_eal_remote_launch(cperf_testmap[opts.test].runner,
838 : : ctx[i], lcore_id);
839 : 0 : i++;
840 : : }
841 : : i = 0;
842 : 0 : RTE_LCORE_FOREACH_WORKER(lcore_id) {
843 : :
844 : 0 : if (i == total_nb_qps)
845 : : break;
846 : 0 : ret |= rte_eal_wait_lcore(lcore_id);
847 : 0 : i++;
848 : : }
849 : :
850 : 0 : if (ret != EXIT_SUCCESS)
851 : 0 : goto err;
852 : : } else {
853 : :
854 : : /* Get next size from range or list */
855 : 0 : if (opts.inc_buffer_size != 0)
856 : 0 : opts.test_buffer_size = opts.min_buffer_size;
857 : : else
858 : 0 : opts.test_buffer_size = opts.buffer_size_list[0];
859 : :
860 : 0 : while (opts.test_buffer_size <= opts.max_buffer_size) {
861 : : i = 0;
862 : 0 : RTE_LCORE_FOREACH_WORKER(lcore_id) {
863 : :
864 : 0 : if (i == total_nb_qps)
865 : : break;
866 : :
867 : 0 : rte_eal_remote_launch(cperf_testmap[opts.test].runner,
868 : : ctx[i], lcore_id);
869 : 0 : i++;
870 : : }
871 : : i = 0;
872 : 0 : RTE_LCORE_FOREACH_WORKER(lcore_id) {
873 : :
874 : 0 : if (i == total_nb_qps)
875 : : break;
876 : 0 : ret |= rte_eal_wait_lcore(lcore_id);
877 : 0 : i++;
878 : : }
879 : :
880 : 0 : if (ret != EXIT_SUCCESS)
881 : 0 : goto err;
882 : :
883 : : /* Get next size from range or list */
884 : 0 : if (opts.inc_buffer_size != 0)
885 : 0 : opts.test_buffer_size += opts.inc_buffer_size;
886 : : else {
887 : 0 : if (++buffer_size_idx == opts.buffer_size_count)
888 : : break;
889 : 0 : opts.test_buffer_size =
890 : 0 : opts.buffer_size_list[buffer_size_idx];
891 : : }
892 : : }
893 : : }
894 : :
895 : : i = 0;
896 : 0 : RTE_LCORE_FOREACH_WORKER(lcore_id) {
897 : :
898 : 0 : if (i == total_nb_qps)
899 : : break;
900 : :
901 : 0 : cperf_testmap[opts.test].destructor(ctx[i]);
902 : 0 : i++;
903 : : }
904 : :
905 : 0 : for (i = 0; i < nb_cryptodevs &&
906 : 0 : i < RTE_CRYPTO_MAX_DEVS; i++) {
907 : 0 : rte_cryptodev_stop(enabled_cdevs[i]);
908 : 0 : ret = rte_cryptodev_close(enabled_cdevs[i]);
909 : 0 : if (ret)
910 : 0 : RTE_LOG(ERR, USER1,
911 : : "Crypto device close error %d\n", ret);
912 : : }
913 : :
914 : 0 : free_test_vector(t_vec, &opts);
915 : :
916 : : printf("\n");
917 : 0 : return EXIT_SUCCESS;
918 : :
919 : 0 : err:
920 : : i = 0;
921 : 0 : RTE_LCORE_FOREACH_WORKER(lcore_id) {
922 : 0 : if (i == total_nb_qps)
923 : : break;
924 : :
925 : 0 : if (ctx[i] && cperf_testmap[opts.test].destructor)
926 : 0 : cperf_testmap[opts.test].destructor(ctx[i]);
927 : 0 : i++;
928 : : }
929 : :
930 : 0 : for (i = 0; i < nb_cryptodevs &&
931 : 0 : i < RTE_CRYPTO_MAX_DEVS; i++) {
932 : 0 : rte_cryptodev_stop(enabled_cdevs[i]);
933 : 0 : ret = rte_cryptodev_close(enabled_cdevs[i]);
934 : 0 : if (ret)
935 : 0 : RTE_LOG(ERR, USER1,
936 : : "Crypto device close error %d\n", ret);
937 : :
938 : : }
939 : 0 : rte_free(opts.imix_buffer_sizes);
940 : 0 : free_test_vector(t_vec, &opts);
941 : :
942 : 0 : if (rte_errno == ENOTSUP || cap_unsupported) {
943 : 0 : RTE_LOG(ERR, USER1, "Unsupported case: errno: %u\n", rte_errno);
944 : 0 : return -ENOTSUP;
945 : : }
946 : : printf("\n");
947 : 0 : return EXIT_FAILURE;
948 : : }
|