Branch data Line data Source code
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 : 0 : 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 : 0 : for (i = 0; i < t->nb_workers; i++)
108 : 0 : total += t->worker[i].processed_pkts;
109 : 0 : for (i = 0; i < t->nb_workers; i++)
110 : 0 : printf("Worker %d packets: "CLGRN"%"PRIx64" "CLNRM"percentage:"
111 : : CLGRN" %3.2f"CLNRM"\n", i,
112 : : t->worker[i].processed_pkts,
113 : 0 : (((double)t->worker[i].processed_pkts)/total)
114 : : * 100);
115 : :
116 : 0 : return t->result;
117 : : }
118 : :
119 : : static inline int
120 : 0 : perf_producer(void *arg)
121 : : {
122 : : int i;
123 : : struct prod_data *p = arg;
124 : 0 : struct test_perf *t = p->t;
125 : 0 : struct evt_options *opt = t->opt;
126 : 0 : const uint8_t dev_id = p->dev_id;
127 : 0 : const uint8_t port = p->port_id;
128 : 0 : struct rte_mempool *pool = t->pool;
129 : 0 : const uint64_t nb_pkts = t->nb_pkts;
130 : 0 : const uint32_t nb_flows = t->nb_flows;
131 : : uint32_t flow_counter = 0;
132 : : uint64_t count = 0;
133 : 0 : struct perf_elt *m[BURST_SIZE + 1] = {NULL};
134 : : uint8_t enable_fwd_latency;
135 : : struct rte_event ev;
136 : :
137 : 0 : enable_fwd_latency = opt->fwd_latency;
138 : 0 : if (opt->verbose_level > 1)
139 : 0 : printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__,
140 : 0 : rte_lcore_id(), dev_id, port, p->queue_id);
141 : :
142 : 0 : ev.event = 0;
143 : : ev.op = RTE_EVENT_OP_NEW;
144 : 0 : ev.queue_id = p->queue_id;
145 : 0 : ev.sched_type = t->opt->sched_type_list[0];
146 : 0 : ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
147 : 0 : ev.event_type = RTE_EVENT_TYPE_CPU;
148 : : ev.sub_event_type = 0; /* stage 0 */
149 : :
150 : 0 : while (count < nb_pkts && t->done == false) {
151 : 0 : if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0)
152 : 0 : continue;
153 : 0 : for (i = 0; i < BURST_SIZE; i++) {
154 : 0 : ev.flow_id = flow_counter++ % nb_flows;
155 : 0 : ev.event_ptr = m[i];
156 : 0 : if (enable_fwd_latency)
157 : 0 : m[i]->timestamp = rte_get_timer_cycles();
158 : 0 : while (rte_event_enqueue_new_burst(dev_id, port, &ev,
159 : 0 : 1) != 1) {
160 : 0 : if (t->done)
161 : : break;
162 : : rte_pause();
163 : 0 : if (enable_fwd_latency)
164 : 0 : m[i]->timestamp =
165 : : rte_get_timer_cycles();
166 : : }
167 : : }
168 : 0 : count += BURST_SIZE;
169 : : }
170 : :
171 : 0 : return 0;
172 : : }
173 : :
174 : : static inline int
175 : 0 : perf_producer_burst(void *arg)
176 : 0 : {
177 : : uint32_t i;
178 : : uint64_t timestamp;
179 : : struct prod_data *p = arg;
180 : 0 : struct test_perf *t = p->t;
181 : 0 : struct evt_options *opt = t->opt;
182 : 0 : const uint8_t dev_id = p->dev_id;
183 : 0 : const uint8_t port = p->port_id;
184 : 0 : struct rte_mempool *pool = t->pool;
185 : 0 : const uint64_t nb_pkts = t->nb_pkts;
186 : 0 : 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 : 0 : struct perf_elt *m[opt->prod_enq_burst_sz + 1];
191 : 0 : 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 : 0 : enable_fwd_latency = opt->fwd_latency;
196 : : memset(m, 0, sizeof(*m) * (opt->prod_enq_burst_sz + 1));
197 : 0 : if (opt->verbose_level > 1)
198 : 0 : printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__,
199 : 0 : rte_lcore_id(), dev_id, port, p->queue_id);
200 : :
201 : 0 : for (i = 0; i < burst_size; i++) {
202 : 0 : ev[i].op = RTE_EVENT_OP_NEW;
203 : 0 : ev[i].queue_id = p->queue_id;
204 : 0 : ev[i].sched_type = t->opt->sched_type_list[0];
205 : 0 : ev[i].priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
206 : 0 : ev[i].event_type = RTE_EVENT_TYPE_CPU;
207 : 0 : ev[i].sub_event_type = 0; /* stage 0 */
208 : : }
209 : :
210 : 0 : while (count < nb_pkts && t->done == false) {
211 : 0 : if (rte_mempool_get_bulk(pool, (void **)m, burst_size) < 0)
212 : 0 : continue;
213 : : timestamp = rte_get_timer_cycles();
214 : 0 : for (i = 0; i < burst_size; i++) {
215 : 0 : ev[i].flow_id = flow_counter++ % nb_flows;
216 : 0 : ev[i].event_ptr = m[i];
217 : 0 : if (enable_fwd_latency)
218 : 0 : m[i]->timestamp = timestamp;
219 : : }
220 : 0 : enq = rte_event_enqueue_new_burst(dev_id, port, ev, burst_size);
221 : 0 : while (enq < burst_size) {
222 : 0 : enq += rte_event_enqueue_new_burst(
223 : 0 : dev_id, port, ev + enq, burst_size - enq);
224 : 0 : if (t->done)
225 : : break;
226 : : rte_pause();
227 : 0 : if (enable_fwd_latency) {
228 : : timestamp = rte_get_timer_cycles();
229 : 0 : for (i = enq; i < burst_size; i++)
230 : 0 : m[i]->timestamp = timestamp;
231 : : }
232 : : }
233 : 0 : count += burst_size;
234 : : }
235 : 0 : return 0;
236 : : }
237 : :
238 : : static inline int
239 : 0 : perf_event_timer_producer(void *arg)
240 : : {
241 : : int i;
242 : : struct prod_data *p = arg;
243 : 0 : struct test_perf *t = p->t;
244 : 0 : struct evt_options *opt = t->opt;
245 : : uint32_t flow_counter = 0;
246 : : uint64_t count = 0;
247 : : uint64_t arm_latency = 0;
248 : 0 : const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs;
249 : 0 : const uint32_t nb_flows = t->nb_flows;
250 : 0 : const uint64_t nb_timers = opt->nb_timers;
251 : 0 : struct rte_mempool *pool = t->pool;
252 : 0 : struct perf_elt *m[BURST_SIZE + 1] = {NULL};
253 : 0 : struct rte_event_timer_adapter **adptr = t->timer_adptr;
254 : : struct rte_event_timer tim;
255 : 0 : uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec;
256 : :
257 : : memset(&tim, 0, sizeof(struct rte_event_timer));
258 : 0 : timeout_ticks =
259 : 0 : opt->optm_timer_tick_nsec
260 : 0 : ? ceil((double)(timeout_ticks * opt->timer_tick_nsec) /
261 : : opt->optm_timer_tick_nsec)
262 : : : timeout_ticks;
263 : 0 : timeout_ticks += timeout_ticks ? 0 : 1;
264 : 0 : tim.ev.event_type = RTE_EVENT_TYPE_TIMER;
265 : : tim.ev.op = RTE_EVENT_OP_NEW;
266 : 0 : tim.ev.sched_type = t->opt->sched_type_list[0];
267 : 0 : tim.ev.queue_id = p->queue_id;
268 : 0 : tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
269 : : tim.state = RTE_EVENT_TIMER_NOT_ARMED;
270 : 0 : tim.timeout_ticks = timeout_ticks;
271 : :
272 : 0 : if (opt->verbose_level > 1)
273 : : printf("%s(): lcore %d\n", __func__, rte_lcore_id());
274 : :
275 : 0 : while (count < nb_timers && t->done == false) {
276 : 0 : if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0)
277 : 0 : continue;
278 : 0 : for (i = 0; i < BURST_SIZE; i++) {
279 : 0 : rte_prefetch0(m[i + 1]);
280 : 0 : m[i]->tim = tim;
281 : 0 : m[i]->tim.ev.flow_id = flow_counter++ % nb_flows;
282 : 0 : m[i]->tim.ev.event_ptr = m[i];
283 : 0 : m[i]->timestamp = rte_get_timer_cycles();
284 : 0 : while (rte_event_timer_arm_burst(
285 : 0 : adptr[flow_counter % nb_timer_adptrs],
286 : 0 : (struct rte_event_timer **)&m[i], 1) != 1) {
287 : 0 : if (t->done)
288 : : break;
289 : 0 : m[i]->timestamp = rte_get_timer_cycles();
290 : : }
291 : 0 : arm_latency += rte_get_timer_cycles() - m[i]->timestamp;
292 : : }
293 : 0 : count += BURST_SIZE;
294 : : }
295 : 0 : fflush(stdout);
296 : : rte_delay_ms(1000);
297 : 0 : printf("%s(): lcore %d Average event timer arm latency = %.3f us\n",
298 : : __func__, rte_lcore_id(),
299 : 0 : count ? (float)(arm_latency / count) /
300 : 0 : (rte_get_timer_hz() / 1000000) : 0);
301 : 0 : return 0;
302 : : }
303 : :
304 : : static inline int
305 : 0 : perf_event_timer_producer_burst(void *arg)
306 : : {
307 : : int i;
308 : : struct prod_data *p = arg;
309 : 0 : struct test_perf *t = p->t;
310 : 0 : struct evt_options *opt = t->opt;
311 : : uint32_t flow_counter = 0;
312 : : uint64_t count = 0;
313 : : uint64_t arm_latency = 0;
314 : 0 : const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs;
315 : 0 : const uint32_t nb_flows = t->nb_flows;
316 : 0 : const uint64_t nb_timers = opt->nb_timers;
317 : 0 : struct rte_mempool *pool = t->pool;
318 : 0 : struct perf_elt *m[BURST_SIZE + 1] = {NULL};
319 : 0 : struct rte_event_timer_adapter **adptr = t->timer_adptr;
320 : : struct rte_event_timer tim;
321 : 0 : uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec;
322 : :
323 : : memset(&tim, 0, sizeof(struct rte_event_timer));
324 : 0 : timeout_ticks =
325 : 0 : opt->optm_timer_tick_nsec
326 : 0 : ? ceil((double)(timeout_ticks * opt->timer_tick_nsec) /
327 : : opt->optm_timer_tick_nsec)
328 : : : timeout_ticks;
329 : 0 : timeout_ticks += timeout_ticks ? 0 : 1;
330 : 0 : tim.ev.event_type = RTE_EVENT_TYPE_TIMER;
331 : : tim.ev.op = RTE_EVENT_OP_NEW;
332 : 0 : tim.ev.sched_type = t->opt->sched_type_list[0];
333 : 0 : tim.ev.queue_id = p->queue_id;
334 : 0 : tim.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
335 : : tim.state = RTE_EVENT_TIMER_NOT_ARMED;
336 : 0 : tim.timeout_ticks = timeout_ticks;
337 : :
338 : 0 : if (opt->verbose_level > 1)
339 : : printf("%s(): lcore %d\n", __func__, rte_lcore_id());
340 : :
341 : 0 : while (count < nb_timers && t->done == false) {
342 : 0 : if (rte_mempool_get_bulk(pool, (void **)m, BURST_SIZE) < 0)
343 : 0 : continue;
344 : 0 : for (i = 0; i < BURST_SIZE; i++) {
345 : 0 : rte_prefetch0(m[i + 1]);
346 : 0 : m[i]->tim = tim;
347 : 0 : m[i]->tim.ev.flow_id = flow_counter++ % nb_flows;
348 : 0 : m[i]->tim.ev.event_ptr = m[i];
349 : 0 : m[i]->timestamp = rte_get_timer_cycles();
350 : : }
351 : 0 : rte_event_timer_arm_tmo_tick_burst(
352 : 0 : adptr[flow_counter % nb_timer_adptrs],
353 : : (struct rte_event_timer **)m,
354 : : tim.timeout_ticks,
355 : : BURST_SIZE);
356 : 0 : arm_latency += rte_get_timer_cycles() - m[i - 1]->timestamp;
357 : 0 : count += BURST_SIZE;
358 : : }
359 : 0 : fflush(stdout);
360 : : rte_delay_ms(1000);
361 : 0 : printf("%s(): lcore %d Average event timer arm latency = %.3f us\n",
362 : : __func__, rte_lcore_id(),
363 : 0 : count ? (float)(arm_latency / count) /
364 : 0 : (rte_get_timer_hz() / 1000000) : 0);
365 : 0 : return 0;
366 : : }
367 : :
368 : : static inline void
369 : 0 : crypto_adapter_enq_op_new(struct prod_data *p)
370 : : {
371 : 0 : struct test_perf *t = p->t;
372 : 0 : const uint32_t nb_flows = t->nb_flows;
373 : 0 : const uint64_t nb_pkts = t->nb_pkts;
374 : 0 : struct rte_mempool *pool = t->pool;
375 : : uint16_t data_length, data_offset;
376 : 0 : struct evt_options *opt = t->opt;
377 : 0 : uint16_t qp_id = p->ca.cdev_qp_id;
378 : 0 : 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 : 0 : if (opt->verbose_level > 1)
387 : 0 : printf("%s(): lcore %d queue %d cdev_id %u cdev_qp_id %u\n",
388 : 0 : __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 : 0 : len = RTE_MAX(RTE_ETHER_MIN_LEN + offset, opt->mbuf_sz);
393 : :
394 : 0 : if (opt->crypto_cipher_bit_mode) {
395 : : data_offset = offset << 3;
396 : 0 : data_length = (len - offset) << 3;
397 : : } else {
398 : : data_offset = offset;
399 : 0 : data_length = len - offset;
400 : : }
401 : :
402 : 0 : while (count < nb_pkts && t->done == false) {
403 : 0 : if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
404 : : struct rte_crypto_sym_op *sym_op;
405 : :
406 : 0 : op = rte_crypto_op_alloc(t->ca_op_pool,
407 : : RTE_CRYPTO_OP_TYPE_SYMMETRIC);
408 : 0 : if (unlikely(op == NULL)) {
409 : 0 : alloc_failures++;
410 : 0 : continue;
411 : : }
412 : :
413 : 0 : m = rte_pktmbuf_alloc(pool);
414 : 0 : if (unlikely(m == NULL)) {
415 : 0 : alloc_failures++;
416 : 0 : rte_crypto_op_free(op);
417 : 0 : continue;
418 : : }
419 : :
420 : : rte_pktmbuf_append(m, len);
421 : 0 : sym_op = op->sym;
422 : 0 : sym_op->m_src = m;
423 : :
424 : 0 : sym_op->cipher.data.offset = data_offset;
425 : 0 : sym_op->cipher.data.length = data_length;
426 : :
427 : 0 : rte_crypto_op_attach_sym_session(
428 : 0 : 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 : 0 : if (rte_mempool_get(pool, (void **)&result)) {
434 : 0 : alloc_failures++;
435 : 0 : continue;
436 : : }
437 : :
438 : 0 : op = rte_crypto_op_alloc(t->ca_op_pool,
439 : : RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
440 : 0 : if (unlikely(op == NULL)) {
441 : 0 : alloc_failures++;
442 : 0 : rte_mempool_put(pool, result);
443 : 0 : continue;
444 : : }
445 : :
446 : : asym_op = op->asym;
447 : 0 : asym_op->modex.base.data = modex_test_case.base.data;
448 : 0 : asym_op->modex.base.length = modex_test_case.base.len;
449 : 0 : asym_op->modex.result.data = result;
450 : 0 : asym_op->modex.result.length = modex_test_case.result_len;
451 : 0 : rte_crypto_op_attach_asym_session(
452 : 0 : op, p->ca.crypto_sess[flow_counter++ % nb_flows]);
453 : : }
454 : 0 : while (rte_cryptodev_enqueue_burst(cdev_id, qp_id, &op, 1) != 1 &&
455 : 0 : t->done == false)
456 : : rte_pause();
457 : :
458 : 0 : count++;
459 : : }
460 : :
461 : 0 : if (opt->verbose_level > 1 && alloc_failures)
462 : : printf("%s(): lcore %d allocation failures: %"PRIu64"\n",
463 : : __func__, rte_lcore_id(), alloc_failures);
464 : 0 : }
465 : :
466 : : static inline void
467 : 0 : crypto_adapter_enq_op_fwd(struct prod_data *p)
468 : : {
469 : 0 : const uint8_t dev_id = p->dev_id;
470 : 0 : const uint8_t port = p->port_id;
471 : 0 : struct test_perf *t = p->t;
472 : 0 : const uint32_t nb_flows = t->nb_flows;
473 : 0 : const uint64_t nb_pkts = t->nb_pkts;
474 : 0 : struct rte_mempool *pool = t->pool;
475 : 0 : 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 : 0 : if (opt->verbose_level > 1)
485 : 0 : printf("%s(): lcore %d port %d queue %d cdev_id %u cdev_qp_id %u\n",
486 : 0 : __func__, rte_lcore_id(), port, p->queue_id,
487 : 0 : p->ca.cdev_id, p->ca.cdev_qp_id);
488 : :
489 : 0 : ev.event = 0;
490 : : ev.op = RTE_EVENT_OP_NEW;
491 : 0 : ev.queue_id = p->queue_id;
492 : 0 : ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
493 : 0 : ev.event_type = RTE_EVENT_TYPE_CPU;
494 : :
495 : : offset = sizeof(struct perf_elt);
496 : 0 : len = RTE_MAX(RTE_ETHER_MIN_LEN + offset, opt->mbuf_sz);
497 : :
498 : 0 : while (count < nb_pkts && t->done == false) {
499 : 0 : if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
500 : : struct rte_crypto_sym_op *sym_op;
501 : :
502 : 0 : op = rte_crypto_op_alloc(t->ca_op_pool,
503 : : RTE_CRYPTO_OP_TYPE_SYMMETRIC);
504 : 0 : if (unlikely(op == NULL)) {
505 : 0 : alloc_failures++;
506 : 0 : continue;
507 : : }
508 : :
509 : 0 : m = rte_pktmbuf_alloc(pool);
510 : 0 : if (unlikely(m == NULL)) {
511 : 0 : alloc_failures++;
512 : 0 : rte_crypto_op_free(op);
513 : 0 : continue;
514 : : }
515 : :
516 : : rte_pktmbuf_append(m, len);
517 : : sym_op = op->sym;
518 : 0 : sym_op->m_src = m;
519 : 0 : sym_op->cipher.data.offset = offset;
520 : 0 : sym_op->cipher.data.length = len - offset;
521 : 0 : rte_crypto_op_attach_sym_session(
522 : 0 : 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 : 0 : if (rte_mempool_get(pool, (void **)&result)) {
528 : 0 : alloc_failures++;
529 : 0 : continue;
530 : : }
531 : :
532 : 0 : op = rte_crypto_op_alloc(t->ca_op_pool,
533 : : RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
534 : 0 : if (unlikely(op == NULL)) {
535 : 0 : alloc_failures++;
536 : 0 : rte_mempool_put(pool, result);
537 : 0 : continue;
538 : : }
539 : :
540 : : asym_op = op->asym;
541 : 0 : asym_op->modex.base.data = modex_test_case.base.data;
542 : 0 : asym_op->modex.base.length = modex_test_case.base.len;
543 : 0 : asym_op->modex.result.data = result;
544 : 0 : asym_op->modex.result.length = modex_test_case.result_len;
545 : 0 : rte_crypto_op_attach_asym_session(
546 : 0 : op, p->ca.crypto_sess[flow_counter++ % nb_flows]);
547 : : }
548 : 0 : ev.event_ptr = op;
549 : :
550 : 0 : while (rte_event_crypto_adapter_enqueue(dev_id, port, &ev, 1) != 1 &&
551 : 0 : t->done == false)
552 : : rte_pause();
553 : :
554 : 0 : count++;
555 : : }
556 : :
557 : 0 : if (opt->verbose_level > 1 && alloc_failures)
558 : : printf("%s(): lcore %d allocation failures: %"PRIu64"\n",
559 : : __func__, rte_lcore_id(), alloc_failures);
560 : 0 : }
561 : :
562 : : static inline void
563 : 0 : dma_adapter_enq_op_fwd(struct prod_data *p)
564 : : {
565 : 0 : struct test_perf *t = p->t;
566 : 0 : const uint32_t nb_flows = t->nb_flows;
567 : 0 : const uint64_t nb_pkts = t->nb_pkts;
568 : : struct rte_event_dma_adapter_op *op;
569 : 0 : const uint8_t dev_id = p->dev_id;
570 : 0 : struct evt_options *opt = t->opt;
571 : 0 : 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 : 0 : if (opt->verbose_level > 1)
577 : 0 : printf("%s(): lcore %d port %d queue %d dma_dev_id %u dma_dev_vchan_id %u\n",
578 : 0 : __func__, rte_lcore_id(), port, p->queue_id,
579 : 0 : p->da.dma_dev_id, p->da.vchan_id);
580 : :
581 : 0 : ev.event = 0;
582 : : ev.op = RTE_EVENT_OP_NEW;
583 : 0 : ev.queue_id = p->queue_id;
584 : 0 : ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
585 : 0 : ev.event_type = RTE_EVENT_TYPE_CPU;
586 : :
587 : 0 : while (count < nb_pkts && t->done == false) {
588 : 0 : op = p->da.dma_op[flow_counter++ % nb_flows];
589 : 0 : ev.event_ptr = op;
590 : :
591 : 0 : while (rte_event_dma_adapter_enqueue(dev_id, port, &ev, 1) != 1 &&
592 : 0 : t->done == false)
593 : : rte_pause();
594 : :
595 : 0 : count++;
596 : : }
597 : 0 : }
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 : 0 : dma_adapter_enq_op_fwd(p);
606 : :
607 : : return 0;
608 : : }
609 : :
610 : : static inline int
611 : 0 : perf_event_crypto_producer(void *arg)
612 : : {
613 : : struct prod_data *p = arg;
614 : 0 : struct evt_options *opt = p->t->opt;
615 : :
616 : 0 : if (opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW)
617 : 0 : crypto_adapter_enq_op_new(p);
618 : : else
619 : 0 : crypto_adapter_enq_op_fwd(p);
620 : :
621 : 0 : return 0;
622 : : }
623 : :
624 : : static void
625 : 0 : crypto_adapter_enq_op_new_burst(struct prod_data *p)
626 : : {
627 : 0 : const struct test_perf *t = p->t;
628 : 0 : 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 : 0 : const uint32_t burst_size = opt->prod_enq_burst_sz;
633 : : uint8_t *result[MAX_PROD_ENQ_BURST_SIZE];
634 : 0 : const uint32_t nb_flows = t->nb_flows;
635 : 0 : const uint64_t nb_pkts = t->nb_pkts;
636 : : uint16_t len, enq, nb_alloc, offset;
637 : 0 : struct rte_mempool *pool = t->pool;
638 : 0 : uint16_t qp_id = p->ca.cdev_qp_id;
639 : 0 : 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 : 0 : if (opt->verbose_level > 1)
646 : 0 : printf("%s(): lcore %d queue %d cdev_id %u cdev_qp_id %u\n",
647 : 0 : __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 : 0 : len = RTE_MAX(RTE_ETHER_MIN_LEN + offset, opt->mbuf_sz);
652 : :
653 : 0 : while (count < nb_pkts && t->done == false) {
654 : 0 : if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
655 : : struct rte_crypto_sym_op *sym_op;
656 : : int ret;
657 : :
658 : 0 : nb_alloc = rte_crypto_op_bulk_alloc(t->ca_op_pool,
659 : : RTE_CRYPTO_OP_TYPE_SYMMETRIC, ops_burst, burst_size);
660 : 0 : if (unlikely(nb_alloc != burst_size)) {
661 : 0 : alloc_failures++;
662 : 0 : continue;
663 : : }
664 : :
665 : 0 : ret = rte_pktmbuf_alloc_bulk(pool, pkts_burst, burst_size);
666 : 0 : if (unlikely(ret != 0)) {
667 : 0 : alloc_failures++;
668 : 0 : rte_mempool_put_bulk(t->ca_op_pool, (void **)ops_burst, burst_size);
669 : 0 : continue;
670 : : }
671 : :
672 : 0 : for (i = 0; i < burst_size; i++) {
673 : 0 : m = pkts_burst[i];
674 : : rte_pktmbuf_append(m, len);
675 : 0 : sym_op = ops_burst[i]->sym;
676 : 0 : sym_op->m_src = m;
677 : 0 : sym_op->cipher.data.offset = offset;
678 : 0 : sym_op->cipher.data.length = len - offset;
679 : 0 : rte_crypto_op_attach_sym_session(ops_burst[i],
680 : 0 : p->ca.crypto_sess[flow_counter++ % nb_flows]);
681 : : }
682 : : } else {
683 : : struct rte_crypto_asym_op *asym_op;
684 : :
685 : 0 : nb_alloc = rte_crypto_op_bulk_alloc(t->ca_op_pool,
686 : : RTE_CRYPTO_OP_TYPE_ASYMMETRIC, ops_burst, burst_size);
687 : 0 : if (unlikely(nb_alloc != burst_size)) {
688 : 0 : alloc_failures++;
689 : 0 : continue;
690 : : }
691 : :
692 : 0 : if (rte_mempool_get_bulk(pool, (void **)result, burst_size)) {
693 : 0 : alloc_failures++;
694 : 0 : rte_mempool_put_bulk(t->ca_op_pool, (void **)ops_burst, burst_size);
695 : 0 : continue;
696 : : }
697 : :
698 : 0 : for (i = 0; i < burst_size; i++) {
699 : 0 : asym_op = ops_burst[i]->asym;
700 : 0 : asym_op->modex.base.data = modex_test_case.base.data;
701 : 0 : asym_op->modex.base.length = modex_test_case.base.len;
702 : 0 : asym_op->modex.result.data = result[i];
703 : 0 : asym_op->modex.result.length = modex_test_case.result_len;
704 : 0 : rte_crypto_op_attach_asym_session(ops_burst[i],
705 : 0 : p->ca.crypto_sess[flow_counter++ % nb_flows]);
706 : : }
707 : : }
708 : :
709 : : enq = 0;
710 : 0 : while (!t->done) {
711 : 0 : enq += rte_cryptodev_enqueue_burst(cdev_id, qp_id, ops_burst + enq,
712 : 0 : burst_size - enq);
713 : 0 : if (enq == burst_size)
714 : : break;
715 : : }
716 : :
717 : 0 : count += burst_size;
718 : : }
719 : :
720 : 0 : if (opt->verbose_level > 1 && alloc_failures)
721 : : printf("%s(): lcore %d allocation failures: %"PRIu64"\n",
722 : : __func__, rte_lcore_id(), alloc_failures);
723 : 0 : }
724 : :
725 : : static void
726 : 0 : crypto_adapter_enq_op_fwd_burst(struct prod_data *p)
727 : : {
728 : 0 : const struct test_perf *t = p->t;
729 : 0 : 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 : 0 : 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 : 0 : const uint32_t nb_flows = t->nb_flows;
737 : 0 : const uint64_t nb_pkts = t->nb_pkts;
738 : : uint16_t len, enq, nb_alloc, offset;
739 : 0 : struct rte_mempool *pool = t->pool;
740 : 0 : const uint8_t dev_id = p->dev_id;
741 : 0 : 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 : 0 : if (opt->verbose_level > 1)
748 : 0 : printf("%s(): lcore %d port %d queue %d cdev_id %u cdev_qp_id %u\n",
749 : 0 : __func__, rte_lcore_id(), port, p->queue_id,
750 : 0 : p->ca.cdev_id, p->ca.cdev_qp_id);
751 : :
752 : : offset = sizeof(struct perf_elt);
753 : 0 : len = RTE_MAX(RTE_ETHER_MIN_LEN + offset, opt->mbuf_sz);
754 : :
755 : 0 : for (i = 0; i < burst_size; i++) {
756 : 0 : ev[i].event = 0;
757 : 0 : ev[i].op = RTE_EVENT_OP_NEW;
758 : 0 : ev[i].queue_id = p->queue_id;
759 : 0 : ev[i].sched_type = RTE_SCHED_TYPE_ATOMIC;
760 : 0 : ev[i].event_type = RTE_EVENT_TYPE_CPU;
761 : : }
762 : :
763 : 0 : while (count < nb_pkts && t->done == false) {
764 : 0 : if (opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
765 : : struct rte_crypto_sym_op *sym_op;
766 : : int ret;
767 : :
768 : 0 : nb_alloc = rte_crypto_op_bulk_alloc(t->ca_op_pool,
769 : : RTE_CRYPTO_OP_TYPE_SYMMETRIC, ops_burst, burst_size);
770 : 0 : if (unlikely(nb_alloc != burst_size)) {
771 : 0 : alloc_failures++;
772 : 0 : continue;
773 : : }
774 : :
775 : 0 : ret = rte_pktmbuf_alloc_bulk(pool, pkts_burst, burst_size);
776 : 0 : if (unlikely(ret != 0)) {
777 : 0 : alloc_failures++;
778 : 0 : rte_mempool_put_bulk(t->ca_op_pool, (void **)ops_burst, burst_size);
779 : 0 : continue;
780 : : }
781 : :
782 : 0 : for (i = 0; i < burst_size; i++) {
783 : 0 : m = pkts_burst[i];
784 : : rte_pktmbuf_append(m, len);
785 : 0 : sym_op = ops_burst[i]->sym;
786 : 0 : sym_op->m_src = m;
787 : 0 : sym_op->cipher.data.offset = offset;
788 : 0 : sym_op->cipher.data.length = len - offset;
789 : 0 : rte_crypto_op_attach_sym_session(ops_burst[i],
790 : 0 : p->ca.crypto_sess[flow_counter++ % nb_flows]);
791 : 0 : ev[i].event_ptr = ops_burst[i];
792 : : }
793 : : } else {
794 : : struct rte_crypto_asym_op *asym_op;
795 : :
796 : 0 : nb_alloc = rte_crypto_op_bulk_alloc(t->ca_op_pool,
797 : : RTE_CRYPTO_OP_TYPE_ASYMMETRIC, ops_burst, burst_size);
798 : 0 : if (unlikely(nb_alloc != burst_size)) {
799 : 0 : alloc_failures++;
800 : 0 : continue;
801 : : }
802 : :
803 : 0 : if (rte_mempool_get_bulk(pool, (void **)result, burst_size)) {
804 : 0 : alloc_failures++;
805 : 0 : rte_mempool_put_bulk(t->ca_op_pool, (void **)ops_burst, burst_size);
806 : 0 : continue;
807 : : }
808 : :
809 : 0 : for (i = 0; i < burst_size; i++) {
810 : 0 : asym_op = ops_burst[i]->asym;
811 : 0 : asym_op->modex.base.data = modex_test_case.base.data;
812 : 0 : asym_op->modex.base.length = modex_test_case.base.len;
813 : 0 : asym_op->modex.result.data = result[i];
814 : 0 : asym_op->modex.result.length = modex_test_case.result_len;
815 : 0 : rte_crypto_op_attach_asym_session(ops_burst[i],
816 : 0 : p->ca.crypto_sess[flow_counter++ % nb_flows]);
817 : 0 : ev[i].event_ptr = ops_burst[i];
818 : : }
819 : : }
820 : :
821 : : enq = 0;
822 : 0 : while (!t->done) {
823 : 0 : enq += rte_event_crypto_adapter_enqueue(dev_id, port, ev + enq,
824 : 0 : burst_size - enq);
825 : 0 : if (enq == burst_size)
826 : : break;
827 : : }
828 : :
829 : 0 : count += burst_size;
830 : : }
831 : :
832 : 0 : if (opt->verbose_level > 1 && alloc_failures)
833 : : printf("%s(): lcore %d allocation failures: %"PRIu64"\n",
834 : : __func__, rte_lcore_id(), alloc_failures);
835 : 0 : }
836 : :
837 : : static inline int
838 : 0 : perf_event_crypto_producer_burst(void *arg)
839 : : {
840 : : struct prod_data *p = arg;
841 : 0 : struct evt_options *opt = p->t->opt;
842 : :
843 : 0 : if (opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW)
844 : 0 : crypto_adapter_enq_op_new_burst(p);
845 : : else
846 : 0 : crypto_adapter_enq_op_fwd_burst(p);
847 : :
848 : 0 : return 0;
849 : : }
850 : :
851 : : static int
852 : 0 : perf_producer_wrapper(void *arg)
853 : : {
854 : : struct rte_event_dev_info dev_info;
855 : : struct prod_data *p = arg;
856 : 0 : struct test_perf *t = p->t;
857 : :
858 : 0 : rte_event_dev_info_get(p->dev_id, &dev_info);
859 : 0 : if (!t->opt->prod_enq_burst_sz) {
860 : 0 : t->opt->prod_enq_burst_sz = MAX_PROD_ENQ_BURST_SIZE;
861 : 0 : 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 : 0 : 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 : 0 : if (t->opt->prod_type == EVT_PROD_TYPE_SYNT &&
872 : 0 : t->opt->prod_enq_burst_sz == 1)
873 : 0 : return perf_producer(arg);
874 : 0 : else if (t->opt->prod_type == EVT_PROD_TYPE_SYNT &&
875 : 0 : t->opt->prod_enq_burst_sz > 1) {
876 : 0 : if (dev_info.max_event_port_enqueue_depth == 1)
877 : 0 : evt_err("This event device does not support burst mode");
878 : : else
879 : 0 : return perf_producer_burst(arg);
880 : : }
881 : 0 : else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR &&
882 : 0 : !t->opt->timdev_use_burst)
883 : 0 : return perf_event_timer_producer(arg);
884 : 0 : else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR &&
885 : 0 : t->opt->timdev_use_burst)
886 : 0 : return perf_event_timer_producer_burst(arg);
887 : 0 : else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) {
888 : 0 : if (t->opt->prod_enq_burst_sz > 1)
889 : 0 : return perf_event_crypto_producer_burst(arg);
890 : : else
891 : 0 : return perf_event_crypto_producer(arg);
892 : 0 : } else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_DMA_ADPTR)
893 : 0 : 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 : 0 : for (i = 0; i < t->nb_workers; i++)
905 : 0 : 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 : 0 : for (i = 0; i < t->nb_workers; i++)
917 : 0 : total += t->worker[i].latency;
918 : :
919 : : return total;
920 : : }
921 : :
922 : :
923 : : int
924 : 0 : 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 : 0 : RTE_LCORE_FOREACH_WORKER(lcore_id) {
933 : 0 : if (!(opt->wlcores[lcore_id]))
934 : 0 : continue;
935 : :
936 : 0 : ret = rte_eal_remote_launch(worker,
937 : 0 : &t->worker[port_idx], lcore_id);
938 : 0 : if (ret) {
939 : 0 : evt_err("failed to launch worker %d", lcore_id);
940 : 0 : return ret;
941 : : }
942 : 0 : port_idx++;
943 : : }
944 : :
945 : : /* launch producers */
946 : 0 : RTE_LCORE_FOREACH_WORKER(lcore_id) {
947 : 0 : if (!(opt->plcores[lcore_id]))
948 : 0 : continue;
949 : :
950 : 0 : ret = rte_eal_remote_launch(perf_producer_wrapper,
951 : 0 : &t->prod[port_idx], lcore_id);
952 : 0 : if (ret) {
953 : 0 : evt_err("failed to launch perf_producer %d", lcore_id);
954 : 0 : return ret;
955 : : }
956 : 0 : port_idx++;
957 : : }
958 : :
959 : 0 : const uint64_t total_pkts = t->outstand_pkts;
960 : :
961 : : uint64_t dead_lock_cycles = rte_get_timer_cycles();
962 : 0 : int64_t dead_lock_remaining = total_pkts;
963 : 0 : 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 : 0 : const uint64_t freq_mhz = rte_get_timer_hz() / 1000000;
973 : : int64_t remaining = t->outstand_pkts - processed_pkts(t);
974 : :
975 : 0 : while (t->done == false) {
976 : : const uint64_t new_cycles = rte_get_timer_cycles();
977 : :
978 : 0 : 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 : 0 : remaining = t->outstand_pkts - pkts;
983 : 0 : float mpps = (float)(perf_remaining-remaining)/1000000;
984 : :
985 : : perf_remaining = remaining;
986 : : perf_cycles = new_cycles;
987 : 0 : total_mpps += mpps;
988 : 0 : ++samples;
989 : 0 : if (opt->fwd_latency && pkts > 0) {
990 : 0 : printf(CLGRN"\r%.3f mpps avg %.3f mpps [avg fwd latency %.3f us] "CLNRM,
991 : 0 : mpps, total_mpps/samples,
992 : 0 : (float)(latency/pkts)/freq_mhz);
993 : : } else {
994 : 0 : printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM,
995 : 0 : mpps, total_mpps/samples);
996 : : }
997 : 0 : fflush(stdout);
998 : :
999 : 0 : if (remaining <= 0) {
1000 : 0 : t->result = EVT_TEST_SUCCESS;
1001 : 0 : if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
1002 : : opt->prod_type ==
1003 : 0 : EVT_PROD_TYPE_EVENT_TIMER_ADPTR ||
1004 : : opt->prod_type ==
1005 : 0 : EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR ||
1006 : : opt->prod_type ==
1007 : : EVT_PROD_TYPE_EVENT_DMA_ADPTR) {
1008 : 0 : t->done = true;
1009 : 0 : break;
1010 : : }
1011 : : }
1012 : : }
1013 : :
1014 : 0 : if (new_cycles - dead_lock_cycles > dead_lock_sample &&
1015 : 0 : (opt->prod_type == EVT_PROD_TYPE_SYNT ||
1016 : 0 : opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR ||
1017 : 0 : opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR ||
1018 : : opt->prod_type == EVT_PROD_TYPE_EVENT_DMA_ADPTR)) {
1019 : 0 : remaining = t->outstand_pkts - processed_pkts(t);
1020 : 0 : if (dead_lock_remaining == remaining) {
1021 : 0 : rte_event_dev_dump(opt->dev_id, stdout);
1022 : 0 : evt_err("No schedules for seconds, deadlock");
1023 : 0 : t->done = true;
1024 : 0 : break;
1025 : : }
1026 : : dead_lock_remaining = remaining;
1027 : : dead_lock_cycles = new_cycles;
1028 : : }
1029 : : }
1030 : : printf("\n");
1031 : 0 : return 0;
1032 : : }
1033 : :
1034 : : static int
1035 : 0 : 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 : 0 : queue_conf.ev.sched_type = opt->sched_type_list[0];
1045 : 0 : RTE_ETH_FOREACH_DEV(prod) {
1046 : : uint32_t cap;
1047 : :
1048 : 0 : ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id,
1049 : : prod, &cap);
1050 : 0 : if (ret) {
1051 : 0 : evt_err("failed to get event rx adapter[%d]"
1052 : : " capabilities",
1053 : : opt->dev_id);
1054 : 0 : return ret;
1055 : : }
1056 : 0 : queue_conf.ev.queue_id = prod * stride;
1057 : 0 : ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id,
1058 : : &prod_conf);
1059 : 0 : if (ret) {
1060 : 0 : evt_err("failed to create rx adapter[%d]", prod);
1061 : 0 : return ret;
1062 : : }
1063 : 0 : ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1,
1064 : : &queue_conf);
1065 : 0 : if (ret) {
1066 : 0 : evt_err("failed to add rx queues to adapter[%d]", prod);
1067 : 0 : return ret;
1068 : : }
1069 : :
1070 : 0 : if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) {
1071 : : uint32_t service_id;
1072 : :
1073 : 0 : rte_event_eth_rx_adapter_service_id_get(prod,
1074 : : &service_id);
1075 : 0 : ret = evt_service_setup(service_id);
1076 : 0 : if (ret) {
1077 : 0 : evt_err("Failed to setup service core"
1078 : : " for Rx adapter\n");
1079 : 0 : return ret;
1080 : : }
1081 : : }
1082 : : }
1083 : :
1084 : : return ret;
1085 : : }
1086 : :
1087 : : static int
1088 : 0 : 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 : 0 : uint8_t nb_producers = evt_nr_active_lcores(t->opt->plcores);
1095 : : uint8_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
1096 : :
1097 : 0 : if (nb_producers == 1)
1098 : : flags |= RTE_EVENT_TIMER_ADAPTER_F_SP_PUT;
1099 : :
1100 : 0 : for (i = 0; i < t->opt->nb_timer_adptrs; i++) {
1101 : 0 : struct rte_event_timer_adapter_conf config = {
1102 : 0 : .event_dev_id = t->opt->dev_id,
1103 : : .timer_adapter_id = i,
1104 : 0 : .timer_tick_ns = t->opt->timer_tick_nsec,
1105 : 0 : .max_tmo_ns = t->opt->max_tmo_nsec,
1106 : 0 : .nb_timers = t->opt->pool_sz,
1107 : : .flags = flags,
1108 : : };
1109 : :
1110 : 0 : wl = rte_event_timer_adapter_create(&config);
1111 : 0 : if (wl == NULL) {
1112 : 0 : evt_err("failed to create event timer ring %d", i);
1113 : 0 : return rte_errno;
1114 : : }
1115 : :
1116 : : memset(&adapter_info, 0,
1117 : : sizeof(struct rte_event_timer_adapter_info));
1118 : 0 : rte_event_timer_adapter_get_info(wl, &adapter_info);
1119 : 0 : t->opt->optm_timer_tick_nsec = adapter_info.min_resolution_ns;
1120 : :
1121 : 0 : if (!(adapter_info.caps &
1122 : : RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT)) {
1123 : 0 : uint32_t service_id = -1U;
1124 : :
1125 : 0 : rte_event_timer_adapter_service_id_get(wl,
1126 : : &service_id);
1127 : 0 : ret = evt_service_setup(service_id);
1128 : 0 : if (ret) {
1129 : 0 : evt_err("Failed to setup service core"
1130 : : " for timer adapter\n");
1131 : 0 : return ret;
1132 : : }
1133 : 0 : rte_service_runstate_set(service_id, 1);
1134 : : }
1135 : 0 : t->timer_adptr[i] = wl;
1136 : : }
1137 : : return 0;
1138 : : }
1139 : :
1140 : : static int
1141 : 0 : perf_event_crypto_adapter_setup(struct test_perf *t, struct prod_data *p)
1142 : : {
1143 : : struct rte_event_crypto_adapter_queue_conf conf;
1144 : 0 : struct evt_options *opt = t->opt;
1145 : : uint32_t cap;
1146 : : int ret;
1147 : :
1148 : : memset(&conf, 0, sizeof(conf));
1149 : :
1150 : 0 : ret = rte_event_crypto_adapter_caps_get(p->dev_id, p->ca.cdev_id, &cap);
1151 : 0 : if (ret) {
1152 : 0 : evt_err("Failed to get crypto adapter capabilities");
1153 : 0 : return ret;
1154 : : }
1155 : :
1156 : 0 : if (((opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_NEW) &&
1157 : 0 : !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW)) ||
1158 : 0 : ((opt->crypto_adptr_mode == RTE_EVENT_CRYPTO_ADAPTER_OP_FORWARD) &&
1159 : 0 : !(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))) {
1160 : 0 : evt_err("crypto adapter %s mode unsupported\n",
1161 : : opt->crypto_adptr_mode ? "OP_FORWARD" : "OP_NEW");
1162 : 0 : return -ENOTSUP;
1163 : 0 : } else if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA)) {
1164 : 0 : evt_err("Storing crypto session not supported");
1165 : 0 : return -ENOTSUP;
1166 : : }
1167 : :
1168 : 0 : if (opt->ena_vector) {
1169 : : struct rte_event_crypto_adapter_vector_limits limits;
1170 : :
1171 : 0 : if (!(cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_EVENT_VECTOR)) {
1172 : 0 : evt_err("Crypto adapter doesn't support event vector");
1173 : 0 : return -EINVAL;
1174 : : }
1175 : :
1176 : 0 : ret = rte_event_crypto_adapter_vector_limits_get(p->dev_id, p->ca.cdev_id, &limits);
1177 : 0 : if (ret) {
1178 : 0 : evt_err("Failed to get crypto adapter's vector limits");
1179 : 0 : return ret;
1180 : : }
1181 : :
1182 : 0 : if (opt->vector_size < limits.min_sz || opt->vector_size > limits.max_sz) {
1183 : 0 : evt_err("Vector size [%d] not within limits max[%d] min[%d]",
1184 : : opt->vector_size, limits.max_sz, limits.min_sz);
1185 : 0 : return -EINVAL;
1186 : : }
1187 : :
1188 : 0 : if (limits.log2_sz && !rte_is_power_of_2(opt->vector_size)) {
1189 : 0 : evt_err("Vector size [%d] not power of 2", opt->vector_size);
1190 : 0 : return -EINVAL;
1191 : : }
1192 : :
1193 : 0 : if (opt->vector_tmo_nsec > limits.max_timeout_ns ||
1194 : 0 : opt->vector_tmo_nsec < limits.min_timeout_ns) {
1195 : 0 : 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 : 0 : return -EINVAL;
1199 : : }
1200 : :
1201 : 0 : conf.vector_mp = t->ca_vector_pool;
1202 : 0 : conf.vector_sz = opt->vector_size;
1203 : 0 : conf.vector_timeout_ns = opt->vector_tmo_nsec;
1204 : 0 : conf.flags |= RTE_EVENT_CRYPTO_ADAPTER_EVENT_VECTOR;
1205 : : }
1206 : :
1207 : 0 : if (cap & RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND) {
1208 : 0 : conf.ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
1209 : 0 : conf.ev.queue_id = p->queue_id;
1210 : : }
1211 : :
1212 : 0 : ret = rte_event_crypto_adapter_queue_pair_add(
1213 : 0 : TEST_PERF_CA_ID, p->ca.cdev_id, p->ca.cdev_qp_id, &conf);
1214 : :
1215 : 0 : return ret;
1216 : : }
1217 : :
1218 : : static int
1219 : 0 : perf_event_dma_adapter_setup(struct test_perf *t, struct prod_data *p)
1220 : : {
1221 : 0 : struct evt_options *opt = t->opt;
1222 : : struct rte_event event;
1223 : : uint32_t cap;
1224 : : int ret;
1225 : :
1226 : 0 : ret = rte_event_dma_adapter_caps_get(p->dev_id, p->da.dma_dev_id, &cap);
1227 : 0 : if (ret) {
1228 : 0 : evt_err("Failed to get dma adapter capabilities");
1229 : 0 : return ret;
1230 : : }
1231 : :
1232 : 0 : if (((opt->dma_adptr_mode == RTE_EVENT_DMA_ADAPTER_OP_NEW) &&
1233 : 0 : !(cap & RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_OP_NEW)) ||
1234 : 0 : ((opt->dma_adptr_mode == RTE_EVENT_DMA_ADAPTER_OP_FORWARD) &&
1235 : 0 : !(cap & RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_OP_FWD))) {
1236 : 0 : evt_err("dma adapter %s mode unsupported\n",
1237 : : opt->dma_adptr_mode ? "OP_FORWARD" : "OP_NEW");
1238 : 0 : return -ENOTSUP;
1239 : : }
1240 : :
1241 : 0 : if (cap & RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_VCHAN_EV_BIND)
1242 : 0 : ret = rte_event_dma_adapter_vchan_add(TEST_PERF_DA_ID, p->da.dma_dev_id,
1243 : 0 : p->da.vchan_id, &event);
1244 : : else
1245 : 0 : ret = rte_event_dma_adapter_vchan_add(TEST_PERF_DA_ID, p->da.dma_dev_id,
1246 : 0 : p->da.vchan_id, NULL);
1247 : :
1248 : : return ret;
1249 : : }
1250 : :
1251 : : static void *
1252 : 0 : 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 : 0 : struct evt_options *opt = t->opt;
1259 : : uint16_t key_size;
1260 : : uint16_t iv_size;
1261 : : void *sess;
1262 : :
1263 : 0 : cipher_algo = opt->crypto_cipher_alg;
1264 : 0 : key_size = opt->crypto_cipher_key_sz;
1265 : 0 : iv_size = opt->crypto_cipher_iv_sz;
1266 : :
1267 : : /* Check if device supports the algorithm */
1268 : 0 : cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1269 : 0 : cap_idx.algo.cipher = cipher_algo;
1270 : :
1271 : 0 : cap = rte_cryptodev_sym_capability_get(p->ca.cdev_id, &cap_idx);
1272 : 0 : if (cap == NULL) {
1273 : 0 : evt_err("Device doesn't support cipher algorithm [%s]. Test Skipped\n",
1274 : : rte_cryptodev_get_cipher_algo_string(cipher_algo));
1275 : 0 : return NULL;
1276 : : }
1277 : :
1278 : : /* Check if device supports key size and IV size */
1279 : 0 : if (rte_cryptodev_sym_capability_check_cipher(cap, key_size,
1280 : : iv_size) < 0) {
1281 : 0 : 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 : 0 : return NULL;
1285 : : }
1286 : :
1287 : 0 : cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1288 : 0 : cipher_xform.cipher.algo = cipher_algo;
1289 : 0 : cipher_xform.cipher.key.data = opt->crypto_cipher_key;
1290 : 0 : cipher_xform.cipher.key.length = key_size;
1291 : 0 : cipher_xform.cipher.iv.length = iv_size;
1292 : 0 : cipher_xform.cipher.iv.offset = IV_OFFSET;
1293 : 0 : cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1294 : 0 : cipher_xform.next = NULL;
1295 : :
1296 : 0 : sess = rte_cryptodev_sym_session_create(p->ca.cdev_id, &cipher_xform,
1297 : : t->ca_sess_pool);
1298 : 0 : if (sess == NULL) {
1299 : 0 : evt_err("Failed to create sym session");
1300 : 0 : return NULL;
1301 : : }
1302 : :
1303 : : return sess;
1304 : : }
1305 : :
1306 : : static void *
1307 : 0 : 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 : 0 : xform.next = NULL;
1315 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX;
1316 : 0 : cap_idx.type = xform.xform_type;
1317 : 0 : capability = rte_cryptodev_asym_capability_get(p->ca.cdev_id, &cap_idx);
1318 : 0 : if (capability == NULL) {
1319 : 0 : evt_err("Device doesn't support MODEX. Test Skipped\n");
1320 : 0 : return NULL;
1321 : : }
1322 : :
1323 : 0 : xform.modex.modulus.data = modex_test_case.modulus.data;
1324 : 0 : xform.modex.modulus.length = modex_test_case.modulus.len;
1325 : 0 : xform.modex.exponent.data = modex_test_case.exponent.data;
1326 : 0 : xform.modex.exponent.length = modex_test_case.exponent.len;
1327 : :
1328 : 0 : if (rte_cryptodev_asym_session_create(p->ca.cdev_id, &xform,
1329 : : t->ca_asym_sess_pool, &sess)) {
1330 : 0 : evt_err("Failed to create asym session");
1331 : 0 : return NULL;
1332 : : }
1333 : :
1334 : 0 : return sess;
1335 : : }
1336 : :
1337 : : int
1338 : 0 : 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 : 0 : for (port = 0; port < evt_nr_active_lcores(opt->wlcores);
1348 : 0 : port++) {
1349 : : struct worker_data *w = &t->worker[port];
1350 : :
1351 : 0 : w->dev_id = opt->dev_id;
1352 : 0 : w->port_id = port;
1353 : 0 : w->t = t;
1354 : 0 : w->processed_pkts = 0;
1355 : 0 : w->latency = 0;
1356 : :
1357 : 0 : struct rte_event_port_conf conf = *port_conf;
1358 : 0 : conf.event_port_cfg |= RTE_EVENT_PORT_CFG_HINT_WORKER;
1359 : :
1360 : 0 : ret = rte_event_port_setup(opt->dev_id, port, &conf);
1361 : 0 : if (ret) {
1362 : 0 : evt_err("failed to setup port %d", port);
1363 : 0 : return ret;
1364 : : }
1365 : :
1366 : 0 : ret = rte_event_port_link(opt->dev_id, port, NULL, NULL, 0);
1367 : 0 : if (ret != nb_queues) {
1368 : 0 : evt_err("failed to link all queues to port %d", port);
1369 : 0 : return -EINVAL;
1370 : : }
1371 : : }
1372 : :
1373 : : /* port for producers, no links */
1374 : 0 : if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
1375 : 0 : for ( ; port < perf_nb_event_ports(opt); port++) {
1376 : : struct prod_data *p = &t->prod[port];
1377 : 0 : p->t = t;
1378 : : }
1379 : :
1380 : 0 : struct rte_event_port_conf conf = *port_conf;
1381 : 0 : conf.event_port_cfg |= RTE_EVENT_PORT_CFG_HINT_PRODUCER;
1382 : :
1383 : 0 : ret = perf_event_rx_adapter_setup(opt, stride, conf);
1384 : 0 : if (ret)
1385 : 0 : return ret;
1386 : 0 : } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
1387 : : prod = 0;
1388 : 0 : for ( ; port < perf_nb_event_ports(opt); port++) {
1389 : : struct prod_data *p = &t->prod[port];
1390 : 0 : p->queue_id = prod * stride;
1391 : 0 : p->t = t;
1392 : 0 : prod++;
1393 : : }
1394 : :
1395 : 0 : ret = perf_event_timer_adapter_setup(t);
1396 : 0 : if (ret)
1397 : 0 : return ret;
1398 : 0 : } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR) {
1399 : 0 : struct rte_event_port_conf conf = *port_conf;
1400 : : uint8_t cdev_id = 0;
1401 : : uint16_t qp_id = 0;
1402 : :
1403 : 0 : ret = rte_event_crypto_adapter_create(TEST_PERF_CA_ID,
1404 : 0 : opt->dev_id, &conf, 0);
1405 : 0 : if (ret) {
1406 : 0 : evt_err("Failed to create crypto adapter");
1407 : 0 : return ret;
1408 : : }
1409 : :
1410 : : prod = 0;
1411 : 0 : for (; port < perf_nb_event_ports(opt); port++) {
1412 : : union rte_event_crypto_metadata m_data;
1413 : 0 : struct prod_data *p = &t->prod[port];
1414 : : uint32_t flow_id;
1415 : :
1416 : 0 : if (qp_id == rte_cryptodev_queue_pair_count(cdev_id)) {
1417 : 0 : cdev_id++;
1418 : : qp_id = 0;
1419 : : }
1420 : :
1421 : 0 : p->dev_id = opt->dev_id;
1422 : 0 : p->port_id = port;
1423 : 0 : p->queue_id = prod * stride;
1424 : 0 : p->ca.cdev_id = cdev_id;
1425 : 0 : p->ca.cdev_qp_id = qp_id;
1426 : 0 : p->ca.crypto_sess = rte_zmalloc_socket(
1427 : 0 : NULL, sizeof(void *) * t->nb_flows,
1428 : : RTE_CACHE_LINE_SIZE, opt->socket_id);
1429 : 0 : p->t = t;
1430 : :
1431 : 0 : ret = perf_event_crypto_adapter_setup(t, p);
1432 : 0 : if (ret)
1433 : 0 : return ret;
1434 : :
1435 : 0 : m_data.request_info.cdev_id = p->ca.cdev_id;
1436 : 0 : m_data.request_info.queue_pair_id = p->ca.cdev_qp_id;
1437 : 0 : m_data.response_info.sched_type = RTE_SCHED_TYPE_ATOMIC;
1438 : 0 : m_data.response_info.queue_id = p->queue_id;
1439 : :
1440 : 0 : for (flow_id = 0; flow_id < t->nb_flows; flow_id++) {
1441 : 0 : m_data.response_info.flow_id = flow_id;
1442 : 0 : if (opt->crypto_op_type ==
1443 : : RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
1444 : : void *sess;
1445 : :
1446 : 0 : sess = cryptodev_sym_sess_create(p, t);
1447 : 0 : if (sess == NULL)
1448 : : return -ENOMEM;
1449 : :
1450 : 0 : 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 : 0 : if (ret)
1457 : 0 : return ret;
1458 : 0 : p->ca.crypto_sess[flow_id] = sess;
1459 : : } else {
1460 : : void *sess;
1461 : :
1462 : 0 : sess = cryptodev_asym_sess_create(p, t);
1463 : 0 : if (sess == NULL)
1464 : : return -ENOMEM;
1465 : 0 : 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 : 0 : if (ret)
1472 : 0 : return ret;
1473 : 0 : p->ca.crypto_sess[flow_id] = sess;
1474 : : }
1475 : : }
1476 : :
1477 : 0 : conf.event_port_cfg |=
1478 : : RTE_EVENT_PORT_CFG_HINT_PRODUCER |
1479 : : RTE_EVENT_PORT_CFG_HINT_CONSUMER;
1480 : :
1481 : 0 : ret = rte_event_port_setup(opt->dev_id, port, &conf);
1482 : 0 : if (ret) {
1483 : 0 : evt_err("failed to setup port %d", port);
1484 : 0 : return ret;
1485 : : }
1486 : :
1487 : 0 : qp_id++;
1488 : 0 : prod++;
1489 : : }
1490 : 0 : } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_DMA_ADPTR) {
1491 : 0 : struct rte_event_port_conf conf = *port_conf;
1492 : : struct rte_event_dma_adapter_op *op;
1493 : 0 : struct rte_mempool *pool = t->pool;
1494 : : uint8_t dma_dev_id = 0;
1495 : : uint16_t vchan_id = 0;
1496 : :
1497 : 0 : ret = rte_event_dma_adapter_create(TEST_PERF_DA_ID, opt->dev_id, &conf, 0);
1498 : 0 : if (ret) {
1499 : 0 : evt_err("Failed to create dma adapter");
1500 : 0 : return ret;
1501 : : }
1502 : :
1503 : : prod = 0;
1504 : 0 : for (; port < perf_nb_event_ports(opt); port++) {
1505 : 0 : struct prod_data *p = &t->prod[port];
1506 : : struct rte_event *response_info;
1507 : : uint32_t flow_id;
1508 : :
1509 : 0 : p->dev_id = opt->dev_id;
1510 : 0 : p->port_id = port;
1511 : 0 : p->queue_id = prod * stride;
1512 : 0 : p->da.dma_dev_id = dma_dev_id;
1513 : 0 : p->da.vchan_id = vchan_id;
1514 : 0 : p->da.dma_op = rte_zmalloc_socket(NULL, sizeof(void *) * t->nb_flows,
1515 : : RTE_CACHE_LINE_SIZE, opt->socket_id);
1516 : :
1517 : 0 : p->t = t;
1518 : :
1519 : 0 : ret = perf_event_dma_adapter_setup(t, p);
1520 : 0 : if (ret)
1521 : 0 : return ret;
1522 : :
1523 : 0 : for (flow_id = 0; flow_id < t->nb_flows; flow_id++) {
1524 : 0 : rte_mempool_get(t->da_op_pool, (void **)&op);
1525 : :
1526 : 0 : op->src_seg = rte_malloc(NULL, sizeof(struct rte_dma_sge), 0);
1527 : 0 : op->dst_seg = rte_malloc(NULL, sizeof(struct rte_dma_sge), 0);
1528 : :
1529 : 0 : op->src_seg->addr = rte_pktmbuf_iova(rte_pktmbuf_alloc(pool));
1530 : 0 : op->dst_seg->addr = rte_pktmbuf_iova(rte_pktmbuf_alloc(pool));
1531 : 0 : op->src_seg->length = 1024;
1532 : 0 : op->dst_seg->length = 1024;
1533 : 0 : op->nb_src = 1;
1534 : 0 : op->nb_dst = 1;
1535 : 0 : op->flags = RTE_DMA_OP_FLAG_SUBMIT;
1536 : 0 : op->op_mp = t->da_op_pool;
1537 : 0 : op->dma_dev_id = dma_dev_id;
1538 : 0 : op->vchan = vchan_id;
1539 : :
1540 : : response_info = (struct rte_event *)((uint8_t *)op +
1541 : : sizeof(struct rte_event_dma_adapter_op));
1542 : 0 : response_info->queue_id = p->queue_id;
1543 : 0 : response_info->sched_type = RTE_SCHED_TYPE_ATOMIC;
1544 : 0 : response_info->flow_id = flow_id;
1545 : :
1546 : 0 : p->da.dma_op[flow_id] = op;
1547 : : }
1548 : :
1549 : 0 : conf.event_port_cfg |=
1550 : : RTE_EVENT_PORT_CFG_HINT_PRODUCER |
1551 : : RTE_EVENT_PORT_CFG_HINT_CONSUMER;
1552 : :
1553 : 0 : ret = rte_event_port_setup(opt->dev_id, port, &conf);
1554 : 0 : if (ret) {
1555 : 0 : evt_err("failed to setup port %d", port);
1556 : 0 : return ret;
1557 : : }
1558 : :
1559 : 0 : prod++;
1560 : : }
1561 : : } else {
1562 : : prod = 0;
1563 : 0 : for ( ; port < perf_nb_event_ports(opt); port++) {
1564 : : struct prod_data *p = &t->prod[port];
1565 : :
1566 : 0 : p->dev_id = opt->dev_id;
1567 : 0 : p->port_id = port;
1568 : 0 : p->queue_id = prod * stride;
1569 : 0 : p->t = t;
1570 : :
1571 : 0 : struct rte_event_port_conf conf = *port_conf;
1572 : 0 : conf.event_port_cfg |=
1573 : : RTE_EVENT_PORT_CFG_HINT_PRODUCER |
1574 : : RTE_EVENT_PORT_CFG_HINT_CONSUMER;
1575 : :
1576 : 0 : ret = rte_event_port_setup(opt->dev_id, port, &conf);
1577 : 0 : if (ret) {
1578 : 0 : evt_err("failed to setup port %d", port);
1579 : 0 : return ret;
1580 : : }
1581 : 0 : prod++;
1582 : : }
1583 : : }
1584 : :
1585 : : return ret;
1586 : : }
1587 : :
1588 : : int
1589 : 0 : 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 : 0 : lcores = opt->prod_type == EVT_PROD_TYPE_SYNT ? 3 : 2;
1597 : :
1598 : 0 : if (rte_lcore_count() < lcores) {
1599 : 0 : evt_err("test need minimum %d lcores", lcores);
1600 : 0 : return -1;
1601 : : }
1602 : :
1603 : : /* Validate worker lcores */
1604 : 0 : if (evt_lcores_has_overlap(opt->wlcores, rte_get_main_lcore())) {
1605 : 0 : evt_err("worker lcores overlaps with main lcore");
1606 : 0 : return -1;
1607 : : }
1608 : 0 : if (evt_lcores_has_overlap_multi(opt->wlcores, opt->plcores)) {
1609 : 0 : evt_err("worker lcores overlaps producer lcores");
1610 : 0 : return -1;
1611 : : }
1612 : 0 : if (evt_has_disabled_lcore(opt->wlcores)) {
1613 : 0 : evt_err("one or more workers lcores are not enabled");
1614 : 0 : return -1;
1615 : : }
1616 : 0 : if (!evt_has_active_lcore(opt->wlcores)) {
1617 : 0 : evt_err("minimum one worker is required");
1618 : 0 : return -1;
1619 : : }
1620 : :
1621 : 0 : if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
1622 : 0 : opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR ||
1623 : 0 : opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR ||
1624 : : opt->prod_type == EVT_PROD_TYPE_EVENT_DMA_ADPTR) {
1625 : : /* Validate producer lcores */
1626 : 0 : if (evt_lcores_has_overlap(opt->plcores,
1627 : 0 : rte_get_main_lcore())) {
1628 : 0 : evt_err("producer lcores overlaps with main lcore");
1629 : 0 : return -1;
1630 : : }
1631 : 0 : if (evt_has_disabled_lcore(opt->plcores)) {
1632 : 0 : evt_err("one or more producer lcores are not enabled");
1633 : 0 : return -1;
1634 : : }
1635 : 0 : if (!evt_has_active_lcore(opt->plcores)) {
1636 : 0 : evt_err("minimum one producer is required");
1637 : 0 : return -1;
1638 : : }
1639 : : }
1640 : :
1641 : 0 : if (evt_has_invalid_stage(opt))
1642 : : return -1;
1643 : :
1644 : 0 : if (evt_has_invalid_sched_type(opt))
1645 : : return -1;
1646 : :
1647 : 0 : if (nb_queues > EVT_MAX_QUEUES) {
1648 : 0 : evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
1649 : 0 : return -1;
1650 : : }
1651 : 0 : if (perf_nb_event_ports(opt) > EVT_MAX_PORTS) {
1652 : 0 : evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
1653 : 0 : return -1;
1654 : : }
1655 : :
1656 : : /* Fixups */
1657 : 0 : if ((opt->nb_stages == 1 &&
1658 : 0 : opt->prod_type != EVT_PROD_TYPE_EVENT_TIMER_ADPTR) &&
1659 : : opt->fwd_latency) {
1660 : 0 : evt_info("fwd_latency is valid when nb_stages > 1, disabling");
1661 : 0 : opt->fwd_latency = 0;
1662 : : }
1663 : :
1664 : 0 : if (opt->fwd_latency && !opt->q_priority) {
1665 : 0 : evt_info("enabled queue priority for latency measurement");
1666 : 0 : opt->q_priority = 1;
1667 : : }
1668 : 0 : if (opt->nb_pkts == 0)
1669 : 0 : opt->nb_pkts = INT64_MAX/evt_nr_active_lcores(opt->plcores);
1670 : :
1671 : : return 0;
1672 : : }
1673 : :
1674 : : void
1675 : 0 : perf_opt_dump(struct evt_options *opt, uint8_t nb_queues)
1676 : : {
1677 : 0 : evt_dump("nb_prod_lcores", "%d", evt_nr_active_lcores(opt->plcores));
1678 : 0 : evt_dump_producer_lcores(opt);
1679 : 0 : evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores));
1680 : 0 : evt_dump_worker_lcores(opt);
1681 : : evt_dump_nb_stages(opt);
1682 : : evt_dump("nb_evdev_ports", "%d", perf_nb_event_ports(opt));
1683 : 0 : evt_dump("nb_evdev_queues", "%d", nb_queues);
1684 : 0 : evt_dump_queue_priority(opt);
1685 : 0 : evt_dump_sched_type_list(opt);
1686 : 0 : evt_dump_producer_type(opt);
1687 : 0 : evt_dump("prod_enq_burst_sz", "%d", opt->prod_enq_burst_sz);
1688 : 0 : }
1689 : :
1690 : : static void
1691 : 0 : perf_event_port_flush(uint8_t dev_id __rte_unused, struct rte_event ev,
1692 : : void *args)
1693 : : {
1694 : 0 : rte_mempool_put(args, ev.event_ptr);
1695 : 0 : }
1696 : :
1697 : : void
1698 : 0 : 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 : 0 : if (nb_deq) {
1705 : 0 : for (i = nb_enq; i < nb_deq; i++)
1706 : 0 : rte_mempool_put(pool, events[i].event_ptr);
1707 : :
1708 : 0 : for (i = 0; i < nb_deq; i++)
1709 : 0 : events[i].op = RTE_EVENT_OP_RELEASE;
1710 : 0 : rte_event_enqueue_burst(dev_id, port_id, events, nb_deq);
1711 : : }
1712 : 0 : rte_event_port_quiesce(dev_id, port_id, perf_event_port_flush, pool);
1713 : 0 : }
1714 : :
1715 : : void
1716 : 0 : 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 : 0 : if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
1722 : 0 : for (i = 0; i < opt->nb_timer_adptrs; i++)
1723 : 0 : rte_event_timer_adapter_stop(t->timer_adptr[i]);
1724 : : }
1725 : 0 : rte_event_dev_stop(opt->dev_id);
1726 : 0 : rte_event_dev_close(opt->dev_id);
1727 : 0 : }
1728 : :
1729 : : static inline void
1730 : 0 : perf_elt_init(struct rte_mempool *mp, void *arg __rte_unused,
1731 : : void *obj, unsigned i __rte_unused)
1732 : : {
1733 : 0 : memset(obj, 0, mp->elt_size);
1734 : 0 : }
1735 : :
1736 : : #define NB_RX_DESC 128
1737 : : #define NB_TX_DESC 512
1738 : : int
1739 : 0 : 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 : 0 : 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 : 0 : if (opt->prod_type != EVT_PROD_TYPE_ETH_RX_ADPTR)
1757 : : return 0;
1758 : :
1759 : 0 : if (!rte_eth_dev_count_avail()) {
1760 : 0 : evt_err("No ethernet ports found.");
1761 : 0 : return -ENODEV;
1762 : : }
1763 : :
1764 : 0 : RTE_ETH_FOREACH_DEV(i) {
1765 : : struct rte_eth_dev_info dev_info;
1766 : 0 : struct rte_eth_conf local_port_conf = port_conf;
1767 : :
1768 : 0 : ret = rte_eth_dev_info_get(i, &dev_info);
1769 : 0 : if (ret != 0) {
1770 : 0 : evt_err("Error during getting device (port %u) info: %s\n",
1771 : : i, strerror(-ret));
1772 : 0 : return ret;
1773 : : }
1774 : :
1775 : 0 : local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
1776 : 0 : dev_info.flow_type_rss_offloads;
1777 : 0 : if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
1778 : : port_conf.rx_adv_conf.rss_conf.rss_hf) {
1779 : 0 : 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 : 0 : if (rte_eth_dev_configure(i, 1, 1, &local_port_conf) < 0) {
1787 : 0 : evt_err("Failed to configure eth port [%d]", i);
1788 : 0 : return -EINVAL;
1789 : : }
1790 : :
1791 : 0 : if (rte_eth_rx_queue_setup(i, 0, NB_RX_DESC,
1792 : : rte_socket_id(), NULL, t->pool) < 0) {
1793 : 0 : evt_err("Failed to setup eth port [%d] rx_queue: %d.",
1794 : : i, 0);
1795 : 0 : return -EINVAL;
1796 : : }
1797 : :
1798 : 0 : if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC,
1799 : : rte_socket_id(), NULL) < 0) {
1800 : 0 : evt_err("Failed to setup eth port [%d] tx_queue: %d.",
1801 : : i, 0);
1802 : 0 : return -EINVAL;
1803 : : }
1804 : :
1805 : 0 : ret = rte_eth_promiscuous_enable(i);
1806 : 0 : if (ret != 0) {
1807 : 0 : evt_err("Failed to enable promiscuous mode for eth port [%d]: %s",
1808 : : i, rte_strerror(-ret));
1809 : 0 : return ret;
1810 : : }
1811 : : }
1812 : :
1813 : : return 0;
1814 : : }
1815 : :
1816 : : void
1817 : 0 : perf_ethdev_rx_stop(struct evt_test *test, struct evt_options *opt)
1818 : : {
1819 : : uint16_t i;
1820 : : RTE_SET_USED(test);
1821 : :
1822 : 0 : if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
1823 : 0 : RTE_ETH_FOREACH_DEV(i) {
1824 : 0 : rte_event_eth_rx_adapter_stop(i);
1825 : 0 : rte_event_eth_rx_adapter_queue_del(i, i, -1);
1826 : 0 : rte_eth_dev_rx_queue_stop(i, 0);
1827 : : }
1828 : : }
1829 : 0 : }
1830 : :
1831 : : void
1832 : 0 : perf_ethdev_destroy(struct evt_test *test, struct evt_options *opt)
1833 : : {
1834 : : uint16_t i;
1835 : : RTE_SET_USED(test);
1836 : :
1837 : 0 : if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
1838 : 0 : RTE_ETH_FOREACH_DEV(i) {
1839 : 0 : rte_event_eth_tx_adapter_stop(i);
1840 : 0 : rte_event_eth_tx_adapter_queue_del(i, i, -1);
1841 : 0 : rte_eth_dev_tx_queue_stop(i, 0);
1842 : 0 : rte_eth_dev_stop(i);
1843 : : }
1844 : : }
1845 : 0 : }
1846 : :
1847 : : int
1848 : 0 : 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 : 0 : if (opt->prod_type != EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR)
1857 : : return 0;
1858 : :
1859 : 0 : cdev_count = rte_cryptodev_count();
1860 : 0 : if (cdev_count == 0) {
1861 : 0 : evt_err("No crypto devices available\n");
1862 : 0 : return -ENODEV;
1863 : : }
1864 : :
1865 : 0 : t->ca_op_pool = rte_crypto_op_pool_create(
1866 : 0 : "crypto_op_pool", opt->crypto_op_type, opt->pool_sz,
1867 : : 128, sizeof(union rte_event_crypto_metadata) + EVT_CRYPTO_MAX_IV_SIZE,
1868 : 0 : rte_socket_id());
1869 : 0 : if (t->ca_op_pool == NULL) {
1870 : 0 : evt_err("Failed to create crypto op pool");
1871 : 0 : return -ENOMEM;
1872 : : }
1873 : :
1874 : 0 : nb_sessions = evt_nr_active_lcores(opt->plcores) * t->nb_flows;
1875 : 0 : 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 : 0 : if (t->ca_asym_sess_pool == NULL) {
1879 : 0 : evt_err("Failed to create sym session pool");
1880 : : ret = -ENOMEM;
1881 : 0 : goto err;
1882 : : }
1883 : :
1884 : : max_session_size = 0;
1885 : 0 : for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) {
1886 : : unsigned int session_size;
1887 : :
1888 : : session_size =
1889 : 0 : 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 : 0 : 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 : 0 : if (t->ca_sess_pool == NULL) {
1898 : 0 : evt_err("Failed to create sym session pool");
1899 : : ret = -ENOMEM;
1900 : 0 : goto err;
1901 : : }
1902 : :
1903 : 0 : if (opt->ena_vector) {
1904 : 0 : unsigned int nb_elem = (opt->pool_sz / opt->vector_size) * 2;
1905 : 0 : nb_elem = RTE_MAX(512U, nb_elem);
1906 : 0 : nb_elem += evt_nr_active_lcores(opt->wlcores) * 32;
1907 : 0 : t->ca_vector_pool = rte_event_vector_pool_create("vector_pool", nb_elem, 32,
1908 : : opt->vector_size, opt->socket_id);
1909 : 0 : if (t->ca_vector_pool == NULL) {
1910 : 0 : evt_err("Failed to create event vector pool");
1911 : : ret = -ENOMEM;
1912 : 0 : 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 : 0 : nb_plcores = evt_nr_active_lcores(opt->plcores);
1923 : 0 : nb_qps = (nb_plcores % cdev_count) ? (nb_plcores / cdev_count) + 1 :
1924 : : nb_plcores / cdev_count;
1925 : 0 : 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 : 0 : rte_cryptodev_info_get(cdev_id, &info);
1932 : 0 : if (nb_qps > info.max_nb_queue_pairs) {
1933 : 0 : evt_err("Not enough queue pairs per cryptodev (%u)",
1934 : : nb_qps);
1935 : : ret = -EINVAL;
1936 : 0 : goto err;
1937 : : }
1938 : :
1939 : 0 : conf.nb_queue_pairs = nb_qps;
1940 : 0 : conf.socket_id = SOCKET_ID_ANY;
1941 : 0 : conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
1942 : :
1943 : 0 : ret = rte_cryptodev_configure(cdev_id, &conf);
1944 : 0 : if (ret) {
1945 : 0 : evt_err("Failed to configure cryptodev (%u)", cdev_id);
1946 : 0 : goto err;
1947 : : }
1948 : :
1949 : 0 : qp_conf.nb_descriptors = NB_CRYPTODEV_DESCRIPTORS;
1950 : 0 : qp_conf.mp_session = t->ca_sess_pool;
1951 : :
1952 : 0 : for (qp_id = 0; qp_id < conf.nb_queue_pairs; qp_id++) {
1953 : 0 : ret = rte_cryptodev_queue_pair_setup(
1954 : : cdev_id, qp_id, &qp_conf,
1955 : : rte_cryptodev_socket_id(cdev_id));
1956 : 0 : if (ret) {
1957 : 0 : evt_err("Failed to setup queue pairs on cryptodev %u\n",
1958 : : cdev_id);
1959 : 0 : goto err;
1960 : : }
1961 : : }
1962 : : }
1963 : :
1964 : : return 0;
1965 : 0 : err:
1966 : 0 : for (cdev_id = 0; cdev_id < cdev_count; cdev_id++)
1967 : 0 : rte_cryptodev_close(cdev_id);
1968 : :
1969 : 0 : rte_mempool_free(t->ca_op_pool);
1970 : 0 : rte_mempool_free(t->ca_sess_pool);
1971 : 0 : rte_mempool_free(t->ca_asym_sess_pool);
1972 : 0 : rte_mempool_free(t->ca_vector_pool);
1973 : :
1974 : 0 : return ret;
1975 : : }
1976 : :
1977 : : void
1978 : 0 : perf_cryptodev_destroy(struct evt_test *test, struct evt_options *opt)
1979 : : {
1980 : 0 : uint8_t cdev_id, cdev_count = rte_cryptodev_count();
1981 : : struct test_perf *t = evt_test_priv(test);
1982 : : uint16_t port;
1983 : :
1984 : 0 : if (opt->prod_type != EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR)
1985 : : return;
1986 : :
1987 : 0 : 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 : 0 : for (flow_id = 0; flow_id < t->nb_flows; flow_id++) {
1994 : 0 : sess = p->ca.crypto_sess[flow_id];
1995 : 0 : cdev_id = p->ca.cdev_id;
1996 : 0 : rte_cryptodev_sym_session_free(cdev_id, sess);
1997 : : }
1998 : :
1999 : 0 : rte_event_crypto_adapter_queue_pair_del(
2000 : 0 : TEST_PERF_CA_ID, p->ca.cdev_id, p->ca.cdev_qp_id);
2001 : : }
2002 : :
2003 : 0 : rte_event_crypto_adapter_free(TEST_PERF_CA_ID);
2004 : :
2005 : 0 : for (cdev_id = 0; cdev_id < cdev_count; cdev_id++) {
2006 : 0 : rte_cryptodev_stop(cdev_id);
2007 : 0 : rte_cryptodev_close(cdev_id);
2008 : : }
2009 : :
2010 : 0 : rte_mempool_free(t->ca_op_pool);
2011 : 0 : rte_mempool_free(t->ca_sess_pool);
2012 : 0 : rte_mempool_free(t->ca_asym_sess_pool);
2013 : 0 : rte_mempool_free(t->ca_vector_pool);
2014 : : }
2015 : :
2016 : : int
2017 : 0 : perf_dmadev_setup(struct evt_test *test, struct evt_options *opt)
2018 : : {
2019 : 0 : const struct rte_dma_conf conf = { .nb_vchans = 1};
2020 : 0 : 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 : 0 : if (opt->prod_type != EVT_PROD_TYPE_EVENT_DMA_ADPTR)
2031 : : return 0;
2032 : :
2033 : 0 : dma_dev_count = rte_dma_count_avail();
2034 : 0 : if (dma_dev_count == 0) {
2035 : 0 : evt_err("No dma devices available\n");
2036 : 0 : return -ENODEV;
2037 : : }
2038 : :
2039 : : elt_size = sizeof(struct rte_event_dma_adapter_op) + sizeof(struct rte_event);
2040 : 0 : t->da_op_pool = rte_mempool_create("dma_op_pool", opt->pool_sz, elt_size, 256,
2041 : 0 : 0, NULL, NULL, NULL, NULL, rte_socket_id(), 0);
2042 : 0 : if (t->da_op_pool == NULL) {
2043 : 0 : evt_err("Failed to create dma op pool");
2044 : 0 : return -ENOMEM;
2045 : : }
2046 : :
2047 : 0 : ret = rte_dma_configure(dma_dev_id, &conf);
2048 : 0 : if (ret) {
2049 : 0 : evt_err("Failed to configure dma dev (%u)", dma_dev_id);
2050 : 0 : goto err;
2051 : : }
2052 : :
2053 : 0 : for (vchan_id = 0; vchan_id < conf.nb_vchans; vchan_id++) {
2054 : 0 : ret = rte_dma_vchan_setup(dma_dev_id, vchan_id, &qconf);
2055 : 0 : if (ret) {
2056 : 0 : evt_err("Failed to setup vchan on dma dev %u\n",
2057 : : dma_dev_id);
2058 : 0 : goto err;
2059 : : }
2060 : : }
2061 : :
2062 : : return 0;
2063 : 0 : err:
2064 : 0 : rte_dma_close(dma_dev_id);
2065 : 0 : rte_mempool_free(t->da_op_pool);
2066 : :
2067 : 0 : return ret;
2068 : : }
2069 : :
2070 : : void
2071 : 0 : 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 : 0 : if (opt->prod_type != EVT_PROD_TYPE_EVENT_DMA_ADPTR)
2078 : : return;
2079 : :
2080 : 0 : 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 : 0 : for (flow_id = 0; flow_id < t->nb_flows; flow_id++) {
2086 : 0 : op = p->da.dma_op[flow_id];
2087 : :
2088 : 0 : rte_pktmbuf_free((struct rte_mbuf *)(uintptr_t)op->src_seg->addr);
2089 : 0 : rte_pktmbuf_free((struct rte_mbuf *)(uintptr_t)op->dst_seg->addr);
2090 : 0 : rte_free(op->src_seg);
2091 : 0 : rte_free(op->dst_seg);
2092 : 0 : rte_mempool_put(op->op_mp, op);
2093 : : }
2094 : :
2095 : 0 : rte_event_dma_adapter_vchan_del(TEST_PERF_DA_ID, p->da.dma_dev_id, p->da.vchan_id);
2096 : : }
2097 : :
2098 : 0 : rte_event_dma_adapter_free(TEST_PERF_DA_ID);
2099 : :
2100 : 0 : rte_dma_stop(dma_dev_id);
2101 : 0 : rte_dma_close(dma_dev_id);
2102 : :
2103 : 0 : rte_mempool_free(t->da_op_pool);
2104 : : }
2105 : :
2106 : : int
2107 : 0 : 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 : 0 : cache_sz = RTE_MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, (opt->pool_sz / 1.5) / t->nb_workers);
2113 : 0 : if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
2114 : : opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
2115 : 0 : 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 : 0 : } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR &&
2123 : 0 : opt->crypto_op_type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
2124 : 0 : t->pool = rte_mempool_create(test->name, /* mempool name */
2125 : : opt->pool_sz, /* number of elements*/
2126 : 0 : 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 : 0 : 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 : 0 : if (t->pool == NULL) {
2142 : 0 : evt_err("failed to create mempool");
2143 : 0 : return -ENOMEM;
2144 : : }
2145 : :
2146 : : return 0;
2147 : : }
2148 : :
2149 : : void
2150 : 0 : 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 : 0 : rte_mempool_free(t->pool);
2156 : 0 : }
2157 : :
2158 : : int
2159 : 0 : perf_test_setup(struct evt_test *test, struct evt_options *opt)
2160 : : {
2161 : : void *test_perf;
2162 : :
2163 : 0 : test_perf = rte_zmalloc_socket(test->name, sizeof(struct test_perf),
2164 : : RTE_CACHE_LINE_SIZE, opt->socket_id);
2165 : 0 : if (test_perf == NULL) {
2166 : 0 : evt_err("failed to allocate test_perf memory");
2167 : 0 : goto nomem;
2168 : : }
2169 : 0 : test->test_priv = test_perf;
2170 : :
2171 : : struct test_perf *t = evt_test_priv(test);
2172 : :
2173 : 0 : if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
2174 : 0 : t->outstand_pkts = opt->nb_timers *
2175 : 0 : evt_nr_active_lcores(opt->plcores);
2176 : 0 : t->nb_pkts = opt->nb_timers;
2177 : : } else {
2178 : 0 : t->outstand_pkts = opt->nb_pkts *
2179 : 0 : evt_nr_active_lcores(opt->plcores);
2180 : 0 : t->nb_pkts = opt->nb_pkts;
2181 : : }
2182 : :
2183 : 0 : t->nb_workers = evt_nr_active_lcores(opt->wlcores);
2184 : 0 : t->done = false;
2185 : 0 : t->nb_flows = opt->nb_flows;
2186 : 0 : t->result = EVT_TEST_FAILED;
2187 : 0 : t->opt = opt;
2188 : 0 : memcpy(t->sched_type_list, opt->sched_type_list,
2189 : : sizeof(opt->sched_type_list));
2190 : 0 : return 0;
2191 : : nomem:
2192 : 0 : return -ENOMEM;
2193 : : }
2194 : :
2195 : : void
2196 : 0 : perf_test_destroy(struct evt_test *test, struct evt_options *opt)
2197 : : {
2198 : : RTE_SET_USED(opt);
2199 : :
2200 : 0 : rte_free(test->test_priv);
2201 : 0 : }
|