app/testeventdev: add perf opt dump and check functions
[dpdk.git] / app / test-eventdev / test_perf_common.c
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium 2017.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium networks nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include "test_perf_common.h"
34
35 int
36 perf_test_result(struct evt_test *test, struct evt_options *opt)
37 {
38         RTE_SET_USED(opt);
39         struct test_perf *t = evt_test_priv(test);
40
41         return t->result;
42 }
43
44 int
45 perf_opt_check(struct evt_options *opt, uint64_t nb_queues)
46 {
47         unsigned int lcores;
48         bool need_slcore = !evt_has_distributed_sched(opt->dev_id);
49
50         /* N producer + N worker + 1 scheduler(based on dev capa) + 1 master */
51         lcores = need_slcore ? 4 : 3;
52
53         if (rte_lcore_count() < lcores) {
54                 evt_err("test need minimum %d lcores", lcores);
55                 return -1;
56         }
57
58         /* Validate worker lcores */
59         if (evt_lcores_has_overlap(opt->wlcores, rte_get_master_lcore())) {
60                 evt_err("worker lcores overlaps with master lcore");
61                 return -1;
62         }
63         if (need_slcore && evt_lcores_has_overlap(opt->wlcores, opt->slcore)) {
64                 evt_err("worker lcores overlaps with scheduler lcore");
65                 return -1;
66         }
67         if (evt_lcores_has_overlap_multi(opt->wlcores, opt->plcores)) {
68                 evt_err("worker lcores overlaps producer lcores");
69                 return -1;
70         }
71         if (evt_has_disabled_lcore(opt->wlcores)) {
72                 evt_err("one or more workers lcores are not enabled");
73                 return -1;
74         }
75         if (!evt_has_active_lcore(opt->wlcores)) {
76                 evt_err("minimum one worker is required");
77                 return -1;
78         }
79
80         /* Validate producer lcores */
81         if (evt_lcores_has_overlap(opt->plcores, rte_get_master_lcore())) {
82                 evt_err("producer lcores overlaps with master lcore");
83                 return -1;
84         }
85         if (need_slcore && evt_lcores_has_overlap(opt->plcores, opt->slcore)) {
86                 evt_err("producer lcores overlaps with scheduler lcore");
87                 return -1;
88         }
89         if (evt_has_disabled_lcore(opt->plcores)) {
90                 evt_err("one or more producer lcores are not enabled");
91                 return -1;
92         }
93         if (!evt_has_active_lcore(opt->plcores)) {
94                 evt_err("minimum one producer is required");
95                 return -1;
96         }
97
98         /* Validate scheduler lcore */
99         if (!evt_has_distributed_sched(opt->dev_id) &&
100                         opt->slcore == (int)rte_get_master_lcore()) {
101                 evt_err("scheduler lcore and master lcore should be different");
102                 return -1;
103         }
104         if (need_slcore && !rte_lcore_is_enabled(opt->slcore)) {
105                 evt_err("scheduler lcore is not enabled");
106                 return -1;
107         }
108
109         if (evt_has_invalid_stage(opt))
110                 return -1;
111
112         if (evt_has_invalid_sched_type(opt))
113                 return -1;
114
115         if (nb_queues > EVT_MAX_QUEUES) {
116                 evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
117                 return -1;
118         }
119         if (perf_nb_event_ports(opt) > EVT_MAX_PORTS) {
120                 evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
121                 return -1;
122         }
123
124         /* Fixups */
125         if (opt->nb_stages == 1 && opt->fwd_latency) {
126                 evt_info("fwd_latency is valid when nb_stages > 1, disabling");
127                 opt->fwd_latency = 0;
128         }
129         if (opt->fwd_latency && !opt->q_priority) {
130                 evt_info("enabled queue priority for latency measurement");
131                 opt->q_priority = 1;
132         }
133
134         return 0;
135 }
136
137 void
138 perf_opt_dump(struct evt_options *opt, uint8_t nb_queues)
139 {
140         evt_dump("nb_prod_lcores", "%d", evt_nr_active_lcores(opt->plcores));
141         evt_dump_producer_lcores(opt);
142         evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores));
143         evt_dump_worker_lcores(opt);
144         if (!evt_has_distributed_sched(opt->dev_id))
145                 evt_dump_scheduler_lcore(opt);
146         evt_dump_nb_stages(opt);
147         evt_dump("nb_evdev_ports", "%d", perf_nb_event_ports(opt));
148         evt_dump("nb_evdev_queues", "%d", nb_queues);
149         evt_dump_queue_priority(opt);
150         evt_dump_sched_type_list(opt);
151 }
152
153 void
154 perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
155 {
156         RTE_SET_USED(test);
157
158         rte_event_dev_stop(opt->dev_id);
159         rte_event_dev_close(opt->dev_id);
160 }
161
162 static inline void
163 perf_elt_init(struct rte_mempool *mp, void *arg __rte_unused,
164             void *obj, unsigned i __rte_unused)
165 {
166         memset(obj, 0, mp->elt_size);
167 }
168
169 int
170 perf_mempool_setup(struct evt_test *test, struct evt_options *opt)
171 {
172         struct test_perf *t = evt_test_priv(test);
173
174         t->pool = rte_mempool_create(test->name, /* mempool name */
175                                 opt->pool_sz, /* number of elements*/
176                                 sizeof(struct perf_elt), /* element size*/
177                                 512, /* cache size*/
178                                 0, NULL, NULL,
179                                 perf_elt_init, /* obj constructor */
180                                 NULL, opt->socket_id, 0); /* flags */
181         if (t->pool == NULL) {
182                 evt_err("failed to create mempool");
183                 return -ENOMEM;
184         }
185
186         return 0;
187 }
188
189 void
190 perf_mempool_destroy(struct evt_test *test, struct evt_options *opt)
191 {
192         RTE_SET_USED(opt);
193         struct test_perf *t = evt_test_priv(test);
194
195         rte_mempool_free(t->pool);
196 }
197
198 int
199 perf_test_setup(struct evt_test *test, struct evt_options *opt)
200 {
201         void *test_perf;
202
203         test_perf = rte_zmalloc_socket(test->name, sizeof(struct test_perf),
204                                 RTE_CACHE_LINE_SIZE, opt->socket_id);
205         if (test_perf  == NULL) {
206                 evt_err("failed to allocate test_perf memory");
207                 goto nomem;
208         }
209         test->test_priv = test_perf;
210
211         struct test_perf *t = evt_test_priv(test);
212
213         t->outstand_pkts = opt->nb_pkts * evt_nr_active_lcores(opt->plcores);
214         t->nb_workers = evt_nr_active_lcores(opt->wlcores);
215         t->done = false;
216         t->nb_pkts = opt->nb_pkts;
217         t->nb_flows = opt->nb_flows;
218         t->result = EVT_TEST_FAILED;
219         t->opt = opt;
220         memcpy(t->sched_type_list, opt->sched_type_list,
221                         sizeof(opt->sched_type_list));
222         return 0;
223 nomem:
224         return -ENOMEM;
225 }
226
227 void
228 perf_test_destroy(struct evt_test *test, struct evt_options *opt)
229 {
230         RTE_SET_USED(opt);
231
232         rte_free(test->test_priv);
233 }