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