1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2017 Cavium, Inc 3 */ 4 5 #include <math.h> 6 7 #include "test_perf_common.h" 8 9 #define NB_CRYPTODEV_DESCRIPTORS 1024 10 #define DATA_SIZE 512 11 #define IV_OFFSET (sizeof(struct rte_crypto_op) + \ 12 sizeof(struct rte_crypto_sym_op) + \ 13 sizeof(union rte_event_crypto_metadata)) 14 15 struct modex_test_data { 16 enum rte_crypto_asym_xform_type xform_type; 17 struct { 18 uint8_t data[DATA_SIZE]; 19 uint16_t len; 20 } base; 21 struct { 22 uint8_t data[DATA_SIZE]; 23 uint16_t len; 24 } exponent; 25 struct { 26 uint8_t data[DATA_SIZE]; 27 uint16_t len; 28 } modulus; 29 struct { 30 uint8_t data[DATA_SIZE]; 31 uint16_t len; 32 } reminder; 33 uint16_t result_len; 34 }; 35 36 static struct 37 modex_test_data modex_test_case = { 38 .xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX, 39 .base = { 40 .data = { 41 0xF8, 0xBA, 0x1A, 0x55, 0xD0, 0x2F, 0x85, 42 0xAE, 0x96, 0x7B, 0xB6, 0x2F, 0xB6, 0xCD, 43 0xA8, 0xEB, 0x7E, 0x78, 0xA0, 0x50 44 }, 45 .len = 20, 46 }, 47 .exponent = { 48 .data = { 49 0x01, 0x00, 0x01 50 }, 51 .len = 3, 52 }, 53 .reminder = { 54 .data = { 55 0x2C, 0x60, 0x75, 0x45, 0x98, 0x9D, 0xE0, 0x72, 56 0xA0, 0x9D, 0x3A, 0x9E, 0x03, 0x38, 0x73, 0x3C, 57 0x31, 0x83, 0x04, 0xFE, 0x75, 0x43, 0xE6, 0x17, 58 0x5C, 0x01, 0x29, 0x51, 0x69, 0x33, 0x62, 0x2D, 59 0x78, 0xBE, 0xAE, 0xC4, 0xBC, 0xDE, 0x7E, 0x2C, 60 0x77, 0x84, 0xF2, 0xC5, 0x14, 0xB5, 0x2F, 0xF7, 61 0xC5, 0x94, 0xEF, 0x86, 0x75, 0x75, 0xB5, 0x11, 62 0xE5, 0x0E, 0x0A, 0x29, 0x76, 0xE2, 0xEA, 0x32, 63 0x0E, 0x43, 0x77, 0x7E, 0x2C, 0x27, 0xAC, 0x3B, 64 0x86, 0xA5, 0xDB, 0xC9, 0x48, 0x40, 0xE8, 0x99, 65 0x9A, 0x0A, 0x3D, 0xD6, 0x74, 0xFA, 0x2E, 0x2E, 66 0x5B, 0xAF, 0x8C, 0x99, 0x44, 0x2A, 0x67, 0x38, 67 0x27, 0x41, 0x59, 0x9D, 0xB8, 0x51, 0xC9, 0xF7, 68 0x43, 0x61, 0x31, 0x6E, 0xF1, 0x25, 0x38, 0x7F, 69 0xAE, 0xC6, 0xD0, 0xBB, 0x29, 0x76, 0x3F, 0x46, 70 0x2E, 0x1B, 0xE4, 0x67, 0x71, 0xE3, 0x87, 0x5A 71 }, 72 .len = 128, 73 }, 74 .modulus = { 75 .data = { 76 0xb3, 0xa1, 0xaf, 0xb7, 0x13, 0x08, 0x00, 0x0a, 77 0x35, 0xdc, 0x2b, 0x20, 0x8d, 0xa1, 0xb5, 0xce, 78 0x47, 0x8a, 0xc3, 0x80, 0xf4, 0x7d, 0x4a, 0xa2, 79 0x62, 0xfd, 0x61, 0x7f, 0xb5, 0xa8, 0xde, 0x0a, 80 0x17, 0x97, 0xa0, 0xbf, 0xdf, 0x56, 0x5a, 0x3d, 81 0x51, 0x56, 0x4f, 0x70, 0x70, 0x3f, 0x63, 0x6a, 82 0x44, 0x5b, 0xad, 0x84, 0x0d, 0x3f, 0x27, 0x6e, 83 0x3b, 0x34, 0x91, 0x60, 0x14, 0xb9, 0xaa, 0x72, 84 0xfd, 0xa3, 0x64, 0xd2, 0x03, 0xa7, 0x53, 0x87, 85 0x9e, 0x88, 0x0b, 0xc1, 0x14, 0x93, 0x1a, 0x62, 86 0xff, 0xb1, 0x5d, 0x74, 0xcd, 0x59, 0x63, 0x18, 87 0x11, 0x3d, 0x4f, 0xba, 0x75, 0xd4, 0x33, 0x4e, 88 0x23, 0x6b, 0x7b, 0x57, 0x44, 0xe1, 0xd3, 0x03, 89 0x13, 0xa6, 0xf0, 0x8b, 0x60, 0xb0, 0x9e, 0xee, 90 0x75, 0x08, 0x9d, 0x71, 0x63, 0x13, 0xcb, 0xa6, 91 0x81, 0x92, 0x14, 0x03, 0x22, 0x2d, 0xde, 0x55 92 }, 93 .len = 128, 94 }, 95 .result_len = 128, 96 }; 97 98 int 99 perf_test_result(struct evt_test *test, struct evt_options *opt) 100 { 101 RTE_SET_USED(opt); 102 int i; 103 uint64_t total = 0; 104 struct test_perf *t = evt_test_priv(test); 105 106 printf("Packet distribution across worker cores :\n"); 107 for (i = 0; i < t->nb_workers; i++) 108 total += t->worker[i].processed_pkts; 109 for (i = 0; i < t->nb_workers; i++) 110 printf("Worker %d packets: "CLGRN"%"PRIx64" "CLNRM"percentage:" 111 CLGRN" %3.2f"CLNRM"\n", i, 112 t->worker[i].processed_pkts, 113 (((double)t->worker[i].processed_pkts)/total) 114 * 100); 115 116 return t->result; 117 } 118 119 static inline int 120 perf_producer(void *arg) 121 { 122 int i; 123 struct prod_data *p = arg; 124 struct test_perf *t = p->t; 125 struct evt_options *opt = t->opt; 126 const uint8_t dev_id = p->dev_id; 127 const uint8_t port = p->port_id; 128 struct rte_mempool *pool = t->pool; 129 const uint64_t nb_pkts = t->nb_pkts; 130 const uint32_t nb_flows = t->nb_flows; 131 uint32_t flow_counter = 0; 132 uint64_t count = 0; 133 struct perf_elt *m[BURST_SIZE + 1] = {NULL}; 134 uint8_t enable_fwd_latency; 135 struct rte_event ev; 136 137 enable_fwd_latency = opt->fwd_latency; 138 if (opt->verbose_level > 1) 139 printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__, 140 rte_lcore_id(), dev_id, port, p->queue_id); 141 142 ev.event = 0; 143 ev.op = RTE_EVENT_OP_NEW; 144 ev.queue_id = p->queue_id; 145 ev.sched_type = t->opt->sched_type_list[0]; 146 ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL; 147 ev.event_type = RTE_EVENT_TYPE_CPU; 148 ev.sub_event_type = 0; /* stage 0 */ 149 150 while (count < nb_pkts && t->done == false) { 151 if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0) 152 continue; 153 for (i = 0; i < BURST_SIZE; i++) { 154 ev.flow_id = flow_counter++ % nb_flows; 155 ev.event_ptr = m[i]; 156 if (enable_fwd_latency) 157 m[i]->timestamp = rte_get_timer_cycles(); 158 while (rte_event_enqueue_new_burst(dev_id, port, &ev, 159 1) != 1) { 160 if (t->done) 161 break; 162 rte_pause(); 163 if (enable_fwd_latency) 164 m[i]->timestamp = 165 rte_get_timer_cycles(); 166 } 167 } 168 count += BURST_SIZE; 169 } 170 171 return 0; 172 } 173 174 static inline int 175 perf_producer_burst(void *arg) 176 { 177 uint32_t i; 178 uint64_t timestamp; 179 struct prod_data *p = arg; 180 struct test_perf *t = p->t; 181 struct evt_options *opt = t->opt; 182 const uint8_t dev_id = p->dev_id; 183 const uint8_t port = p->port_id; 184 struct rte_mempool *pool = t->pool; 185 const uint64_t nb_pkts = t->nb_pkts; 186 const uint32_t nb_flows = t->nb_flows; 187 uint32_t flow_counter = 0; 188 uint16_t enq = 0; 189 uint64_t count = 0; 190 struct perf_elt *m[opt->prod_enq_burst_sz + 1]; 191 struct rte_event ev[opt->prod_enq_burst_sz + 1]; 192 uint32_t burst_size = opt->prod_enq_burst_sz; 193 uint8_t enable_fwd_latency; 194 195 enable_fwd_latency = opt->fwd_latency; 196 memset(m, 0, sizeof(*m) * (opt->prod_enq_burst_sz + 1)); 197 if (opt->verbose_level > 1) 198 printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__, 199 rte_lcore_id(), dev_id, port, p->queue_id); 200 201 for (i = 0; i < burst_size; i++) { 202 ev[i].op = RTE_EVENT_OP_NEW; 203 ev[i].queue_id = p->queue_id; 204 ev[i].sched_type = t->opt->sched_type_list[0]; 205 ev[i].priority = RTE_EVENT_DEV_PRIORITY_NORMAL; 206 ev[i].event_type = RTE_EVENT_TYPE_CPU; 207 ev[i].sub_event_type = 0; /* stage 0 */ 208 } 209 210 while (count < nb_pkts && t->done == false) { 211 if (rte_mempool_get_bulk(pool, (void **)m, burst_size) < 0) 212 continue; 213 timestamp = rte_get_timer_cycles(); 214 for (i = 0; i < burst_size; i++) { 215 ev[i].flow_id = flow_counter++ % nb_flows; 216 ev[i].event_ptr = m[i]; 217 if (enable_fwd_latency) 218 m[i]->timestamp = timestamp; 219 } 220 enq = rte_event_enqueue_new_burst(dev_id, port, ev, burst_size); 221 while (enq < burst_size) { 222 enq += rte_event_enqueue_new_burst( 223 dev_id, port, ev + enq, burst_size - enq); 224 if (t->done) 225 break; 226 rte_pause(); 227 if (enable_fwd_latency) { 228 timestamp = rte_get_timer_cycles(); 229 for (i = enq; i < burst_size; i++) 230 m[i]->timestamp = timestamp; 231 } 232 } 233 count += burst_size; 234 } 235 return 0; 236 } 237 238 static inline int 239 perf_event_timer_producer(void *arg) 240 { 241 int i; 242 struct prod_data *p = arg; 243 struct test_perf *t = p->t; 244 struct evt_options *opt = t->opt; 245 uint32_t flow_counter = 0; 246 uint64_t count = 0; 247 uint64_t arm_latency = 0; 248 const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs; 249 const uint32_t nb_flows = t->nb_flows; 250 const uint64_t nb_timers = opt->nb_timers; 251 struct rte_mempool *pool = t->pool; 252 struct perf_elt *m[BURST_SIZE + 1] = {NULL}; 253 struct rte_event_timer_adapter **adptr = t->timer_adptr; 254 struct rte_event_timer tim; 255 uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec; 256 257 memset(&tim, 0, sizeof(struct rte_event_timer)); 258 timeout_ticks = 259 opt->optm_timer_tick_nsec 260 ? ceil((double)(timeout_ticks * opt->timer_tick_nsec) / 261 opt->optm_timer_tick_nsec) 262 : timeout_ticks; 263 timeout_ticks += timeout_ticks ? 0 : 1; 264 tim.ev.event_type = RTE_EVENT_TYPE_TIMER; 265 tim.ev.op = RTE_EVENT_OP_NEW; 266 tim.ev.sched_type = t->opt->sched_type_list[0]; 267 tim.ev.queue_id = p->queue_id; 268 tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL; 269 tim.state = RTE_EVENT_TIMER_NOT_ARMED; 270 tim.timeout_ticks = timeout_ticks; 271 272 if (opt->verbose_level > 1) 273 printf("%s(): lcore %d\n", __func__, rte_lcore_id()); 274 275 while (count < nb_timers && t->done == false) { 276 if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0) 277 continue; 278 for (i = 0; i < BURST_SIZE; i++) { 279 rte_prefetch0(m[i + 1]); 280 m[i]->tim = tim; 281 m[i]->tim.ev.flow_id = flow_counter++ % nb_flows; 282 m[i]->tim.ev.event_ptr = m[i]; 283 m[i]->timestamp = rte_get_timer_cycles(); 284 while (rte_event_timer_arm_burst( 285 adptr[flow_counter % nb_timer_adptrs], 286 (struct rte_event_timer **)&m[i], 1) != 1) { 287 if (t->done) 288 break; 289 m[i]->timestamp = rte_get_timer_cycles(); 290 } 291 arm_latency += rte_get_timer_cycles() - m[i]->timestamp; 292 } 293 count += BURST_SIZE; 294 } 295 fflush(stdout); 296 rte_delay_ms(1000); 297 printf("%s(): lcore %d Average event timer arm latency = %.3f us\n", 298 __func__, rte_lcore_id(), 299 count ? (float)(arm_latency / count) / 300 (rte_get_timer_hz() / 1000000) : 0); 301 return 0; 302 } 303 304 static inline int 305 perf_event_timer_producer_burst(void *arg) 306 { 307 int i; 308 struct prod_data *p = arg; 309 struct test_perf *t = p->t; 310 struct evt_options *opt = t->opt; 311 uint32_t flow_counter = 0; 312 uint64_t count = 0; 313 uint64_t arm_latency = 0; 314 const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs; 315 const uint32_t nb_flows = t->nb_flows; 316 const uint64_t nb_timers = opt->nb_timers; 317 struct rte_mempool *pool = t->pool; 318 struct perf_elt *m[BURST_SIZE + 1] = {NULL}; 319 struct rte_event_timer_adapter **adptr = t->timer_adptr; 320 struct rte_event_timer tim; 321 uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec; 322 323 memset(&tim, 0, sizeof(struct rte_event_timer)); 324 timeout_ticks = 325 opt->optm_timer_tick_nsec 326 ? ceil((double)(timeout_ticks * opt->timer_tick_nsec) / 327 opt->optm_timer_tick_nsec) 328 : timeout_ticks; 329 timeout_ticks += timeout_ticks ? 0 : 1; 330 tim.ev.event_type = RTE_EVENT_TYPE_TIMER; 331 tim.ev.op = RTE_EVENT_OP_NEW; 332 tim.ev.sched_type = t->opt->sched_type_list[0]; 333 tim.ev.queue_id = p->queue_id; 334 tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL; 335 tim.state = RTE_EVENT_TIMER_NOT_ARMED; 336 tim.timeout_ticks = timeout_ticks; 337 338 if (opt->verbose_level > 1) 339 printf("%s(): lcore %d\n", __func__, rte_lcore_id()); 340 341 while (count < nb_timers && t->done == false) { 342 if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0) 343 continue; 344 for (i = 0; i < BURST_SIZE; i++) { 345 rte_prefetch0(m[i + 1]); 346 m[i]->tim = tim; 347 m[i]->tim.ev.flow_id = flow_counter++ % nb_flows; 348 m[i]->tim.ev.event_ptr = m[i]; 349 m[i]->timestamp = rte_get_timer_cycles(); 350 } 351 rte_event_timer_arm_tmo_tick_burst( 352 adptr[flow_counter % nb_timer_adptrs], 353 (struct rte_event_timer **)m, 354 tim.timeout_ticks, 355 BURST_SIZE); 356 arm_latency += rte_get_timer_cycles() - m[i - 1]->timestamp; 357 count += BURST_SIZE; 358 } 359 fflush(stdout); 360 rte_delay_ms(1000); 361 printf("%s(): lcore %d Average event timer arm latency = %.3f us\n", 362 __func__, rte_lcore_id(), 363 count ? (float)(arm_latency / count) / 364 (rte_get_timer_hz() / 1000000) : 0); 365 return 0; 366 } 367 368 static inline void 369 crypto_adapter_enq_op_new(struct prod_data *p) 370 { 371 struct test_perf *t = p->t; 372 const uint32_t nb_flows = t->nb_flows; 373 const uint64_t nb_pkts = t->nb_pkts; 374 struct rte_mempool *pool = t->pool; 375 uint16_t data_length, data_offset; 376 struct evt_options *opt = t->opt; 377 uint16_t qp_id = p->ca.cdev_qp_id; 378 uint8_t cdev_id = p->ca.cdev_id; 379 uint64_t alloc_failures = 0; 380 uint32_t flow_counter = 0; 381 struct rte_crypto_op *op; 382 uint16_t len, offset; 383 struct rte_mbuf *m; 384 uint64_t count = 0; 385 386 if (opt->verbose_level > 1) 387 printf("%s(): lcore %d queue %d cdev_id %u cdev_qp_id %u\n", 388 __func__, rte_lcore_id(), p->queue_id, p->ca.cdev_id, 389 p->ca.cdev_qp_id); 390 391 offset = sizeof(struct perf_elt); 392 len = RTE_MAX(RTE_ETHER_MIN_LEN + offset, opt->mbuf_sz); 393 394 if (opt->crypto_cipher_bit_mode) { 395 data_offset = offset << 3; 396 data_length = (len - offset) << 3; 397 } else { 398 data_offset = offset; 399 data_length = len - offset; 400 } 401 402 while (count < nb_pkts && t->done == false) { 403 if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) { 404 struct rte_crypto_sym_op *sym_op; 405 406 op = rte_crypto_op_alloc(t->ca_op_pool, 407 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 408 if (unlikely(op == NULL)) { 409 alloc_failures++; 410 continue; 411 } 412 413 m = rte_pktmbuf_alloc(pool); 414 if (unlikely(m == NULL)) { 415 alloc_failures++; 416 rte_crypto_op_free(op); 417 continue; 418 } 419 420 rte_pktmbuf_append(m, len); 421 sym_op = op->sym; 422 sym_op->m_src = m; 423 424 sym_op->cipher.data.offset = data_offset; 425 sym_op->cipher.data.length = data_length; 426 427 rte_crypto_op_attach_sym_session( 428 op, p->ca.crypto_sess[flow_counter++ % nb_flows]); 429 } else { 430 struct rte_crypto_asym_op *asym_op; 431 uint8_t *result; 432 433 if (rte_mempool_get(pool, (void **)&result)) { 434 alloc_failures++; 435 continue; 436 } 437 438 op = rte_crypto_op_alloc(t->ca_op_pool, 439 RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 440 if (unlikely(op == NULL)) { 441 alloc_failures++; 442 rte_mempool_put(pool, result); 443 continue; 444 } 445 446 asym_op = op->asym; 447 asym_op->modex.base.data = modex_test_case.base.data; 448 asym_op->modex.base.length = modex_test_case.base.len; 449 asym_op->modex.result.data = result; 450 asym_op->modex.result.length = modex_test_case.result_len; 451 rte_crypto_op_attach_asym_session( 452 op, p->ca.crypto_sess[flow_counter++ % nb_flows]); 453 } 454 while (rte_cryptodev_enqueue_burst(cdev_id, qp_id, &op, 1) != 1 && 455 t->done == false) 456 rte_pause(); 457 458 count++; 459 } 460 461 if (opt->verbose_level > 1 && alloc_failures) 462 printf("%s(): lcore %d allocation failures: %"PRIu64"\n", 463 __func__, rte_lcore_id(), alloc_failures); 464 } 465 466 static inline void 467 crypto_adapter_enq_op_fwd(struct prod_data *p) 468 { 469 const uint8_t dev_id = p->dev_id; 470 const uint8_t port = p->port_id; 471 struct test_perf *t = p->t; 472 const uint32_t nb_flows = t->nb_flows; 473 const uint64_t nb_pkts = t->nb_pkts; 474 struct rte_mempool *pool = t->pool; 475 struct evt_options *opt = t->opt; 476 uint64_t alloc_failures = 0; 477 uint32_t flow_counter = 0; 478 struct rte_crypto_op *op; 479 uint16_t len, offset; 480 struct rte_event ev; 481 struct rte_mbuf *m; 482 uint64_t count = 0; 483 484 if (opt->verbose_level > 1) 485 printf("%s(): lcore %d port %d queue %d cdev_id %u cdev_qp_id %u\n", 486 __func__, rte_lcore_id(), port, p->queue_id, 487 p->ca.cdev_id, p->ca.cdev_qp_id); 488 489 ev.event = 0; 490 ev.op = RTE_EVENT_OP_NEW; 491 ev.queue_id = p->queue_id; 492 ev.sched_type = RTE_SCHED_TYPE_ATOMIC; 493 ev.event_type = RTE_EVENT_TYPE_CPU; 494 495 offset = sizeof(struct perf_elt); 496 len = RTE_MAX(RTE_ETHER_MIN_LEN + offset, opt->mbuf_sz); 497 498 while (count < nb_pkts && t->done == false) { 499 if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) { 500 struct rte_crypto_sym_op *sym_op; 501 502 op = rte_crypto_op_alloc(t->ca_op_pool, 503 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 504 if (unlikely(op == NULL)) { 505 alloc_failures++; 506 continue; 507 } 508 509 m = rte_pktmbuf_alloc(pool); 510 if (unlikely(m == NULL)) { 511 alloc_failures++; 512 rte_crypto_op_free(op); 513 continue; 514 } 515 516 rte_pktmbuf_append(m, len); 517 sym_op = op->sym; 518 sym_op->m_src = m; 519 sym_op->cipher.data.offset = offset; 520 sym_op->cipher.data.length = len - offset; 521 rte_crypto_op_attach_sym_session( 522 op, p->ca.crypto_sess[flow_counter++ % nb_flows]); 523 } else { 524 struct rte_crypto_asym_op *asym_op; 525 uint8_t *result; 526 527 if (rte_mempool_get(pool, (void **)&result)) { 528 alloc_failures++; 529 continue; 530 } 531 532 op = rte_crypto_op_alloc(t->ca_op_pool, 533 RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 534 if (unlikely(op == NULL)) { 535 alloc_failures++; 536 rte_mempool_put(pool, result); 537 continue; 538 } 539 540 asym_op = op->asym; 541 asym_op->modex.base.data = modex_test_case.base.data; 542 asym_op->modex.base.length = modex_test_case.base.len; 543 asym_op->modex.result.data = result; 544 asym_op->modex.result.length = modex_test_case.result_len; 545 rte_crypto_op_attach_asym_session( 546 op, p->ca.crypto_sess[flow_counter++ % nb_flows]); 547 } 548 ev.event_ptr = op; 549 550 while (rte_event_crypto_adapter_enqueue(dev_id, port, &ev, 1) != 1 && 551 t->done == false) 552 rte_pause(); 553 554 count++; 555 } 556 557 if (opt->verbose_level > 1 && alloc_failures) 558 printf("%s(): lcore %d allocation failures: %"PRIu64"\n", 559 __func__, rte_lcore_id(), alloc_failures); 560 } 561 562 static inline void 563 dma_adapter_enq_op_fwd(struct prod_data *p) 564 { 565 struct test_perf *t = p->t; 566 const uint32_t nb_flows = t->nb_flows; 567 const uint64_t nb_pkts = t->nb_pkts; 568 struct rte_event_dma_adapter_op *op; 569 const uint8_t dev_id = p->dev_id; 570 struct evt_options *opt = t->opt; 571 const uint8_t port = p->port_id; 572 uint32_t flow_counter = 0; 573 struct rte_event ev; 574 uint64_t count = 0; 575 576 if (opt->verbose_level > 1) 577 printf("%s(): lcore %d port %d queue %d dma_dev_id %u dma_dev_vchan_id %u\n", 578 __func__, rte_lcore_id(), port, p->queue_id, 579 p->da.dma_dev_id, p->da.vchan_id); 580 581 ev.event = 0; 582 ev.op = RTE_EVENT_OP_NEW; 583 ev.queue_id = p->queue_id; 584 ev.sched_type = RTE_SCHED_TYPE_ATOMIC; 585 ev.event_type = RTE_EVENT_TYPE_CPU; 586 587 while (count < nb_pkts && t->done == false) { 588 op = p->da.dma_op[flow_counter++ % nb_flows]; 589 ev.event_ptr = op; 590 591 while (rte_event_dma_adapter_enqueue(dev_id, port, &ev, 1) != 1 && 592 t->done == false) 593 rte_pause(); 594 595 count++; 596 } 597 } 598 599 static inline int 600 perf_event_dma_producer(void *arg) 601 { 602 struct prod_data *p = arg; 603 604 /* Only fwd mode is supported. */ 605 dma_adapter_enq_op_fwd(p); 606 607 return 0; 608 } 609 610 static inline int 611 perf_event_crypto_producer(void *arg) 612 { 613 struct prod_data *p = arg; 614 struct evt_options *opt = p->t->opt; 615 616 if (opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW) 617 crypto_adapter_enq_op_new(p); 618 else 619 crypto_adapter_enq_op_fwd(p); 620 621 return 0; 622 } 623 624 static void 625 crypto_adapter_enq_op_new_burst(struct prod_data *p) 626 { 627 const struct test_perf *t = p->t; 628 const struct evt_options *opt = t->opt; 629 630 struct rte_mbuf *m, *pkts_burst[MAX_PROD_ENQ_BURST_SIZE]; 631 struct rte_crypto_op *ops_burst[MAX_PROD_ENQ_BURST_SIZE]; 632 const uint32_t burst_size = opt->prod_enq_burst_sz; 633 uint8_t *result[MAX_PROD_ENQ_BURST_SIZE]; 634 const uint32_t nb_flows = t->nb_flows; 635 const uint64_t nb_pkts = t->nb_pkts; 636 uint16_t len, enq, nb_alloc, offset; 637 struct rte_mempool *pool = t->pool; 638 uint16_t qp_id = p->ca.cdev_qp_id; 639 uint8_t cdev_id = p->ca.cdev_id; 640 uint64_t alloc_failures = 0; 641 uint32_t flow_counter = 0; 642 uint64_t count = 0; 643 uint32_t i; 644 645 if (opt->verbose_level > 1) 646 printf("%s(): lcore %d queue %d cdev_id %u cdev_qp_id %u\n", 647 __func__, rte_lcore_id(), p->queue_id, p->ca.cdev_id, 648 p->ca.cdev_qp_id); 649 650 offset = sizeof(struct perf_elt); 651 len = RTE_MAX(RTE_ETHER_MIN_LEN + offset, opt->mbuf_sz); 652 653 while (count < nb_pkts && t->done == false) { 654 if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) { 655 struct rte_crypto_sym_op *sym_op; 656 int ret; 657 658 nb_alloc = rte_crypto_op_bulk_alloc(t->ca_op_pool, 659 RTE_CRYPTO_OP_TYPE_SYMMETRIC, ops_burst, burst_size); 660 if (unlikely(nb_alloc != burst_size)) { 661 alloc_failures++; 662 continue; 663 } 664 665 ret = rte_pktmbuf_alloc_bulk(pool, pkts_burst, burst_size); 666 if (unlikely(ret != 0)) { 667 alloc_failures++; 668 rte_mempool_put_bulk(t->ca_op_pool, (void **)ops_burst, burst_size); 669 continue; 670 } 671 672 for (i = 0; i < burst_size; i++) { 673 m = pkts_burst[i]; 674 rte_pktmbuf_append(m, len); 675 sym_op = ops_burst[i]->sym; 676 sym_op->m_src = m; 677 sym_op->cipher.data.offset = offset; 678 sym_op->cipher.data.length = len - offset; 679 rte_crypto_op_attach_sym_session(ops_burst[i], 680 p->ca.crypto_sess[flow_counter++ % nb_flows]); 681 } 682 } else { 683 struct rte_crypto_asym_op *asym_op; 684 685 nb_alloc = rte_crypto_op_bulk_alloc(t->ca_op_pool, 686 RTE_CRYPTO_OP_TYPE_ASYMMETRIC, ops_burst, burst_size); 687 if (unlikely(nb_alloc != burst_size)) { 688 alloc_failures++; 689 continue; 690 } 691 692 if (rte_mempool_get_bulk(pool, (void **)result, burst_size)) { 693 alloc_failures++; 694 rte_mempool_put_bulk(t->ca_op_pool, (void **)ops_burst, burst_size); 695 continue; 696 } 697 698 for (i = 0; i < burst_size; i++) { 699 asym_op = ops_burst[i]->asym; 700 asym_op->modex.base.data = modex_test_case.base.data; 701 asym_op->modex.base.length = modex_test_case.base.len; 702 asym_op->modex.result.data = result[i]; 703 asym_op->modex.result.length = modex_test_case.result_len; 704 rte_crypto_op_attach_asym_session(ops_burst[i], 705 p->ca.crypto_sess[flow_counter++ % nb_flows]); 706 } 707 } 708 709 enq = 0; 710 while (!t->done) { 711 enq += rte_cryptodev_enqueue_burst(cdev_id, qp_id, ops_burst + enq, 712 burst_size - enq); 713 if (enq == burst_size) 714 break; 715 } 716 717 count += burst_size; 718 } 719 720 if (opt->verbose_level > 1 && alloc_failures) 721 printf("%s(): lcore %d allocation failures: %"PRIu64"\n", 722 __func__, rte_lcore_id(), alloc_failures); 723 } 724 725 static void 726 crypto_adapter_enq_op_fwd_burst(struct prod_data *p) 727 { 728 const struct test_perf *t = p->t; 729 const struct evt_options *opt = t->opt; 730 731 struct rte_mbuf *m, *pkts_burst[MAX_PROD_ENQ_BURST_SIZE]; 732 struct rte_crypto_op *ops_burst[MAX_PROD_ENQ_BURST_SIZE]; 733 const uint32_t burst_size = opt->prod_enq_burst_sz; 734 struct rte_event ev[MAX_PROD_ENQ_BURST_SIZE]; 735 uint8_t *result[MAX_PROD_ENQ_BURST_SIZE]; 736 const uint32_t nb_flows = t->nb_flows; 737 const uint64_t nb_pkts = t->nb_pkts; 738 uint16_t len, enq, nb_alloc, offset; 739 struct rte_mempool *pool = t->pool; 740 const uint8_t dev_id = p->dev_id; 741 const uint8_t port = p->port_id; 742 uint64_t alloc_failures = 0; 743 uint32_t flow_counter = 0; 744 uint64_t count = 0; 745 uint32_t i; 746 747 if (opt->verbose_level > 1) 748 printf("%s(): lcore %d port %d queue %d cdev_id %u cdev_qp_id %u\n", 749 __func__, rte_lcore_id(), port, p->queue_id, 750 p->ca.cdev_id, p->ca.cdev_qp_id); 751 752 offset = sizeof(struct perf_elt); 753 len = RTE_MAX(RTE_ETHER_MIN_LEN + offset, opt->mbuf_sz); 754 755 for (i = 0; i < burst_size; i++) { 756 ev[i].event = 0; 757 ev[i].op = RTE_EVENT_OP_NEW; 758 ev[i].queue_id = p->queue_id; 759 ev[i].sched_type = RTE_SCHED_TYPE_ATOMIC; 760 ev[i].event_type = RTE_EVENT_TYPE_CPU; 761 } 762 763 while (count < nb_pkts && t->done == false) { 764 if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) { 765 struct rte_crypto_sym_op *sym_op; 766 int ret; 767 768 nb_alloc = rte_crypto_op_bulk_alloc(t->ca_op_pool, 769 RTE_CRYPTO_OP_TYPE_SYMMETRIC, ops_burst, burst_size); 770 if (unlikely(nb_alloc != burst_size)) { 771 alloc_failures++; 772 continue; 773 } 774 775 ret = rte_pktmbuf_alloc_bulk(pool, pkts_burst, burst_size); 776 if (unlikely(ret != 0)) { 777 alloc_failures++; 778 rte_mempool_put_bulk(t->ca_op_pool, (void **)ops_burst, burst_size); 779 continue; 780 } 781 782 for (i = 0; i < burst_size; i++) { 783 m = pkts_burst[i]; 784 rte_pktmbuf_append(m, len); 785 sym_op = ops_burst[i]->sym; 786 sym_op->m_src = m; 787 sym_op->cipher.data.offset = offset; 788 sym_op->cipher.data.length = len - offset; 789 rte_crypto_op_attach_sym_session(ops_burst[i], 790 p->ca.crypto_sess[flow_counter++ % nb_flows]); 791 ev[i].event_ptr = ops_burst[i]; 792 } 793 } else { 794 struct rte_crypto_asym_op *asym_op; 795 796 nb_alloc = rte_crypto_op_bulk_alloc(t->ca_op_pool, 797 RTE_CRYPTO_OP_TYPE_ASYMMETRIC, ops_burst, burst_size); 798 if (unlikely(nb_alloc != burst_size)) { 799 alloc_failures++; 800 continue; 801 } 802 803 if (rte_mempool_get_bulk(pool, (void **)result, burst_size)) { 804 alloc_failures++; 805 rte_mempool_put_bulk(t->ca_op_pool, (void **)ops_burst, burst_size); 806 continue; 807 } 808 809 for (i = 0; i < burst_size; i++) { 810 asym_op = ops_burst[i]->asym; 811 asym_op->modex.base.data = modex_test_case.base.data; 812 asym_op->modex.base.length = modex_test_case.base.len; 813 asym_op->modex.result.data = result[i]; 814 asym_op->modex.result.length = modex_test_case.result_len; 815 rte_crypto_op_attach_asym_session(ops_burst[i], 816 p->ca.crypto_sess[flow_counter++ % nb_flows]); 817 ev[i].event_ptr = ops_burst[i]; 818 } 819 } 820 821 enq = 0; 822 while (!t->done) { 823 enq += rte_event_crypto_adapter_enqueue(dev_id, port, ev + enq, 824 burst_size - enq); 825 if (enq == burst_size) 826 break; 827 } 828 829 count += burst_size; 830 } 831 832 if (opt->verbose_level > 1 && alloc_failures) 833 printf("%s(): lcore %d allocation failures: %"PRIu64"\n", 834 __func__, rte_lcore_id(), alloc_failures); 835 } 836 837 static inline int 838 perf_event_crypto_producer_burst(void *arg) 839 { 840 struct prod_data *p = arg; 841 struct evt_options *opt = p->t->opt; 842 843 if (opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW) 844 crypto_adapter_enq_op_new_burst(p); 845 else 846 crypto_adapter_enq_op_fwd_burst(p); 847 848 return 0; 849 } 850 851 static int 852 perf_producer_wrapper(void *arg) 853 { 854 struct rte_event_dev_info dev_info; 855 struct prod_data *p = arg; 856 struct test_perf *t = p->t; 857 858 rte_event_dev_info_get(p->dev_id, &dev_info); 859 if (!t->opt->prod_enq_burst_sz) { 860 t->opt->prod_enq_burst_sz = MAX_PROD_ENQ_BURST_SIZE; 861 if (dev_info.max_event_port_enqueue_depth > 0 && 862 (uint32_t)dev_info.max_event_port_enqueue_depth < 863 t->opt->prod_enq_burst_sz) 864 t->opt->prod_enq_burst_sz = 865 dev_info.max_event_port_enqueue_depth; 866 } 867 868 /* In case of synthetic producer, launch perf_producer or 869 * perf_producer_burst depending on producer enqueue burst size 870 */ 871 if (t->opt->prod_type == EVT_PROD_TYPE_SYNT && 872 t->opt->prod_enq_burst_sz == 1) 873 return perf_producer(arg); 874 else if (t->opt->prod_type == EVT_PROD_TYPE_SYNT && 875 t->opt->prod_enq_burst_sz > 1) { 876 if (dev_info.max_event_port_enqueue_depth == 1) 877 evt_err("This event device does not support burst mode"); 878 else 879 return perf_producer_burst(arg); 880 } 881 else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR && 882 !t->opt->timdev_use_burst) 883 return perf_event_timer_producer(arg); 884 else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR && 885 t->opt->timdev_use_burst) 886 return perf_event_timer_producer_burst(arg); 887 else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) { 888 if (t->opt->prod_enq_burst_sz > 1) 889 return perf_event_crypto_producer_burst(arg); 890 else 891 return perf_event_crypto_producer(arg); 892 } else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_DMA_ADPTR) 893 return perf_event_dma_producer(arg); 894 895 return 0; 896 } 897 898 static inline uint64_t 899 processed_pkts(struct test_perf *t) 900 { 901 uint8_t i; 902 uint64_t total = 0; 903 904 for (i = 0; i < t->nb_workers; i++) 905 total += t->worker[i].processed_pkts; 906 907 return total; 908 } 909 910 static inline uint64_t 911 total_latency(struct test_perf *t) 912 { 913 uint8_t i; 914 uint64_t total = 0; 915 916 for (i = 0; i < t->nb_workers; i++) 917 total += t->worker[i].latency; 918 919 return total; 920 } 921 922 923 int 924 perf_launch_lcores(struct evt_test *test, struct evt_options *opt, 925 int (*worker)(void *)) 926 { 927 int ret, lcore_id; 928 struct test_perf *t = evt_test_priv(test); 929 930 int port_idx = 0; 931 /* launch workers */ 932 RTE_LCORE_FOREACH_WORKER(lcore_id) { 933 if (!(opt->wlcores[lcore_id])) 934 continue; 935 936 ret = rte_eal_remote_launch(worker, 937 &t->worker[port_idx], lcore_id); 938 if (ret) { 939 evt_err("failed to launch worker %d", lcore_id); 940 return ret; 941 } 942 port_idx++; 943 } 944 945 /* launch producers */ 946 RTE_LCORE_FOREACH_WORKER(lcore_id) { 947 if (!(opt->plcores[lcore_id])) 948 continue; 949 950 ret = rte_eal_remote_launch(perf_producer_wrapper, 951 &t->prod[port_idx], lcore_id); 952 if (ret) { 953 evt_err("failed to launch perf_producer %d", lcore_id); 954 return ret; 955 } 956 port_idx++; 957 } 958 959 const uint64_t total_pkts = t->outstand_pkts; 960 961 uint64_t dead_lock_cycles = rte_get_timer_cycles(); 962 int64_t dead_lock_remaining = total_pkts; 963 const uint64_t dead_lock_sample = rte_get_timer_hz() * 5; 964 965 uint64_t perf_cycles = rte_get_timer_cycles(); 966 int64_t perf_remaining = total_pkts; 967 const uint64_t perf_sample = rte_get_timer_hz(); 968 969 static float total_mpps; 970 static uint64_t samples; 971 972 const uint64_t freq_mhz = rte_get_timer_hz() / 1000000; 973 int64_t remaining = t->outstand_pkts - processed_pkts(t); 974 975 while (t->done == false) { 976 const uint64_t new_cycles = rte_get_timer_cycles(); 977 978 if ((new_cycles - perf_cycles) > perf_sample) { 979 const uint64_t latency = total_latency(t); 980 const uint64_t pkts = processed_pkts(t); 981 982 remaining = t->outstand_pkts - pkts; 983 float mpps = (float)(perf_remaining-remaining)/1000000; 984 985 perf_remaining = remaining; 986 perf_cycles = new_cycles; 987 total_mpps += mpps; 988 ++samples; 989 if (opt->fwd_latency && pkts > 0) { 990 printf(CLGRN"\r%.3f mpps avg %.3f mpps [avg fwd latency %.3f us] "CLNRM, 991 mpps, total_mpps/samples, 992 (float)(latency/pkts)/freq_mhz); 993 } else { 994 printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM, 995 mpps, total_mpps/samples); 996 } 997 fflush(stdout); 998 999 if (remaining <= 0) { 1000 t->result = EVT_TEST_SUCCESS; 1001 if (opt->prod_type == EVT_PROD_TYPE_SYNT || 1002 opt->prod_type == 1003 EVT_PROD_TYPE_EVENT_TIMER_ADPTR || 1004 opt->prod_type == 1005 EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR || 1006 opt->prod_type == 1007 EVT_PROD_TYPE_EVENT_DMA_ADPTR) { 1008 t->done = true; 1009 break; 1010 } 1011 } 1012 } 1013 1014 if (new_cycles - dead_lock_cycles > dead_lock_sample && 1015 (opt->prod_type == EVT_PROD_TYPE_SYNT || 1016 opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR || 1017 opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR || 1018 opt->prod_type == EVT_PROD_TYPE_EVENT_DMA_ADPTR)) { 1019 remaining = t->outstand_pkts - processed_pkts(t); 1020 if (dead_lock_remaining == remaining) { 1021 rte_event_dev_dump(opt->dev_id, stdout); 1022 evt_err("No schedules for seconds, deadlock"); 1023 t->done = true; 1024 break; 1025 } 1026 dead_lock_remaining = remaining; 1027 dead_lock_cycles = new_cycles; 1028 } 1029 } 1030 printf("\n"); 1031 return 0; 1032 } 1033 1034 static int 1035 perf_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride, 1036 struct rte_event_port_conf prod_conf) 1037 { 1038 int ret = 0; 1039 uint16_t prod; 1040 struct rte_event_eth_rx_adapter_queue_conf queue_conf; 1041 1042 memset(&queue_conf, 0, 1043 sizeof(struct rte_event_eth_rx_adapter_queue_conf)); 1044 queue_conf.ev.sched_type = opt->sched_type_list[0]; 1045 RTE_ETH_FOREACH_DEV(prod) { 1046 uint32_t cap; 1047 1048 ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id, 1049 prod, &cap); 1050 if (ret) { 1051 evt_err("failed to get event rx adapter[%d]" 1052 " capabilities", 1053 opt->dev_id); 1054 return ret; 1055 } 1056 queue_conf.ev.queue_id = prod * stride; 1057 ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id, 1058 &prod_conf); 1059 if (ret) { 1060 evt_err("failed to create rx adapter[%d]", prod); 1061 return ret; 1062 } 1063 ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1, 1064 &queue_conf); 1065 if (ret) { 1066 evt_err("failed to add rx queues to adapter[%d]", prod); 1067 return ret; 1068 } 1069 1070 if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) { 1071 uint32_t service_id; 1072 1073 rte_event_eth_rx_adapter_service_id_get(prod, 1074 &service_id); 1075 ret = evt_service_setup(service_id); 1076 if (ret) { 1077 evt_err("Failed to setup service core" 1078 " for Rx adapter\n"); 1079 return ret; 1080 } 1081 } 1082 } 1083 1084 return ret; 1085 } 1086 1087 static int 1088 perf_event_timer_adapter_setup(struct test_perf *t) 1089 { 1090 int i; 1091 int ret; 1092 struct rte_event_timer_adapter_info adapter_info; 1093 struct rte_event_timer_adapter *wl; 1094 uint8_t nb_producers = evt_nr_active_lcores(t->opt->plcores); 1095 uint8_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES; 1096 1097 if (nb_producers == 1) 1098 flags |= RTE_EVENT_TIMER_ADAPTER_F_SP_PUT; 1099 1100 for (i = 0; i < t->opt->nb_timer_adptrs; i++) { 1101 struct rte_event_timer_adapter_conf config = { 1102 .event_dev_id = t->opt->dev_id, 1103 .timer_adapter_id = i, 1104 .timer_tick_ns = t->opt->timer_tick_nsec, 1105 .max_tmo_ns = t->opt->max_tmo_nsec, 1106 .nb_timers = t->opt->pool_sz, 1107 .flags = flags, 1108 }; 1109 1110 wl = rte_event_timer_adapter_create(&config); 1111 if (wl == NULL) { 1112 evt_err("failed to create event timer ring %d", i); 1113 return rte_errno; 1114 } 1115 1116 memset(&adapter_info, 0, 1117 sizeof(struct rte_event_timer_adapter_info)); 1118 rte_event_timer_adapter_get_info(wl, &adapter_info); 1119 t->opt->optm_timer_tick_nsec = adapter_info.min_resolution_ns; 1120 1121 if (!(adapter_info.caps & 1122 RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT)) { 1123 uint32_t service_id = -1U; 1124 1125 rte_event_timer_adapter_service_id_get(wl, 1126 &service_id); 1127 ret = evt_service_setup(service_id); 1128 if (ret) { 1129 evt_err("Failed to setup service core" 1130 " for timer adapter\n"); 1131 return ret; 1132 } 1133 rte_service_runstate_set(service_id, 1); 1134 } 1135 t->timer_adptr[i] = wl; 1136 } 1137 return 0; 1138 } 1139 1140 static int 1141 perf_event_crypto_adapter_setup(struct test_perf *t, struct prod_data *p) 1142 { 1143 struct rte_event_crypto_adapter_queue_conf conf; 1144 struct evt_options *opt = t->opt; 1145 uint32_t cap; 1146 int ret; 1147 1148 memset(&conf, 0, sizeof(conf)); 1149 1150 ret = rte_event_crypto_adapter_caps_get(p->dev_id, p->ca.cdev_id, &cap); 1151 if (ret) { 1152 evt_err("Failed to get crypto adapter capabilities"); 1153 return ret; 1154 } 1155 1156 if (((opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW) && 1157 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW)) || 1158 ((opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_FORWARD) && 1159 !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))) { 1160 evt_err("crypto adapter %s mode unsupported\n", 1161 opt->crypto_adptr_mode ? "OP_FORWARD" : "OP_NEW"); 1162 return -ENOTSUP; 1163 } else if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA)) { 1164 evt_err("Storing crypto session not supported"); 1165 return -ENOTSUP; 1166 } 1167 1168 if (opt->ena_vector) { 1169 struct rte_event_crypto_adapter_vector_limits limits; 1170 1171 if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_EVENT_VECTOR)) { 1172 evt_err("Crypto adapter doesn't support event vector"); 1173 return -EINVAL; 1174 } 1175 1176 ret = rte_event_crypto_adapter_vector_limits_get(p->dev_id, p->ca.cdev_id, &limits); 1177 if (ret) { 1178 evt_err("Failed to get crypto adapter's vector limits"); 1179 return ret; 1180 } 1181 1182 if (opt->vector_size < limits.min_sz || opt->vector_size > limits.max_sz) { 1183 evt_err("Vector size [%d] not within limits max[%d] min[%d]", 1184 opt->vector_size, limits.max_sz, limits.min_sz); 1185 return -EINVAL; 1186 } 1187 1188 if (limits.log2_sz && !rte_is_power_of_2(opt->vector_size)) { 1189 evt_err("Vector size [%d] not power of 2", opt->vector_size); 1190 return -EINVAL; 1191 } 1192 1193 if (opt->vector_tmo_nsec > limits.max_timeout_ns || 1194 opt->vector_tmo_nsec < limits.min_timeout_ns) { 1195 evt_err("Vector timeout [%" PRIu64 "] not within limits " 1196 "max[%" PRIu64 "] min[%" PRIu64 "]", 1197 opt->vector_tmo_nsec, limits.max_timeout_ns, limits.min_timeout_ns); 1198 return -EINVAL; 1199 } 1200 1201 conf.vector_mp = t->ca_vector_pool; 1202 conf.vector_sz = opt->vector_size; 1203 conf.vector_timeout_ns = opt->vector_tmo_nsec; 1204 conf.flags |= RTE_EVENT_CRYPTO_ADAPTER_EVENT_VECTOR; 1205 } 1206 1207 if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND) { 1208 conf.ev.sched_type = RTE_SCHED_TYPE_ATOMIC; 1209 conf.ev.queue_id = p->queue_id; 1210 } 1211 1212 ret = rte_event_crypto_adapter_queue_pair_add( 1213 TEST_PERF_CA_ID, p->ca.cdev_id, p->ca.cdev_qp_id, &conf); 1214 1215 return ret; 1216 } 1217 1218 static int 1219 perf_event_dma_adapter_setup(struct test_perf *t, struct prod_data *p) 1220 { 1221 struct evt_options *opt = t->opt; 1222 struct rte_event event; 1223 uint32_t cap; 1224 int ret; 1225 1226 ret = rte_event_dma_adapter_caps_get(p->dev_id, p->da.dma_dev_id, &cap); 1227 if (ret) { 1228 evt_err("Failed to get dma adapter capabilities"); 1229 return ret; 1230 } 1231 1232 if (((opt->dma_adptr_mode == RTE_EVENT_DMA_ADAPTER_OP_NEW) && 1233 !(cap & RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_OP_NEW)) || 1234 ((opt->dma_adptr_mode == RTE_EVENT_DMA_ADAPTER_OP_FORWARD) && 1235 !(cap & RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))) { 1236 evt_err("dma adapter %s mode unsupported\n", 1237 opt->dma_adptr_mode ? "OP_FORWARD" : "OP_NEW"); 1238 return -ENOTSUP; 1239 } 1240 1241 if (cap & RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_VCHAN_EV_BIND) 1242 ret = rte_event_dma_adapter_vchan_add(TEST_PERF_DA_ID, p->da.dma_dev_id, 1243 p->da.vchan_id, &event); 1244 else 1245 ret = rte_event_dma_adapter_vchan_add(TEST_PERF_DA_ID, p->da.dma_dev_id, 1246 p->da.vchan_id, NULL); 1247 1248 return ret; 1249 } 1250 1251 static void * 1252 cryptodev_sym_sess_create(struct prod_data *p, struct test_perf *t) 1253 { 1254 const struct rte_cryptodev_symmetric_capability *cap; 1255 struct rte_cryptodev_sym_capability_idx cap_idx; 1256 enum rte_crypto_cipher_algorithm cipher_algo; 1257 struct rte_crypto_sym_xform cipher_xform; 1258 struct evt_options *opt = t->opt; 1259 uint16_t key_size; 1260 uint16_t iv_size; 1261 void *sess; 1262 1263 cipher_algo = opt->crypto_cipher_alg; 1264 key_size = opt->crypto_cipher_key_sz; 1265 iv_size = opt->crypto_cipher_iv_sz; 1266 1267 /* Check if device supports the algorithm */ 1268 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1269 cap_idx.algo.cipher = cipher_algo; 1270 1271 cap = rte_cryptodev_sym_capability_get(p->ca.cdev_id, &cap_idx); 1272 if (cap == NULL) { 1273 evt_err("Device doesn't support cipher algorithm [%s]. Test Skipped\n", 1274 rte_cryptodev_get_cipher_algo_string(cipher_algo)); 1275 return NULL; 1276 } 1277 1278 /* Check if device supports key size and IV size */ 1279 if (rte_cryptodev_sym_capability_check_cipher(cap, key_size, 1280 iv_size) < 0) { 1281 evt_err("Device doesn't support cipher configuration:\n" 1282 "cipher algo [%s], key sz [%d], iv sz [%d]. Test Skipped\n", 1283 rte_cryptodev_get_cipher_algo_string(cipher_algo), key_size, iv_size); 1284 return NULL; 1285 } 1286 1287 cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1288 cipher_xform.cipher.algo = cipher_algo; 1289 cipher_xform.cipher.key.data = opt->crypto_cipher_key; 1290 cipher_xform.cipher.key.length = key_size; 1291 cipher_xform.cipher.iv.length = iv_size; 1292 cipher_xform.cipher.iv.offset = IV_OFFSET; 1293 cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 1294 cipher_xform.next = NULL; 1295 1296 sess = rte_cryptodev_sym_session_create(p->ca.cdev_id, &cipher_xform, 1297 t->ca_sess_pool); 1298 if (sess == NULL) { 1299 evt_err("Failed to create sym session"); 1300 return NULL; 1301 } 1302 1303 return sess; 1304 } 1305 1306 static void * 1307 cryptodev_asym_sess_create(struct prod_data *p, struct test_perf *t) 1308 { 1309 const struct rte_cryptodev_asymmetric_xform_capability *capability; 1310 struct rte_cryptodev_asym_capability_idx cap_idx; 1311 struct rte_crypto_asym_xform xform; 1312 void *sess; 1313 1314 xform.next = NULL; 1315 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX; 1316 cap_idx.type = xform.xform_type; 1317 capability = rte_cryptodev_asym_capability_get(p->ca.cdev_id, &cap_idx); 1318 if (capability == NULL) { 1319 evt_err("Device doesn't support MODEX. Test Skipped\n"); 1320 return NULL; 1321 } 1322 1323 xform.modex.modulus.data = modex_test_case.modulus.data; 1324 xform.modex.modulus.length = modex_test_case.modulus.len; 1325 xform.modex.exponent.data = modex_test_case.exponent.data; 1326 xform.modex.exponent.length = modex_test_case.exponent.len; 1327 1328 if (rte_cryptodev_asym_session_create(p->ca.cdev_id, &xform, 1329 t->ca_asym_sess_pool, &sess)) { 1330 evt_err("Failed to create asym session"); 1331 return NULL; 1332 } 1333 1334 return sess; 1335 } 1336 1337 int 1338 perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt, 1339 uint8_t stride, uint8_t nb_queues, 1340 const struct rte_event_port_conf *port_conf) 1341 { 1342 struct test_perf *t = evt_test_priv(test); 1343 uint16_t port, prod; 1344 int ret = -1; 1345 1346 /* setup one port per worker, linking to all queues */ 1347 for (port = 0; port < evt_nr_active_lcores(opt->wlcores); 1348 port++) { 1349 struct worker_data *w = &t->worker[port]; 1350 1351 w->dev_id = opt->dev_id; 1352 w->port_id = port; 1353 w->t = t; 1354 w->processed_pkts = 0; 1355 w->latency = 0; 1356 1357 struct rte_event_port_conf conf = *port_conf; 1358 conf.event_port_cfg |= RTE_EVENT_PORT_CFG_HINT_WORKER; 1359 1360 ret = rte_event_port_setup(opt->dev_id, port, &conf); 1361 if (ret) { 1362 evt_err("failed to setup port %d", port); 1363 return ret; 1364 } 1365 1366 ret = rte_event_port_link(opt->dev_id, port, NULL, NULL, 0); 1367 if (ret != nb_queues) { 1368 evt_err("failed to link all queues to port %d", port); 1369 return -EINVAL; 1370 } 1371 } 1372 1373 /* port for producers, no links */ 1374 if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) { 1375 for ( ; port < perf_nb_event_ports(opt); port++) { 1376 struct prod_data *p = &t->prod[port]; 1377 p->t = t; 1378 } 1379 1380 struct rte_event_port_conf conf = *port_conf; 1381 conf.event_port_cfg |= RTE_EVENT_PORT_CFG_HINT_PRODUCER; 1382 1383 ret = perf_event_rx_adapter_setup(opt, stride, conf); 1384 if (ret) 1385 return ret; 1386 } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 1387 prod = 0; 1388 for ( ; port < perf_nb_event_ports(opt); port++) { 1389 struct prod_data *p = &t->prod[port]; 1390 p->queue_id = prod * stride; 1391 p->t = t; 1392 prod++; 1393 } 1394 1395 ret = perf_event_timer_adapter_setup(t); 1396 if (ret) 1397 return ret; 1398 } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) { 1399 struct rte_event_port_conf conf = *port_conf; 1400 uint8_t cdev_id = 0; 1401 uint16_t qp_id = 0; 1402 1403 ret = rte_event_crypto_adapter_create(TEST_PERF_CA_ID, 1404 opt->dev_id, &conf, 0); 1405 if (ret) { 1406 evt_err("Failed to create crypto adapter"); 1407 return ret; 1408 } 1409 1410 prod = 0; 1411 for (; port < perf_nb_event_ports(opt); port++) { 1412 union rte_event_crypto_metadata m_data; 1413 struct prod_data *p = &t->prod[port]; 1414 uint32_t flow_id; 1415 1416 if (qp_id == rte_cryptodev_queue_pair_count(cdev_id)) { 1417 cdev_id++; 1418 qp_id = 0; 1419 } 1420 1421 p->dev_id = opt->dev_id; 1422 p->port_id = port; 1423 p->queue_id = prod * stride; 1424 p->ca.cdev_id = cdev_id; 1425 p->ca.cdev_qp_id = qp_id; 1426 p->ca.crypto_sess = rte_zmalloc_socket( 1427 NULL, sizeof(void *) * t->nb_flows, 1428 RTE_CACHE_LINE_SIZE, opt->socket_id); 1429 p->t = t; 1430 1431 ret = perf_event_crypto_adapter_setup(t, p); 1432 if (ret) 1433 return ret; 1434 1435 m_data.request_info.cdev_id = p->ca.cdev_id; 1436 m_data.request_info.queue_pair_id = p->ca.cdev_qp_id; 1437 m_data.response_info.sched_type = RTE_SCHED_TYPE_ATOMIC; 1438 m_data.response_info.queue_id = p->queue_id; 1439 1440 for (flow_id = 0; flow_id < t->nb_flows; flow_id++) { 1441 m_data.response_info.flow_id = flow_id; 1442 if (opt->crypto_op_type == 1443 RTE_CRYPTO_OP_TYPE_SYMMETRIC) { 1444 void *sess; 1445 1446 sess = cryptodev_sym_sess_create(p, t); 1447 if (sess == NULL) 1448 return -ENOMEM; 1449 1450 ret = rte_cryptodev_session_event_mdata_set( 1451 cdev_id, 1452 sess, 1453 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 1454 RTE_CRYPTO_OP_WITH_SESSION, 1455 &m_data, sizeof(m_data)); 1456 if (ret) 1457 return ret; 1458 p->ca.crypto_sess[flow_id] = sess; 1459 } else { 1460 void *sess; 1461 1462 sess = cryptodev_asym_sess_create(p, t); 1463 if (sess == NULL) 1464 return -ENOMEM; 1465 ret = rte_cryptodev_session_event_mdata_set( 1466 cdev_id, 1467 sess, 1468 RTE_CRYPTO_OP_TYPE_ASYMMETRIC, 1469 RTE_CRYPTO_OP_WITH_SESSION, 1470 &m_data, sizeof(m_data)); 1471 if (ret) 1472 return ret; 1473 p->ca.crypto_sess[flow_id] = sess; 1474 } 1475 } 1476 1477 conf.event_port_cfg |= 1478 RTE_EVENT_PORT_CFG_HINT_PRODUCER | 1479 RTE_EVENT_PORT_CFG_HINT_CONSUMER; 1480 1481 ret = rte_event_port_setup(opt->dev_id, port, &conf); 1482 if (ret) { 1483 evt_err("failed to setup port %d", port); 1484 return ret; 1485 } 1486 1487 qp_id++; 1488 prod++; 1489 } 1490 } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_DMA_ADPTR) { 1491 struct rte_event_port_conf conf = *port_conf; 1492 struct rte_event_dma_adapter_op *op; 1493 struct rte_mempool *pool = t->pool; 1494 uint8_t dma_dev_id = 0; 1495 uint16_t vchan_id = 0; 1496 1497 ret = rte_event_dma_adapter_create(TEST_PERF_DA_ID, opt->dev_id, &conf, 0); 1498 if (ret) { 1499 evt_err("Failed to create dma adapter"); 1500 return ret; 1501 } 1502 1503 prod = 0; 1504 for (; port < perf_nb_event_ports(opt); port++) { 1505 struct prod_data *p = &t->prod[port]; 1506 struct rte_event *response_info; 1507 uint32_t flow_id; 1508 1509 p->dev_id = opt->dev_id; 1510 p->port_id = port; 1511 p->queue_id = prod * stride; 1512 p->da.dma_dev_id = dma_dev_id; 1513 p->da.vchan_id = vchan_id; 1514 p->da.dma_op = rte_zmalloc_socket(NULL, sizeof(void *) * t->nb_flows, 1515 RTE_CACHE_LINE_SIZE, opt->socket_id); 1516 1517 p->t = t; 1518 1519 ret = perf_event_dma_adapter_setup(t, p); 1520 if (ret) 1521 return ret; 1522 1523 for (flow_id = 0; flow_id < t->nb_flows; flow_id++) { 1524 rte_mempool_get(t->da_op_pool, (void **)&op); 1525 1526 op->src_seg = rte_malloc(NULL, sizeof(struct rte_dma_sge), 0); 1527 op->dst_seg = rte_malloc(NULL, sizeof(struct rte_dma_sge), 0); 1528 1529 op->src_seg->addr = rte_pktmbuf_iova(rte_pktmbuf_alloc(pool)); 1530 op->dst_seg->addr = rte_pktmbuf_iova(rte_pktmbuf_alloc(pool)); 1531 op->src_seg->length = 1024; 1532 op->dst_seg->length = 1024; 1533 op->nb_src = 1; 1534 op->nb_dst = 1; 1535 op->flags = RTE_DMA_OP_FLAG_SUBMIT; 1536 op->op_mp = t->da_op_pool; 1537 op->dma_dev_id = dma_dev_id; 1538 op->vchan = vchan_id; 1539 1540 response_info = (struct rte_event *)((uint8_t *)op + 1541 sizeof(struct rte_event_dma_adapter_op)); 1542 response_info->queue_id = p->queue_id; 1543 response_info->sched_type = RTE_SCHED_TYPE_ATOMIC; 1544 response_info->flow_id = flow_id; 1545 1546 p->da.dma_op[flow_id] = op; 1547 } 1548 1549 conf.event_port_cfg |= 1550 RTE_EVENT_PORT_CFG_HINT_PRODUCER | 1551 RTE_EVENT_PORT_CFG_HINT_CONSUMER; 1552 1553 ret = rte_event_port_setup(opt->dev_id, port, &conf); 1554 if (ret) { 1555 evt_err("failed to setup port %d", port); 1556 return ret; 1557 } 1558 1559 prod++; 1560 } 1561 } else { 1562 prod = 0; 1563 for ( ; port < perf_nb_event_ports(opt); port++) { 1564 struct prod_data *p = &t->prod[port]; 1565 1566 p->dev_id = opt->dev_id; 1567 p->port_id = port; 1568 p->queue_id = prod * stride; 1569 p->t = t; 1570 1571 struct rte_event_port_conf conf = *port_conf; 1572 conf.event_port_cfg |= 1573 RTE_EVENT_PORT_CFG_HINT_PRODUCER | 1574 RTE_EVENT_PORT_CFG_HINT_CONSUMER; 1575 1576 ret = rte_event_port_setup(opt->dev_id, port, &conf); 1577 if (ret) { 1578 evt_err("failed to setup port %d", port); 1579 return ret; 1580 } 1581 prod++; 1582 } 1583 } 1584 1585 return ret; 1586 } 1587 1588 int 1589 perf_opt_check(struct evt_options *opt, uint64_t nb_queues) 1590 { 1591 unsigned int lcores; 1592 1593 /* N producer + N worker + main when producer cores are used 1594 * Else N worker + main when Rx adapter is used 1595 */ 1596 lcores = opt->prod_type == EVT_PROD_TYPE_SYNT ? 3 : 2; 1597 1598 if (rte_lcore_count() < lcores) { 1599 evt_err("test need minimum %d lcores", lcores); 1600 return -1; 1601 } 1602 1603 /* Validate worker lcores */ 1604 if (evt_lcores_has_overlap(opt->wlcores, rte_get_main_lcore())) { 1605 evt_err("worker lcores overlaps with main lcore"); 1606 return -1; 1607 } 1608 if (evt_lcores_has_overlap_multi(opt->wlcores, opt->plcores)) { 1609 evt_err("worker lcores overlaps producer lcores"); 1610 return -1; 1611 } 1612 if (evt_has_disabled_lcore(opt->wlcores)) { 1613 evt_err("one or more workers lcores are not enabled"); 1614 return -1; 1615 } 1616 if (!evt_has_active_lcore(opt->wlcores)) { 1617 evt_err("minimum one worker is required"); 1618 return -1; 1619 } 1620 1621 if (opt->prod_type == EVT_PROD_TYPE_SYNT || 1622 opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR || 1623 opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR || 1624 opt->prod_type == EVT_PROD_TYPE_EVENT_DMA_ADPTR) { 1625 /* Validate producer lcores */ 1626 if (evt_lcores_has_overlap(opt->plcores, 1627 rte_get_main_lcore())) { 1628 evt_err("producer lcores overlaps with main lcore"); 1629 return -1; 1630 } 1631 if (evt_has_disabled_lcore(opt->plcores)) { 1632 evt_err("one or more producer lcores are not enabled"); 1633 return -1; 1634 } 1635 if (!evt_has_active_lcore(opt->plcores)) { 1636 evt_err("minimum one producer is required"); 1637 return -1; 1638 } 1639 } 1640 1641 if (evt_has_invalid_stage(opt)) 1642 return -1; 1643 1644 if (evt_has_invalid_sched_type(opt)) 1645 return -1; 1646 1647 if (nb_queues > EVT_MAX_QUEUES) { 1648 evt_err("number of queues exceeds %d", EVT_MAX_QUEUES); 1649 return -1; 1650 } 1651 if (perf_nb_event_ports(opt) > EVT_MAX_PORTS) { 1652 evt_err("number of ports exceeds %d", EVT_MAX_PORTS); 1653 return -1; 1654 } 1655 1656 /* Fixups */ 1657 if ((opt->nb_stages == 1 && 1658 opt->prod_type != EVT_PROD_TYPE_EVENT_TIMER_ADPTR) && 1659 opt->fwd_latency) { 1660 evt_info("fwd_latency is valid when nb_stages > 1, disabling"); 1661 opt->fwd_latency = 0; 1662 } 1663 1664 if (opt->fwd_latency && !opt->q_priority) { 1665 evt_info("enabled queue priority for latency measurement"); 1666 opt->q_priority = 1; 1667 } 1668 if (opt->nb_pkts == 0) 1669 opt->nb_pkts = INT64_MAX/evt_nr_active_lcores(opt->plcores); 1670 1671 return 0; 1672 } 1673 1674 void 1675 perf_opt_dump(struct evt_options *opt, uint8_t nb_queues) 1676 { 1677 evt_dump("nb_prod_lcores", "%d", evt_nr_active_lcores(opt->plcores)); 1678 evt_dump_producer_lcores(opt); 1679 evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores)); 1680 evt_dump_worker_lcores(opt); 1681 evt_dump_nb_stages(opt); 1682 evt_dump("nb_evdev_ports", "%d", perf_nb_event_ports(opt)); 1683 evt_dump("nb_evdev_queues", "%d", nb_queues); 1684 evt_dump_queue_priority(opt); 1685 evt_dump_sched_type_list(opt); 1686 evt_dump_producer_type(opt); 1687 evt_dump("prod_enq_burst_sz", "%d", opt->prod_enq_burst_sz); 1688 } 1689 1690 static void 1691 perf_event_port_flush(uint8_t dev_id __rte_unused, struct rte_event ev, 1692 void *args) 1693 { 1694 rte_mempool_put(args, ev.event_ptr); 1695 } 1696 1697 void 1698 perf_worker_cleanup(struct rte_mempool *const pool, uint8_t dev_id, 1699 uint8_t port_id, struct rte_event events[], uint16_t nb_enq, 1700 uint16_t nb_deq) 1701 { 1702 int i; 1703 1704 if (nb_deq) { 1705 for (i = nb_enq; i < nb_deq; i++) 1706 rte_mempool_put(pool, events[i].event_ptr); 1707 1708 for (i = 0; i < nb_deq; i++) 1709 events[i].op = RTE_EVENT_OP_RELEASE; 1710 rte_event_enqueue_burst(dev_id, port_id, events, nb_deq); 1711 } 1712 rte_event_port_quiesce(dev_id, port_id, perf_event_port_flush, pool); 1713 } 1714 1715 void 1716 perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt) 1717 { 1718 int i; 1719 struct test_perf *t = evt_test_priv(test); 1720 1721 if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 1722 for (i = 0; i < opt->nb_timer_adptrs; i++) 1723 rte_event_timer_adapter_stop(t->timer_adptr[i]); 1724 } 1725 rte_event_dev_stop(opt->dev_id); 1726 rte_event_dev_close(opt->dev_id); 1727 } 1728 1729 static inline void 1730 perf_elt_init(struct rte_mempool *mp, void *arg __rte_unused, 1731 void *obj, unsigned i __rte_unused) 1732 { 1733 memset(obj, 0, mp->elt_size); 1734 } 1735 1736 #define NB_RX_DESC 128 1737 #define NB_TX_DESC 512 1738 int 1739 perf_ethdev_setup(struct evt_test *test, struct evt_options *opt) 1740 { 1741 uint16_t i; 1742 int ret; 1743 struct test_perf *t = evt_test_priv(test); 1744 struct rte_eth_conf port_conf = { 1745 .rxmode = { 1746 .mq_mode = RTE_ETH_MQ_RX_RSS, 1747 }, 1748 .rx_adv_conf = { 1749 .rss_conf = { 1750 .rss_key = NULL, 1751 .rss_hf = RTE_ETH_RSS_IP, 1752 }, 1753 }, 1754 }; 1755 1756 if (opt->prod_type != EVT_PROD_TYPE_ETH_RX_ADPTR) 1757 return 0; 1758 1759 if (!rte_eth_dev_count_avail()) { 1760 evt_err("No ethernet ports found."); 1761 return -ENODEV; 1762 } 1763 1764 RTE_ETH_FOREACH_DEV(i) { 1765 struct rte_eth_dev_info dev_info; 1766 struct rte_eth_conf local_port_conf = port_conf; 1767 1768 ret = rte_eth_dev_info_get(i, &dev_info); 1769 if (ret != 0) { 1770 evt_err("Error during getting device (port %u) info: %s\n", 1771 i, strerror(-ret)); 1772 return ret; 1773 } 1774 1775 local_port_conf.rx_adv_conf.rss_conf.rss_hf &= 1776 dev_info.flow_type_rss_offloads; 1777 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf != 1778 port_conf.rx_adv_conf.rss_conf.rss_hf) { 1779 evt_info("Port %u modified RSS hash function based on hardware support," 1780 "requested:%#"PRIx64" configured:%#"PRIx64"\n", 1781 i, 1782 port_conf.rx_adv_conf.rss_conf.rss_hf, 1783 local_port_conf.rx_adv_conf.rss_conf.rss_hf); 1784 } 1785 1786 if (rte_eth_dev_configure(i, 1, 1, &local_port_conf) < 0) { 1787 evt_err("Failed to configure eth port [%d]", i); 1788 return -EINVAL; 1789 } 1790 1791 if (rte_eth_rx_queue_setup(i, 0, NB_RX_DESC, 1792 rte_socket_id(), NULL, t->pool) < 0) { 1793 evt_err("Failed to setup eth port [%d] rx_queue: %d.", 1794 i, 0); 1795 return -EINVAL; 1796 } 1797 1798 if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC, 1799 rte_socket_id(), NULL) < 0) { 1800 evt_err("Failed to setup eth port [%d] tx_queue: %d.", 1801 i, 0); 1802 return -EINVAL; 1803 } 1804 1805 ret = rte_eth_promiscuous_enable(i); 1806 if (ret != 0) { 1807 evt_err("Failed to enable promiscuous mode for eth port [%d]: %s", 1808 i, rte_strerror(-ret)); 1809 return ret; 1810 } 1811 } 1812 1813 return 0; 1814 } 1815 1816 void 1817 perf_ethdev_rx_stop(struct evt_test *test, struct evt_options *opt) 1818 { 1819 uint16_t i; 1820 RTE_SET_USED(test); 1821 1822 if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) { 1823 RTE_ETH_FOREACH_DEV(i) { 1824 rte_event_eth_rx_adapter_stop(i); 1825 rte_event_eth_rx_adapter_queue_del(i, i, -1); 1826 rte_eth_dev_rx_queue_stop(i, 0); 1827 } 1828 } 1829 } 1830 1831 void 1832 perf_ethdev_destroy(struct evt_test *test, struct evt_options *opt) 1833 { 1834 uint16_t i; 1835 RTE_SET_USED(test); 1836 1837 if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) { 1838 RTE_ETH_FOREACH_DEV(i) { 1839 rte_event_eth_tx_adapter_stop(i); 1840 rte_event_eth_tx_adapter_queue_del(i, i, -1); 1841 rte_eth_dev_tx_queue_stop(i, 0); 1842 rte_eth_dev_stop(i); 1843 } 1844 } 1845 } 1846 1847 int 1848 perf_cryptodev_setup(struct evt_test *test, struct evt_options *opt) 1849 { 1850 uint8_t cdev_count, cdev_id, nb_plcores, nb_qps; 1851 struct test_perf *t = evt_test_priv(test); 1852 unsigned int max_session_size; 1853 uint32_t nb_sessions; 1854 int ret; 1855 1856 if (opt->prod_type != EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) 1857 return 0; 1858 1859 cdev_count = rte_cryptodev_count(); 1860 if (cdev_count == 0) { 1861 evt_err("No crypto devices available\n"); 1862 return -ENODEV; 1863 } 1864 1865 t->ca_op_pool = rte_crypto_op_pool_create( 1866 "crypto_op_pool", opt->crypto_op_type, opt->pool_sz, 1867 128, sizeof(union rte_event_crypto_metadata) + EVT_CRYPTO_MAX_IV_SIZE, 1868 rte_socket_id()); 1869 if (t->ca_op_pool == NULL) { 1870 evt_err("Failed to create crypto op pool"); 1871 return -ENOMEM; 1872 } 1873 1874 nb_sessions = evt_nr_active_lcores(opt->plcores) * t->nb_flows; 1875 t->ca_asym_sess_pool = rte_cryptodev_asym_session_pool_create( 1876 "ca_asym_sess_pool", nb_sessions, 0, 1877 sizeof(union rte_event_crypto_metadata), SOCKET_ID_ANY); 1878 if (t->ca_asym_sess_pool == NULL) { 1879 evt_err("Failed to create sym session pool"); 1880 ret = -ENOMEM; 1881 goto err; 1882 } 1883 1884 max_session_size = 0; 1885 for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) { 1886 unsigned int session_size; 1887 1888 session_size = 1889 rte_cryptodev_sym_get_private_session_size(cdev_id); 1890 if (session_size > max_session_size) 1891 max_session_size = session_size; 1892 } 1893 1894 t->ca_sess_pool = rte_cryptodev_sym_session_pool_create( 1895 "ca_sess_pool", nb_sessions, max_session_size, 0, 1896 sizeof(union rte_event_crypto_metadata), SOCKET_ID_ANY); 1897 if (t->ca_sess_pool == NULL) { 1898 evt_err("Failed to create sym session pool"); 1899 ret = -ENOMEM; 1900 goto err; 1901 } 1902 1903 if (opt->ena_vector) { 1904 unsigned int nb_elem = (opt->pool_sz / opt->vector_size) * 2; 1905 nb_elem = RTE_MAX(512U, nb_elem); 1906 nb_elem += evt_nr_active_lcores(opt->wlcores) * 32; 1907 t->ca_vector_pool = rte_event_vector_pool_create("vector_pool", nb_elem, 32, 1908 opt->vector_size, opt->socket_id); 1909 if (t->ca_vector_pool == NULL) { 1910 evt_err("Failed to create event vector pool"); 1911 ret = -ENOMEM; 1912 goto err; 1913 } 1914 } 1915 1916 /* 1917 * Calculate number of needed queue pairs, based on the amount of 1918 * available number of logical cores and crypto devices. For instance, 1919 * if there are 4 cores and 2 crypto devices, 2 queue pairs will be set 1920 * up per device. 1921 */ 1922 nb_plcores = evt_nr_active_lcores(opt->plcores); 1923 nb_qps = (nb_plcores % cdev_count) ? (nb_plcores / cdev_count) + 1 : 1924 nb_plcores / cdev_count; 1925 for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) { 1926 struct rte_cryptodev_qp_conf qp_conf; 1927 struct rte_cryptodev_config conf; 1928 struct rte_cryptodev_info info; 1929 int qp_id; 1930 1931 rte_cryptodev_info_get(cdev_id, &info); 1932 if (nb_qps > info.max_nb_queue_pairs) { 1933 evt_err("Not enough queue pairs per cryptodev (%u)", 1934 nb_qps); 1935 ret = -EINVAL; 1936 goto err; 1937 } 1938 1939 conf.nb_queue_pairs = nb_qps; 1940 conf.socket_id = SOCKET_ID_ANY; 1941 conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 1942 1943 ret = rte_cryptodev_configure(cdev_id, &conf); 1944 if (ret) { 1945 evt_err("Failed to configure cryptodev (%u)", cdev_id); 1946 goto err; 1947 } 1948 1949 qp_conf.nb_descriptors = NB_CRYPTODEV_DESCRIPTORS; 1950 qp_conf.mp_session = t->ca_sess_pool; 1951 1952 for (qp_id = 0; qp_id < conf.nb_queue_pairs; qp_id++) { 1953 ret = rte_cryptodev_queue_pair_setup( 1954 cdev_id, qp_id, &qp_conf, 1955 rte_cryptodev_socket_id(cdev_id)); 1956 if (ret) { 1957 evt_err("Failed to setup queue pairs on cryptodev %u\n", 1958 cdev_id); 1959 goto err; 1960 } 1961 } 1962 } 1963 1964 return 0; 1965 err: 1966 for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) 1967 rte_cryptodev_close(cdev_id); 1968 1969 rte_mempool_free(t->ca_op_pool); 1970 rte_mempool_free(t->ca_sess_pool); 1971 rte_mempool_free(t->ca_asym_sess_pool); 1972 rte_mempool_free(t->ca_vector_pool); 1973 1974 return ret; 1975 } 1976 1977 void 1978 perf_cryptodev_destroy(struct evt_test *test, struct evt_options *opt) 1979 { 1980 uint8_t cdev_id, cdev_count = rte_cryptodev_count(); 1981 struct test_perf *t = evt_test_priv(test); 1982 uint16_t port; 1983 1984 if (opt->prod_type != EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) 1985 return; 1986 1987 for (port = t->nb_workers; port < perf_nb_event_ports(opt); port++) { 1988 void *sess; 1989 struct prod_data *p = &t->prod[port]; 1990 uint32_t flow_id; 1991 uint8_t cdev_id; 1992 1993 for (flow_id = 0; flow_id < t->nb_flows; flow_id++) { 1994 sess = p->ca.crypto_sess[flow_id]; 1995 cdev_id = p->ca.cdev_id; 1996 rte_cryptodev_sym_session_free(cdev_id, sess); 1997 } 1998 1999 rte_event_crypto_adapter_queue_pair_del( 2000 TEST_PERF_CA_ID, p->ca.cdev_id, p->ca.cdev_qp_id); 2001 } 2002 2003 rte_event_crypto_adapter_free(TEST_PERF_CA_ID); 2004 2005 for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) { 2006 rte_cryptodev_stop(cdev_id); 2007 rte_cryptodev_close(cdev_id); 2008 } 2009 2010 rte_mempool_free(t->ca_op_pool); 2011 rte_mempool_free(t->ca_sess_pool); 2012 rte_mempool_free(t->ca_asym_sess_pool); 2013 rte_mempool_free(t->ca_vector_pool); 2014 } 2015 2016 int 2017 perf_dmadev_setup(struct evt_test *test, struct evt_options *opt) 2018 { 2019 const struct rte_dma_conf conf = { .nb_vchans = 1}; 2020 const struct rte_dma_vchan_conf qconf = { 2021 .direction = RTE_DMA_DIR_MEM_TO_MEM, 2022 .nb_desc = 1024, 2023 }; 2024 struct test_perf *t = evt_test_priv(test); 2025 uint8_t dma_dev_count, dma_dev_id = 0; 2026 unsigned int elt_size; 2027 int vchan_id; 2028 int ret; 2029 2030 if (opt->prod_type != EVT_PROD_TYPE_EVENT_DMA_ADPTR) 2031 return 0; 2032 2033 dma_dev_count = rte_dma_count_avail(); 2034 if (dma_dev_count == 0) { 2035 evt_err("No dma devices available\n"); 2036 return -ENODEV; 2037 } 2038 2039 elt_size = sizeof(struct rte_event_dma_adapter_op) + sizeof(struct rte_event); 2040 t->da_op_pool = rte_mempool_create("dma_op_pool", opt->pool_sz, elt_size, 256, 2041 0, NULL, NULL, NULL, NULL, rte_socket_id(), 0); 2042 if (t->da_op_pool == NULL) { 2043 evt_err("Failed to create dma op pool"); 2044 return -ENOMEM; 2045 } 2046 2047 ret = rte_dma_configure(dma_dev_id, &conf); 2048 if (ret) { 2049 evt_err("Failed to configure dma dev (%u)", dma_dev_id); 2050 goto err; 2051 } 2052 2053 for (vchan_id = 0; vchan_id < conf.nb_vchans; vchan_id++) { 2054 ret = rte_dma_vchan_setup(dma_dev_id, vchan_id, &qconf); 2055 if (ret) { 2056 evt_err("Failed to setup vchan on dma dev %u\n", 2057 dma_dev_id); 2058 goto err; 2059 } 2060 } 2061 2062 return 0; 2063 err: 2064 rte_dma_close(dma_dev_id); 2065 rte_mempool_free(t->da_op_pool); 2066 2067 return ret; 2068 } 2069 2070 void 2071 perf_dmadev_destroy(struct evt_test *test, struct evt_options *opt) 2072 { 2073 uint8_t dma_dev_id = 0; 2074 struct test_perf *t = evt_test_priv(test); 2075 uint16_t port; 2076 2077 if (opt->prod_type != EVT_PROD_TYPE_EVENT_DMA_ADPTR) 2078 return; 2079 2080 for (port = t->nb_workers; port < perf_nb_event_ports(opt); port++) { 2081 struct prod_data *p = &t->prod[port]; 2082 struct rte_event_dma_adapter_op *op; 2083 uint32_t flow_id; 2084 2085 for (flow_id = 0; flow_id < t->nb_flows; flow_id++) { 2086 op = p->da.dma_op[flow_id]; 2087 2088 rte_pktmbuf_free((struct rte_mbuf *)(uintptr_t)op->src_seg->addr); 2089 rte_pktmbuf_free((struct rte_mbuf *)(uintptr_t)op->dst_seg->addr); 2090 rte_free(op->src_seg); 2091 rte_free(op->dst_seg); 2092 rte_mempool_put(op->op_mp, op); 2093 } 2094 2095 rte_event_dma_adapter_vchan_del(TEST_PERF_DA_ID, p->da.dma_dev_id, p->da.vchan_id); 2096 } 2097 2098 rte_event_dma_adapter_free(TEST_PERF_DA_ID); 2099 2100 rte_dma_stop(dma_dev_id); 2101 rte_dma_close(dma_dev_id); 2102 2103 rte_mempool_free(t->da_op_pool); 2104 } 2105 2106 int 2107 perf_mempool_setup(struct evt_test *test, struct evt_options *opt) 2108 { 2109 struct test_perf *t = evt_test_priv(test); 2110 unsigned int cache_sz; 2111 2112 cache_sz = RTE_MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, (opt->pool_sz / 1.5) / t->nb_workers); 2113 if (opt->prod_type == EVT_PROD_TYPE_SYNT || 2114 opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 2115 t->pool = rte_mempool_create(test->name, /* mempool name */ 2116 opt->pool_sz, /* number of elements*/ 2117 sizeof(struct perf_elt), /* element size*/ 2118 cache_sz, /* cache size*/ 2119 0, NULL, NULL, 2120 perf_elt_init, /* obj constructor */ 2121 NULL, opt->socket_id, 0); /* flags */ 2122 } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR && 2123 opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) { 2124 t->pool = rte_mempool_create(test->name, /* mempool name */ 2125 opt->pool_sz, /* number of elements*/ 2126 sizeof(struct perf_elt) + modex_test_case.result_len, 2127 /* element size*/ 2128 cache_sz, /* cache size*/ 2129 0, NULL, NULL, 2130 NULL, /* obj constructor */ 2131 NULL, opt->socket_id, 0); /* flags */ 2132 } else { 2133 t->pool = rte_pktmbuf_pool_create(test->name, /* mempool name */ 2134 opt->pool_sz, /* number of elements*/ 2135 cache_sz, /* cache size*/ 2136 0, 2137 RTE_MBUF_DEFAULT_BUF_SIZE, 2138 opt->socket_id); /* flags */ 2139 } 2140 2141 if (t->pool == NULL) { 2142 evt_err("failed to create mempool"); 2143 return -ENOMEM; 2144 } 2145 2146 return 0; 2147 } 2148 2149 void 2150 perf_mempool_destroy(struct evt_test *test, struct evt_options *opt) 2151 { 2152 RTE_SET_USED(opt); 2153 struct test_perf *t = evt_test_priv(test); 2154 2155 rte_mempool_free(t->pool); 2156 } 2157 2158 int 2159 perf_test_setup(struct evt_test *test, struct evt_options *opt) 2160 { 2161 void *test_perf; 2162 2163 test_perf = rte_zmalloc_socket(test->name, sizeof(struct test_perf), 2164 RTE_CACHE_LINE_SIZE, opt->socket_id); 2165 if (test_perf == NULL) { 2166 evt_err("failed to allocate test_perf memory"); 2167 goto nomem; 2168 } 2169 test->test_priv = test_perf; 2170 2171 struct test_perf *t = evt_test_priv(test); 2172 2173 if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) { 2174 t->outstand_pkts = opt->nb_timers * 2175 evt_nr_active_lcores(opt->plcores); 2176 t->nb_pkts = opt->nb_timers; 2177 } else { 2178 t->outstand_pkts = opt->nb_pkts * 2179 evt_nr_active_lcores(opt->plcores); 2180 t->nb_pkts = opt->nb_pkts; 2181 } 2182 2183 t->nb_workers = evt_nr_active_lcores(opt->wlcores); 2184 t->done = false; 2185 t->nb_flows = opt->nb_flows; 2186 t->result = EVT_TEST_FAILED; 2187 t->opt = opt; 2188 memcpy(t->sched_type_list, opt->sched_type_list, 2189 sizeof(opt->sched_type_list)); 2190 return 0; 2191 nomem: 2192 return -ENOMEM; 2193 } 2194 2195 void 2196 perf_test_destroy(struct evt_test *test, struct evt_options *opt) 2197 { 2198 RTE_SET_USED(opt); 2199 2200 rte_free(test->test_priv); 2201 } 2202