app/eventdev: add event timer adapter as a producer
[dpdk.git] / app / test-eventdev / test_perf_common.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Cavium, Inc
3  */
4
5 #include "test_perf_common.h"
6
7 int
8 perf_test_result(struct evt_test *test, struct evt_options *opt)
9 {
10         RTE_SET_USED(opt);
11         int i;
12         uint64_t total = 0;
13         struct test_perf *t = evt_test_priv(test);
14
15         printf("Packet distribution across worker cores :\n");
16         for (i = 0; i < t->nb_workers; i++)
17                 total += t->worker[i].processed_pkts;
18         for (i = 0; i < t->nb_workers; i++)
19                 printf("Worker %d packets: "CLGRN"%"PRIx64" "CLNRM"percentage:"
20                                 CLGRN" %3.2f\n"CLNRM, i,
21                                 t->worker[i].processed_pkts,
22                                 (((double)t->worker[i].processed_pkts)/total)
23                                 * 100);
24
25         return t->result;
26 }
27
28 static inline int
29 perf_producer(void *arg)
30 {
31         struct prod_data *p  = arg;
32         struct test_perf *t = p->t;
33         struct evt_options *opt = t->opt;
34         const uint8_t dev_id = p->dev_id;
35         const uint8_t port = p->port_id;
36         struct rte_mempool *pool = t->pool;
37         const uint64_t nb_pkts = t->nb_pkts;
38         const uint32_t nb_flows = t->nb_flows;
39         uint32_t flow_counter = 0;
40         uint64_t count = 0;
41         struct perf_elt *m;
42         struct rte_event ev;
43
44         if (opt->verbose_level > 1)
45                 printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__,
46                                 rte_lcore_id(), dev_id, port, p->queue_id);
47
48         ev.event = 0;
49         ev.op = RTE_EVENT_OP_NEW;
50         ev.queue_id = p->queue_id;
51         ev.sched_type = t->opt->sched_type_list[0];
52         ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
53         ev.event_type =  RTE_EVENT_TYPE_CPU;
54         ev.sub_event_type = 0; /* stage 0 */
55
56         while (count < nb_pkts && t->done == false) {
57                 if (rte_mempool_get(pool, (void **)&m) < 0)
58                         continue;
59
60                 ev.flow_id = flow_counter++ % nb_flows;
61                 ev.event_ptr = m;
62                 m->timestamp = rte_get_timer_cycles();
63                 while (rte_event_enqueue_burst(dev_id, port, &ev, 1) != 1) {
64                         if (t->done)
65                                 break;
66                         rte_pause();
67                         m->timestamp = rte_get_timer_cycles();
68                 }
69                 count++;
70         }
71
72         return 0;
73 }
74
75 static inline int
76 perf_event_timer_producer(void *arg)
77 {
78         struct prod_data *p  = arg;
79         struct test_perf *t = p->t;
80         struct evt_options *opt = t->opt;
81         uint32_t flow_counter = 0;
82         uint64_t count = 0;
83         uint64_t arm_latency = 0;
84         const uint8_t nb_timer_adptrs = opt->nb_timer_adptrs;
85         const uint32_t nb_flows = t->nb_flows;
86         const uint64_t nb_timers = opt->nb_timers;
87         struct rte_mempool *pool = t->pool;
88         struct perf_elt *m;
89         struct rte_event_timer_adapter **adptr = t->timer_adptr;
90         uint64_t timeout_ticks = opt->expiry_nsec / opt->timer_tick_nsec;
91
92         timeout_ticks = opt->optm_timer_tick_nsec ?
93                         (timeout_ticks * opt->timer_tick_nsec)
94                         / opt->optm_timer_tick_nsec : timeout_ticks;
95         timeout_ticks += timeout_ticks ? 0 : 1;
96         const struct rte_event_timer tim = {
97                 .ev.op = RTE_EVENT_OP_NEW,
98                 .ev.queue_id = p->queue_id,
99                 .ev.sched_type = t->opt->sched_type_list[0],
100                 .ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
101                 .ev.event_type =  RTE_EVENT_TYPE_TIMER,
102                 .state = RTE_EVENT_TIMER_NOT_ARMED,
103                 .timeout_ticks = timeout_ticks,
104         };
105
106         if (opt->verbose_level > 1)
107                 printf("%s(): lcore %d\n", __func__, rte_lcore_id());
108
109         while (count < nb_timers && t->done == false) {
110                 if (rte_mempool_get(pool, (void **)&m) < 0)
111                         continue;
112
113                 m->tim = tim;
114                 m->tim.ev.flow_id = flow_counter++ % nb_flows;
115                 m->tim.ev.event_ptr = m;
116                 m->timestamp = rte_get_timer_cycles();
117                 while (rte_event_timer_arm_burst(
118                                 adptr[flow_counter % nb_timer_adptrs],
119                                 (struct rte_event_timer **)&m, 1) != 1) {
120                         if (t->done)
121                                 break;
122                         rte_pause();
123                         m->timestamp = rte_get_timer_cycles();
124                 }
125                 arm_latency += rte_get_timer_cycles() - m->timestamp;
126                 count++;
127         }
128         fflush(stdout);
129         rte_delay_ms(1000);
130         printf("%s(): lcore %d Average event timer arm latency = %.3f us\n",
131                         __func__, rte_lcore_id(), (float)(arm_latency / count) /
132                         (rte_get_timer_hz() / 1000000));
133         return 0;
134 }
135
136 static int
137 perf_producer_wrapper(void *arg)
138 {
139         struct prod_data *p  = arg;
140         struct test_perf *t = p->t;
141         /* Launch the producer function only in case of synthetic producer. */
142         if (t->opt->prod_type == EVT_PROD_TYPE_SYNT)
143                 return perf_producer(arg);
144         else if (t->opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR)
145                 return perf_event_timer_producer(arg);
146         return 0;
147 }
148
149 static inline uint64_t
150 processed_pkts(struct test_perf *t)
151 {
152         uint8_t i;
153         uint64_t total = 0;
154
155         rte_smp_rmb();
156         for (i = 0; i < t->nb_workers; i++)
157                 total += t->worker[i].processed_pkts;
158
159         return total;
160 }
161
162 static inline uint64_t
163 total_latency(struct test_perf *t)
164 {
165         uint8_t i;
166         uint64_t total = 0;
167
168         rte_smp_rmb();
169         for (i = 0; i < t->nb_workers; i++)
170                 total += t->worker[i].latency;
171
172         return total;
173 }
174
175
176 int
177 perf_launch_lcores(struct evt_test *test, struct evt_options *opt,
178                 int (*worker)(void *))
179 {
180         int ret, lcore_id;
181         struct test_perf *t = evt_test_priv(test);
182
183         int port_idx = 0;
184         /* launch workers */
185         RTE_LCORE_FOREACH_SLAVE(lcore_id) {
186                 if (!(opt->wlcores[lcore_id]))
187                         continue;
188
189                 ret = rte_eal_remote_launch(worker,
190                                  &t->worker[port_idx], lcore_id);
191                 if (ret) {
192                         evt_err("failed to launch worker %d", lcore_id);
193                         return ret;
194                 }
195                 port_idx++;
196         }
197
198         /* launch producers */
199         RTE_LCORE_FOREACH_SLAVE(lcore_id) {
200                 if (!(opt->plcores[lcore_id]))
201                         continue;
202
203                 ret = rte_eal_remote_launch(perf_producer_wrapper,
204                                 &t->prod[port_idx], lcore_id);
205                 if (ret) {
206                         evt_err("failed to launch perf_producer %d", lcore_id);
207                         return ret;
208                 }
209                 port_idx++;
210         }
211
212         const uint64_t total_pkts = t->outstand_pkts;
213
214         uint64_t dead_lock_cycles = rte_get_timer_cycles();
215         int64_t dead_lock_remaining  =  total_pkts;
216         const uint64_t dead_lock_sample = rte_get_timer_hz() * 5;
217
218         uint64_t perf_cycles = rte_get_timer_cycles();
219         int64_t perf_remaining  = total_pkts;
220         const uint64_t perf_sample = rte_get_timer_hz();
221
222         static float total_mpps;
223         static uint64_t samples;
224
225         const uint64_t freq_mhz = rte_get_timer_hz() / 1000000;
226         int64_t remaining = t->outstand_pkts - processed_pkts(t);
227
228         while (t->done == false) {
229                 const uint64_t new_cycles = rte_get_timer_cycles();
230
231                 if ((new_cycles - perf_cycles) > perf_sample) {
232                         const uint64_t latency = total_latency(t);
233                         const uint64_t pkts = processed_pkts(t);
234
235                         remaining = t->outstand_pkts - pkts;
236                         float mpps = (float)(perf_remaining-remaining)/1000000;
237
238                         perf_remaining = remaining;
239                         perf_cycles = new_cycles;
240                         total_mpps += mpps;
241                         ++samples;
242                         if (opt->fwd_latency && pkts > 0) {
243                                 printf(CLGRN"\r%.3f mpps avg %.3f mpps [avg fwd latency %.3f us] "CLNRM,
244                                         mpps, total_mpps/samples,
245                                         (float)(latency/pkts)/freq_mhz);
246                         } else {
247                                 printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM,
248                                         mpps, total_mpps/samples);
249                         }
250                         fflush(stdout);
251
252                         if (remaining <= 0) {
253                                 t->result = EVT_TEST_SUCCESS;
254                                 if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
255                                         opt->prod_type ==
256                                         EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
257                                         t->done = true;
258                                         rte_smp_wmb();
259                                         break;
260                                 }
261                         }
262                 }
263
264                 if (new_cycles - dead_lock_cycles > dead_lock_sample &&
265                                 opt->prod_type == EVT_PROD_TYPE_SYNT) {
266                         remaining = t->outstand_pkts - processed_pkts(t);
267                         if (dead_lock_remaining == remaining) {
268                                 rte_event_dev_dump(opt->dev_id, stdout);
269                                 evt_err("No schedules for seconds, deadlock");
270                                 t->done = true;
271                                 rte_smp_wmb();
272                                 break;
273                         }
274                         dead_lock_remaining = remaining;
275                         dead_lock_cycles = new_cycles;
276                 }
277         }
278         printf("\n");
279         return 0;
280 }
281
282 static int
283 perf_event_rx_adapter_setup(struct evt_options *opt, uint8_t stride,
284                 struct rte_event_port_conf prod_conf)
285 {
286         int ret = 0;
287         uint16_t prod;
288         struct rte_event_eth_rx_adapter_queue_conf queue_conf;
289
290         memset(&queue_conf, 0,
291                         sizeof(struct rte_event_eth_rx_adapter_queue_conf));
292         queue_conf.ev.sched_type = opt->sched_type_list[0];
293         for (prod = 0; prod < rte_eth_dev_count(); prod++) {
294                 uint32_t cap;
295
296                 ret = rte_event_eth_rx_adapter_caps_get(opt->dev_id,
297                                 prod, &cap);
298                 if (ret) {
299                         evt_err("failed to get event rx adapter[%d]"
300                                         " capabilities",
301                                         opt->dev_id);
302                         return ret;
303                 }
304                 queue_conf.ev.queue_id = prod * stride;
305                 ret = rte_event_eth_rx_adapter_create(prod, opt->dev_id,
306                                 &prod_conf);
307                 if (ret) {
308                         evt_err("failed to create rx adapter[%d]", prod);
309                         return ret;
310                 }
311                 ret = rte_event_eth_rx_adapter_queue_add(prod, prod, -1,
312                                 &queue_conf);
313                 if (ret) {
314                         evt_err("failed to add rx queues to adapter[%d]", prod);
315                         return ret;
316                 }
317
318                 if (!(cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) {
319                         uint32_t service_id;
320
321                         rte_event_eth_rx_adapter_service_id_get(prod,
322                                         &service_id);
323                         ret = evt_service_setup(service_id);
324                         if (ret) {
325                                 evt_err("Failed to setup service core"
326                                                 " for Rx adapter\n");
327                                 return ret;
328                         }
329                 }
330
331                 ret = rte_eth_dev_start(prod);
332                 if (ret) {
333                         evt_err("Ethernet dev [%d] failed to start."
334                                         " Using synthetic producer", prod);
335                         return ret;
336                 }
337
338                 ret = rte_event_eth_rx_adapter_start(prod);
339                 if (ret) {
340                         evt_err("Rx adapter[%d] start failed", prod);
341                         return ret;
342                 }
343                 printf("%s: Port[%d] using Rx adapter[%d] started\n", __func__,
344                                 prod, prod);
345         }
346
347         return ret;
348 }
349
350 static int
351 perf_event_timer_adapter_setup(struct test_perf *t)
352 {
353         int i;
354         int ret;
355         struct rte_event_timer_adapter_info adapter_info;
356         struct rte_event_timer_adapter *wl;
357         uint8_t nb_producers = evt_nr_active_lcores(t->opt->plcores);
358         uint8_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
359
360         if (nb_producers == 1)
361                 flags |= RTE_EVENT_TIMER_ADAPTER_F_SP_PUT;
362
363         for (i = 0; i < t->opt->nb_timer_adptrs; i++) {
364                 struct rte_event_timer_adapter_conf config = {
365                         .event_dev_id = t->opt->dev_id,
366                         .timer_adapter_id = i,
367                         .timer_tick_ns = t->opt->timer_tick_nsec,
368                         .max_tmo_ns = t->opt->max_tmo_nsec,
369                         .nb_timers = 2 * 1024 * 1024,
370                         .flags = flags,
371                 };
372
373                 wl = rte_event_timer_adapter_create(&config);
374                 if (wl == NULL) {
375                         evt_err("failed to create event timer ring %d", i);
376                         return rte_errno;
377                 }
378
379                 memset(&adapter_info, 0,
380                                 sizeof(struct rte_event_timer_adapter_info));
381                 rte_event_timer_adapter_get_info(wl, &adapter_info);
382                 t->opt->optm_timer_tick_nsec = adapter_info.min_resolution_ns;
383
384                 if (!(adapter_info.caps &
385                                 RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT)) {
386                         uint32_t service_id;
387
388                         rte_event_timer_adapter_service_id_get(wl,
389                                         &service_id);
390                         ret = evt_service_setup(service_id);
391                         if (ret) {
392                                 evt_err("Failed to setup service core"
393                                                 " for timer adapter\n");
394                                 return ret;
395                         }
396                         rte_service_runstate_set(service_id, 1);
397                 }
398
399                 ret = rte_event_timer_adapter_start(wl);
400                 if (ret) {
401                         evt_err("failed to Start event timer adapter %d", i);
402                         return ret;
403                 }
404                 t->timer_adptr[i] = wl;
405         }
406         return 0;
407 }
408
409 int
410 perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt,
411                                 uint8_t stride, uint8_t nb_queues,
412                                 const struct rte_event_port_conf *port_conf)
413 {
414         struct test_perf *t = evt_test_priv(test);
415         uint16_t port, prod;
416         int ret = -1;
417
418         /* setup one port per worker, linking to all queues */
419         for (port = 0; port < evt_nr_active_lcores(opt->wlcores);
420                                 port++) {
421                 struct worker_data *w = &t->worker[port];
422
423                 w->dev_id = opt->dev_id;
424                 w->port_id = port;
425                 w->t = t;
426                 w->processed_pkts = 0;
427                 w->latency = 0;
428
429                 ret = rte_event_port_setup(opt->dev_id, port, port_conf);
430                 if (ret) {
431                         evt_err("failed to setup port %d", port);
432                         return ret;
433                 }
434
435                 ret = rte_event_port_link(opt->dev_id, port, NULL, NULL, 0);
436                 if (ret != nb_queues) {
437                         evt_err("failed to link all queues to port %d", port);
438                         return -EINVAL;
439                 }
440         }
441
442         /* port for producers, no links */
443         if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
444                 for ( ; port < perf_nb_event_ports(opt); port++) {
445                         struct prod_data *p = &t->prod[port];
446                         p->t = t;
447                 }
448
449                 ret = perf_event_rx_adapter_setup(opt, stride, *port_conf);
450                 if (ret)
451                         return ret;
452         } else if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
453                 prod = 0;
454                 for ( ; port < perf_nb_event_ports(opt); port++) {
455                         struct prod_data *p = &t->prod[port];
456                         p->queue_id = prod * stride;
457                         p->t = t;
458                         prod++;
459                 }
460
461                 ret = perf_event_timer_adapter_setup(t);
462                 if (ret)
463                         return ret;
464         } else {
465                 prod = 0;
466                 for ( ; port < perf_nb_event_ports(opt); port++) {
467                         struct prod_data *p = &t->prod[port];
468
469                         p->dev_id = opt->dev_id;
470                         p->port_id = port;
471                         p->queue_id = prod * stride;
472                         p->t = t;
473
474                         ret = rte_event_port_setup(opt->dev_id, port,
475                                         port_conf);
476                         if (ret) {
477                                 evt_err("failed to setup port %d", port);
478                                 return ret;
479                         }
480                         prod++;
481                 }
482         }
483
484         return ret;
485 }
486
487 int
488 perf_opt_check(struct evt_options *opt, uint64_t nb_queues)
489 {
490         unsigned int lcores;
491
492         /* N producer + N worker + 1 master when producer cores are used
493          * Else N worker + 1 master when Rx adapter is used
494          */
495         lcores = opt->prod_type == EVT_PROD_TYPE_SYNT ? 3 : 2;
496
497         if (rte_lcore_count() < lcores) {
498                 evt_err("test need minimum %d lcores", lcores);
499                 return -1;
500         }
501
502         /* Validate worker lcores */
503         if (evt_lcores_has_overlap(opt->wlcores, rte_get_master_lcore())) {
504                 evt_err("worker lcores overlaps with master lcore");
505                 return -1;
506         }
507         if (evt_lcores_has_overlap_multi(opt->wlcores, opt->plcores)) {
508                 evt_err("worker lcores overlaps producer lcores");
509                 return -1;
510         }
511         if (evt_has_disabled_lcore(opt->wlcores)) {
512                 evt_err("one or more workers lcores are not enabled");
513                 return -1;
514         }
515         if (!evt_has_active_lcore(opt->wlcores)) {
516                 evt_err("minimum one worker is required");
517                 return -1;
518         }
519
520         if (opt->prod_type == EVT_PROD_TYPE_SYNT) {
521                 /* Validate producer lcores */
522                 if (evt_lcores_has_overlap(opt->plcores,
523                                         rte_get_master_lcore())) {
524                         evt_err("producer lcores overlaps with master lcore");
525                         return -1;
526                 }
527                 if (evt_has_disabled_lcore(opt->plcores)) {
528                         evt_err("one or more producer lcores are not enabled");
529                         return -1;
530                 }
531                 if (!evt_has_active_lcore(opt->plcores)) {
532                         evt_err("minimum one producer is required");
533                         return -1;
534                 }
535         }
536
537         if (evt_has_invalid_stage(opt))
538                 return -1;
539
540         if (evt_has_invalid_sched_type(opt))
541                 return -1;
542
543         if (nb_queues > EVT_MAX_QUEUES) {
544                 evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
545                 return -1;
546         }
547         if (perf_nb_event_ports(opt) > EVT_MAX_PORTS) {
548                 evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
549                 return -1;
550         }
551
552         /* Fixups */
553         if ((opt->nb_stages == 1 &&
554                         opt->prod_type != EVT_PROD_TYPE_EVENT_TIMER_ADPTR) &&
555                         opt->fwd_latency) {
556                 evt_info("fwd_latency is valid when nb_stages > 1, disabling");
557                 opt->fwd_latency = 0;
558         }
559
560         if (opt->fwd_latency && !opt->q_priority) {
561                 evt_info("enabled queue priority for latency measurement");
562                 opt->q_priority = 1;
563         }
564         if (opt->nb_pkts == 0)
565                 opt->nb_pkts = INT64_MAX/evt_nr_active_lcores(opt->plcores);
566
567         return 0;
568 }
569
570 void
571 perf_opt_dump(struct evt_options *opt, uint8_t nb_queues)
572 {
573         evt_dump("nb_prod_lcores", "%d", evt_nr_active_lcores(opt->plcores));
574         evt_dump_producer_lcores(opt);
575         evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores));
576         evt_dump_worker_lcores(opt);
577         evt_dump_nb_stages(opt);
578         evt_dump("nb_evdev_ports", "%d", perf_nb_event_ports(opt));
579         evt_dump("nb_evdev_queues", "%d", nb_queues);
580         evt_dump_queue_priority(opt);
581         evt_dump_sched_type_list(opt);
582         evt_dump_producer_type(opt);
583 }
584
585 void
586 perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
587 {
588         int i;
589         struct test_perf *t = evt_test_priv(test);
590
591         if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
592                 for (i = 0; i < opt->nb_timer_adptrs; i++)
593                         rte_event_timer_adapter_stop(t->timer_adptr[i]);
594         }
595         rte_event_dev_stop(opt->dev_id);
596         rte_event_dev_close(opt->dev_id);
597 }
598
599 static inline void
600 perf_elt_init(struct rte_mempool *mp, void *arg __rte_unused,
601             void *obj, unsigned i __rte_unused)
602 {
603         memset(obj, 0, mp->elt_size);
604 }
605
606 #define NB_RX_DESC                      128
607 #define NB_TX_DESC                      512
608 int
609 perf_ethdev_setup(struct evt_test *test, struct evt_options *opt)
610 {
611         int i;
612         struct test_perf *t = evt_test_priv(test);
613         struct rte_eth_conf port_conf = {
614                 .rxmode = {
615                         .mq_mode = ETH_MQ_RX_RSS,
616                         .max_rx_pkt_len = ETHER_MAX_LEN,
617                         .split_hdr_size = 0,
618                         .header_split   = 0,
619                         .hw_ip_checksum = 0,
620                         .hw_vlan_filter = 0,
621                         .hw_vlan_strip  = 0,
622                         .hw_vlan_extend = 0,
623                         .jumbo_frame    = 0,
624                         .hw_strip_crc   = 1,
625                 },
626                 .rx_adv_conf = {
627                         .rss_conf = {
628                                 .rss_key = NULL,
629                                 .rss_hf = ETH_RSS_IP,
630                         },
631                 },
632         };
633
634         if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
635                         opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR)
636                 return 0;
637
638         if (!rte_eth_dev_count()) {
639                 evt_err("No ethernet ports found.");
640                 return -ENODEV;
641         }
642
643         for (i = 0; i < rte_eth_dev_count(); i++) {
644
645                 if (rte_eth_dev_configure(i, 1, 1,
646                                         &port_conf)
647                                 < 0) {
648                         evt_err("Failed to configure eth port [%d]", i);
649                         return -EINVAL;
650                 }
651
652                 if (rte_eth_rx_queue_setup(i, 0, NB_RX_DESC,
653                                 rte_socket_id(), NULL, t->pool) < 0) {
654                         evt_err("Failed to setup eth port [%d] rx_queue: %d.",
655                                         i, 0);
656                         return -EINVAL;
657                 }
658
659                 if (rte_eth_tx_queue_setup(i, 0, NB_TX_DESC,
660                                         rte_socket_id(), NULL) < 0) {
661                         evt_err("Failed to setup eth port [%d] tx_queue: %d.",
662                                         i, 0);
663                         return -EINVAL;
664                 }
665
666                 rte_eth_promiscuous_enable(i);
667         }
668
669         return 0;
670 }
671
672 void perf_ethdev_destroy(struct evt_test *test, struct evt_options *opt)
673 {
674         int i;
675         RTE_SET_USED(test);
676
677         if (opt->prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
678                 for (i = 0; i < rte_eth_dev_count(); i++) {
679                         rte_event_eth_rx_adapter_stop(i);
680                         rte_eth_dev_stop(i);
681                         rte_eth_dev_close(i);
682                 }
683         }
684 }
685
686 int
687 perf_mempool_setup(struct evt_test *test, struct evt_options *opt)
688 {
689         struct test_perf *t = evt_test_priv(test);
690
691         if (opt->prod_type == EVT_PROD_TYPE_SYNT ||
692                         opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
693                 t->pool = rte_mempool_create(test->name, /* mempool name */
694                                 opt->pool_sz, /* number of elements*/
695                                 sizeof(struct perf_elt), /* element size*/
696                                 512, /* cache size*/
697                                 0, NULL, NULL,
698                                 perf_elt_init, /* obj constructor */
699                                 NULL, opt->socket_id, 0); /* flags */
700         } else {
701                 t->pool = rte_pktmbuf_pool_create(test->name, /* mempool name */
702                                 opt->pool_sz, /* number of elements*/
703                                 512, /* cache size*/
704                                 0,
705                                 RTE_MBUF_DEFAULT_BUF_SIZE,
706                                 opt->socket_id); /* flags */
707
708         }
709
710         if (t->pool == NULL) {
711                 evt_err("failed to create mempool");
712                 return -ENOMEM;
713         }
714
715         return 0;
716 }
717
718 void
719 perf_mempool_destroy(struct evt_test *test, struct evt_options *opt)
720 {
721         RTE_SET_USED(opt);
722         struct test_perf *t = evt_test_priv(test);
723
724         rte_mempool_free(t->pool);
725 }
726
727 int
728 perf_test_setup(struct evt_test *test, struct evt_options *opt)
729 {
730         void *test_perf;
731
732         test_perf = rte_zmalloc_socket(test->name, sizeof(struct test_perf),
733                                 RTE_CACHE_LINE_SIZE, opt->socket_id);
734         if (test_perf  == NULL) {
735                 evt_err("failed to allocate test_perf memory");
736                 goto nomem;
737         }
738         test->test_priv = test_perf;
739
740         struct test_perf *t = evt_test_priv(test);
741
742         if (opt->prod_type == EVT_PROD_TYPE_EVENT_TIMER_ADPTR) {
743                 t->outstand_pkts = opt->nb_timers *
744                         evt_nr_active_lcores(opt->plcores);
745                 t->nb_pkts = opt->nb_timers;
746         } else {
747                 t->outstand_pkts = opt->nb_pkts *
748                         evt_nr_active_lcores(opt->plcores);
749                 t->nb_pkts = opt->nb_pkts;
750         }
751
752         t->nb_workers = evt_nr_active_lcores(opt->wlcores);
753         t->done = false;
754         t->nb_flows = opt->nb_flows;
755         t->result = EVT_TEST_FAILED;
756         t->opt = opt;
757         memcpy(t->sched_type_list, opt->sched_type_list,
758                         sizeof(opt->sched_type_list));
759         return 0;
760 nomem:
761         return -ENOMEM;
762 }
763
764 void
765 perf_test_destroy(struct evt_test *test, struct evt_options *opt)
766 {
767         RTE_SET_USED(opt);
768
769         rte_free(test->test_priv);
770 }