6c9ac611923112201843f985d73e4e20298939f1
[dpdk.git] / app / test-eventdev / test_pipeline_atq.c
1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * Copyright 2017 Cavium, Inc.
4  */
5
6 #include "test_pipeline_common.h"
7
8 /* See http://dpdk.org/doc/guides/tools/testeventdev.html for test details */
9
10 static __rte_always_inline int
11 pipeline_atq_nb_event_queues(struct evt_options *opt)
12 {
13         RTE_SET_USED(opt);
14
15         return rte_eth_dev_count();
16 }
17
18 static int
19 worker_wrapper(void *arg)
20 {
21         RTE_SET_USED(arg);
22         rte_panic("invalid worker\n");
23 }
24
25 static int
26 pipeline_atq_launch_lcores(struct evt_test *test, struct evt_options *opt)
27 {
28         struct test_pipeline *t = evt_test_priv(test);
29
30         if (t->mt_unsafe)
31                 rte_service_component_runstate_set(t->tx_service.service_id, 1);
32         return pipeline_launch_lcores(test, opt, worker_wrapper);
33 }
34
35 static int
36 pipeline_atq_eventdev_setup(struct evt_test *test, struct evt_options *opt)
37 {
38         int ret;
39         int nb_ports;
40         int nb_queues;
41         uint8_t queue;
42         struct rte_event_dev_info info;
43         struct test_pipeline *t = evt_test_priv(test);
44         uint8_t tx_evqueue_id = 0;
45         uint8_t queue_arr[RTE_EVENT_MAX_QUEUES_PER_DEV];
46         uint8_t nb_worker_queues = 0;
47
48         nb_ports = evt_nr_active_lcores(opt->wlcores);
49         nb_queues = rte_eth_dev_count();
50
51         /* One extra port and queueu for Tx service */
52         if (t->mt_unsafe) {
53                 tx_evqueue_id = nb_queues;
54                 nb_ports++;
55                 nb_queues++;
56         }
57
58
59         rte_event_dev_info_get(opt->dev_id, &info);
60
61         const struct rte_event_dev_config config = {
62                         .nb_event_queues = nb_queues,
63                         .nb_event_ports = nb_ports,
64                         .nb_events_limit  = info.max_num_events,
65                         .nb_event_queue_flows = opt->nb_flows,
66                         .nb_event_port_dequeue_depth =
67                                 info.max_event_port_dequeue_depth,
68                         .nb_event_port_enqueue_depth =
69                                 info.max_event_port_enqueue_depth,
70         };
71         ret = rte_event_dev_configure(opt->dev_id, &config);
72         if (ret) {
73                 evt_err("failed to configure eventdev %d", opt->dev_id);
74                 return ret;
75         }
76
77         struct rte_event_queue_conf q_conf = {
78                         .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
79                         .nb_atomic_flows = opt->nb_flows,
80                         .nb_atomic_order_sequences = opt->nb_flows,
81         };
82         /* queue configurations */
83         for (queue = 0; queue < nb_queues; queue++) {
84                 q_conf.event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
85
86                 if (t->mt_unsafe) {
87                         if (queue == tx_evqueue_id) {
88                                 q_conf.event_queue_cfg =
89                                         RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
90                         } else {
91                                 queue_arr[nb_worker_queues] = queue;
92                                 nb_worker_queues++;
93                         }
94                 }
95
96                 ret = rte_event_queue_setup(opt->dev_id, queue, &q_conf);
97                 if (ret) {
98                         evt_err("failed to setup queue=%d", queue);
99                         return ret;
100                 }
101         }
102
103         /* port configuration */
104         const struct rte_event_port_conf p_conf = {
105                         .dequeue_depth = opt->wkr_deq_dep,
106                         .enqueue_depth = info.max_event_port_dequeue_depth,
107                         .new_event_threshold = info.max_num_events,
108         };
109
110         if (t->mt_unsafe) {
111                 ret = pipeline_event_port_setup(test, opt, queue_arr,
112                                 nb_worker_queues, p_conf);
113                 if (ret)
114                         return ret;
115
116                 ret = pipeline_event_tx_service_setup(test, opt, tx_evqueue_id,
117                                 nb_ports - 1, p_conf);
118         } else
119                 ret = pipeline_event_port_setup(test, opt, NULL, nb_queues,
120                                 p_conf);
121
122         if (ret)
123                 return ret;
124
125         /*
126          * The pipelines are setup in the following manner:
127          *
128          * eth_dev_count = 2, nb_stages = 2, atq mode
129          *
130          * Multi thread safe :
131          *      queues = 2
132          *      stride = 1
133          *
134          *      event queue pipelines:
135          *      eth0 -> q0 ->tx
136          *      eth1 -> q1 ->tx
137          *
138          *      q0, q1 are configured as ATQ so, all the different stages can
139          *      be enqueued on the same queue.
140          *
141          * Multi thread unsafe :
142          *      queues = 3
143          *      stride = 1
144          *
145          *      event queue pipelines:
146          *      eth0 -> q0
147          *                } (q3->tx) Tx service
148          *      eth1 -> q1
149          *
150          *      q0,q1 are configured as stated above.
151          *      q3 configured as SINGLE_LINK|ATOMIC.
152          */
153         ret = pipeline_event_rx_adapter_setup(opt, 1, p_conf);
154         if (ret)
155                 return ret;
156
157         if (!evt_has_distributed_sched(opt->dev_id)) {
158                 uint32_t service_id;
159                 rte_event_dev_service_id_get(opt->dev_id, &service_id);
160                 ret = evt_service_setup(service_id);
161                 if (ret) {
162                         evt_err("No service lcore found to run event dev.");
163                         return ret;
164                 }
165         }
166
167         ret = rte_event_dev_start(opt->dev_id);
168         if (ret) {
169                 evt_err("failed to start eventdev %d", opt->dev_id);
170                 return ret;
171         }
172
173         return 0;
174 }
175
176 static void
177 pipeline_atq_opt_dump(struct evt_options *opt)
178 {
179         pipeline_opt_dump(opt, pipeline_atq_nb_event_queues(opt));
180 }
181
182 static int
183 pipeline_atq_opt_check(struct evt_options *opt)
184 {
185         return pipeline_opt_check(opt, pipeline_atq_nb_event_queues(opt));
186 }
187
188 static bool
189 pipeline_atq_capability_check(struct evt_options *opt)
190 {
191         struct rte_event_dev_info dev_info;
192
193         rte_event_dev_info_get(opt->dev_id, &dev_info);
194         if (dev_info.max_event_queues < pipeline_atq_nb_event_queues(opt) ||
195                         dev_info.max_event_ports <
196                         evt_nr_active_lcores(opt->wlcores)) {
197                 evt_err("not enough eventdev queues=%d/%d or ports=%d/%d",
198                         pipeline_atq_nb_event_queues(opt),
199                         dev_info.max_event_queues,
200                         evt_nr_active_lcores(opt->wlcores),
201                         dev_info.max_event_ports);
202         }
203
204         return true;
205 }
206
207 static const struct evt_test_ops pipeline_atq =  {
208         .cap_check          = pipeline_atq_capability_check,
209         .opt_check          = pipeline_atq_opt_check,
210         .opt_dump           = pipeline_atq_opt_dump,
211         .test_setup         = pipeline_test_setup,
212         .mempool_setup      = pipeline_mempool_setup,
213         .ethdev_setup       = pipeline_ethdev_setup,
214         .eventdev_setup     = pipeline_atq_eventdev_setup,
215         .launch_lcores      = pipeline_atq_launch_lcores,
216         .eventdev_destroy   = pipeline_eventdev_destroy,
217         .mempool_destroy    = pipeline_mempool_destroy,
218         .ethdev_destroy     = pipeline_ethdev_destroy,
219         .test_result        = pipeline_test_result,
220         .test_destroy       = pipeline_test_destroy,
221 };
222
223 EVT_TEST_REGISTER(pipeline_atq);