1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
5 #include "test_perf_common.h"
8 perf_test_result(struct evt_test *test, struct evt_options *opt)
11 struct test_perf *t = evt_test_priv(test);
17 perf_producer(void *arg)
19 struct prod_data *p = arg;
20 struct test_perf *t = p->t;
21 struct evt_options *opt = t->opt;
22 const uint8_t dev_id = p->dev_id;
23 const uint8_t port = p->port_id;
24 struct rte_mempool *pool = t->pool;
25 const uint64_t nb_pkts = t->nb_pkts;
26 const uint32_t nb_flows = t->nb_flows;
27 uint32_t flow_counter = 0;
32 if (opt->verbose_level > 1)
33 printf("%s(): lcore %d dev_id %d port=%d queue %d\n", __func__,
34 rte_lcore_id(), dev_id, port, p->queue_id);
37 ev.op = RTE_EVENT_OP_NEW;
38 ev.queue_id = p->queue_id;
39 ev.sched_type = t->opt->sched_type_list[0];
40 ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
41 ev.event_type = RTE_EVENT_TYPE_CPU;
42 ev.sub_event_type = 0; /* stage 0 */
44 while (count < nb_pkts && t->done == false) {
45 if (rte_mempool_get(pool, (void **)&m) < 0)
48 ev.flow_id = flow_counter++ % nb_flows;
50 m->timestamp = rte_get_timer_cycles();
51 while (rte_event_enqueue_burst(dev_id, port, &ev, 1) != 1) {
55 m->timestamp = rte_get_timer_cycles();
63 static inline uint64_t
64 processed_pkts(struct test_perf *t)
70 for (i = 0; i < t->nb_workers; i++)
71 total += t->worker[i].processed_pkts;
76 static inline uint64_t
77 total_latency(struct test_perf *t)
83 for (i = 0; i < t->nb_workers; i++)
84 total += t->worker[i].latency;
91 perf_launch_lcores(struct evt_test *test, struct evt_options *opt,
92 int (*worker)(void *))
95 struct test_perf *t = evt_test_priv(test);
99 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
100 if (!(opt->wlcores[lcore_id]))
103 ret = rte_eal_remote_launch(worker,
104 &t->worker[port_idx], lcore_id);
106 evt_err("failed to launch worker %d", lcore_id);
112 /* launch producers */
113 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
114 if (!(opt->plcores[lcore_id]))
117 ret = rte_eal_remote_launch(perf_producer, &t->prod[port_idx],
120 evt_err("failed to launch perf_producer %d", lcore_id);
126 const uint64_t total_pkts = opt->nb_pkts *
127 evt_nr_active_lcores(opt->plcores);
129 uint64_t dead_lock_cycles = rte_get_timer_cycles();
130 int64_t dead_lock_remaining = total_pkts;
131 const uint64_t dead_lock_sample = rte_get_timer_hz() * 5;
133 uint64_t perf_cycles = rte_get_timer_cycles();
134 int64_t perf_remaining = total_pkts;
135 const uint64_t perf_sample = rte_get_timer_hz();
137 static float total_mpps;
138 static uint64_t samples;
140 const uint64_t freq_mhz = rte_get_timer_hz() / 1000000;
141 int64_t remaining = t->outstand_pkts - processed_pkts(t);
143 while (t->done == false) {
144 const uint64_t new_cycles = rte_get_timer_cycles();
146 if ((new_cycles - perf_cycles) > perf_sample) {
147 const uint64_t latency = total_latency(t);
148 const uint64_t pkts = processed_pkts(t);
150 remaining = t->outstand_pkts - pkts;
151 float mpps = (float)(perf_remaining-remaining)/1000000;
153 perf_remaining = remaining;
154 perf_cycles = new_cycles;
157 if (opt->fwd_latency && pkts > 0) {
158 printf(CLGRN"\r%.3f mpps avg %.3f mpps [avg fwd latency %.3f us] "CLNRM,
159 mpps, total_mpps/samples,
160 (float)(latency/pkts)/freq_mhz);
162 printf(CLGRN"\r%.3f mpps avg %.3f mpps"CLNRM,
163 mpps, total_mpps/samples);
167 if (remaining <= 0) {
169 t->result = EVT_TEST_SUCCESS;
175 if (new_cycles - dead_lock_cycles > dead_lock_sample) {
176 remaining = t->outstand_pkts - processed_pkts(t);
177 if (dead_lock_remaining == remaining) {
178 rte_event_dev_dump(opt->dev_id, stdout);
179 evt_err("No schedules for seconds, deadlock");
184 dead_lock_remaining = remaining;
185 dead_lock_cycles = new_cycles;
193 perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt,
194 uint8_t stride, uint8_t nb_queues)
196 struct test_perf *t = evt_test_priv(test);
200 /* port configuration */
201 const struct rte_event_port_conf wkr_p_conf = {
202 .dequeue_depth = opt->wkr_deq_dep,
204 .new_event_threshold = 4096,
207 /* setup one port per worker, linking to all queues */
208 for (port = 0; port < evt_nr_active_lcores(opt->wlcores);
210 struct worker_data *w = &t->worker[port];
212 w->dev_id = opt->dev_id;
215 w->processed_pkts = 0;
218 ret = rte_event_port_setup(opt->dev_id, port, &wkr_p_conf);
220 evt_err("failed to setup port %d", port);
224 ret = rte_event_port_link(opt->dev_id, port, NULL, NULL, 0);
225 if (ret != nb_queues) {
226 evt_err("failed to link all queues to port %d", port);
231 /* port for producers, no links */
232 const struct rte_event_port_conf prod_conf = {
235 .new_event_threshold = 1200,
238 for ( ; port < perf_nb_event_ports(opt); port++) {
239 struct prod_data *p = &t->prod[port];
241 p->dev_id = opt->dev_id;
243 p->queue_id = prod * stride;
246 ret = rte_event_port_setup(opt->dev_id, port, &prod_conf);
248 evt_err("failed to setup port %d", port);
258 perf_opt_check(struct evt_options *opt, uint64_t nb_queues)
262 /* N producer + N worker + 1 master */
265 if (rte_lcore_count() < lcores) {
266 evt_err("test need minimum %d lcores", lcores);
270 /* Validate worker lcores */
271 if (evt_lcores_has_overlap(opt->wlcores, rte_get_master_lcore())) {
272 evt_err("worker lcores overlaps with master lcore");
275 if (evt_lcores_has_overlap_multi(opt->wlcores, opt->plcores)) {
276 evt_err("worker lcores overlaps producer lcores");
279 if (evt_has_disabled_lcore(opt->wlcores)) {
280 evt_err("one or more workers lcores are not enabled");
283 if (!evt_has_active_lcore(opt->wlcores)) {
284 evt_err("minimum one worker is required");
288 /* Validate producer lcores */
289 if (evt_lcores_has_overlap(opt->plcores, rte_get_master_lcore())) {
290 evt_err("producer lcores overlaps with master lcore");
293 if (evt_has_disabled_lcore(opt->plcores)) {
294 evt_err("one or more producer lcores are not enabled");
297 if (!evt_has_active_lcore(opt->plcores)) {
298 evt_err("minimum one producer is required");
302 if (evt_has_invalid_stage(opt))
305 if (evt_has_invalid_sched_type(opt))
308 if (nb_queues > EVT_MAX_QUEUES) {
309 evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
312 if (perf_nb_event_ports(opt) > EVT_MAX_PORTS) {
313 evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
318 if (opt->nb_stages == 1 && opt->fwd_latency) {
319 evt_info("fwd_latency is valid when nb_stages > 1, disabling");
320 opt->fwd_latency = 0;
322 if (opt->fwd_latency && !opt->q_priority) {
323 evt_info("enabled queue priority for latency measurement");
326 if (opt->nb_pkts == 0)
327 opt->nb_pkts = INT64_MAX/evt_nr_active_lcores(opt->plcores);
333 perf_opt_dump(struct evt_options *opt, uint8_t nb_queues)
335 evt_dump("nb_prod_lcores", "%d", evt_nr_active_lcores(opt->plcores));
336 evt_dump_producer_lcores(opt);
337 evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores));
338 evt_dump_worker_lcores(opt);
339 evt_dump_nb_stages(opt);
340 evt_dump("nb_evdev_ports", "%d", perf_nb_event_ports(opt));
341 evt_dump("nb_evdev_queues", "%d", nb_queues);
342 evt_dump_queue_priority(opt);
343 evt_dump_sched_type_list(opt);
347 perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
351 rte_event_dev_stop(opt->dev_id);
352 rte_event_dev_close(opt->dev_id);
356 perf_elt_init(struct rte_mempool *mp, void *arg __rte_unused,
357 void *obj, unsigned i __rte_unused)
359 memset(obj, 0, mp->elt_size);
363 perf_mempool_setup(struct evt_test *test, struct evt_options *opt)
365 struct test_perf *t = evt_test_priv(test);
367 t->pool = rte_mempool_create(test->name, /* mempool name */
368 opt->pool_sz, /* number of elements*/
369 sizeof(struct perf_elt), /* element size*/
372 perf_elt_init, /* obj constructor */
373 NULL, opt->socket_id, 0); /* flags */
374 if (t->pool == NULL) {
375 evt_err("failed to create mempool");
383 perf_mempool_destroy(struct evt_test *test, struct evt_options *opt)
386 struct test_perf *t = evt_test_priv(test);
388 rte_mempool_free(t->pool);
392 perf_test_setup(struct evt_test *test, struct evt_options *opt)
396 test_perf = rte_zmalloc_socket(test->name, sizeof(struct test_perf),
397 RTE_CACHE_LINE_SIZE, opt->socket_id);
398 if (test_perf == NULL) {
399 evt_err("failed to allocate test_perf memory");
402 test->test_priv = test_perf;
404 struct test_perf *t = evt_test_priv(test);
406 t->outstand_pkts = opt->nb_pkts * evt_nr_active_lcores(opt->plcores);
407 t->nb_workers = evt_nr_active_lcores(opt->wlcores);
409 t->nb_pkts = opt->nb_pkts;
410 t->nb_flows = opt->nb_flows;
411 t->result = EVT_TEST_FAILED;
413 memcpy(t->sched_type_list, opt->sched_type_list,
414 sizeof(opt->sched_type_list));
421 perf_test_destroy(struct evt_test *test, struct evt_options *opt)
425 rte_free(test->test_priv);