xref: /dpdk/app/test-eventdev/test_perf_common.h (revision 3998e2a07220844d3f3c17f76a781ced3efe0de0)
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium, Inc 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, Inc 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 #ifndef _TEST_PERF_COMMON_
34 #define _TEST_PERF_COMMON_
35 
36 #include <stdio.h>
37 #include <stdbool.h>
38 #include <unistd.h>
39 
40 #include <rte_cycles.h>
41 #include <rte_eventdev.h>
42 #include <rte_lcore.h>
43 #include <rte_malloc.h>
44 #include <rte_mempool.h>
45 #include <rte_prefetch.h>
46 
47 #include "evt_common.h"
48 #include "evt_options.h"
49 #include "evt_test.h"
50 
51 struct test_perf;
52 
53 struct worker_data {
54 	uint64_t processed_pkts;
55 	uint64_t latency;
56 	uint8_t dev_id;
57 	uint8_t port_id;
58 	struct test_perf *t;
59 } __rte_cache_aligned;
60 
61 struct prod_data {
62 	uint8_t dev_id;
63 	uint8_t port_id;
64 	uint8_t queue_id;
65 	struct test_perf *t;
66 } __rte_cache_aligned;
67 
68 struct test_perf {
69 	/* Don't change the offset of "done". Signal handler use this memory
70 	 * to terminate all lcores work.
71 	 */
72 	int done;
73 	uint64_t outstand_pkts;
74 	uint8_t nb_workers;
75 	enum evt_test_result result;
76 	uint32_t nb_flows;
77 	uint64_t nb_pkts;
78 	struct rte_mempool *pool;
79 	struct prod_data prod[EVT_MAX_PORTS];
80 	struct worker_data worker[EVT_MAX_PORTS];
81 	struct evt_options *opt;
82 	uint8_t sched_type_list[EVT_MAX_STAGES] __rte_cache_aligned;
83 } __rte_cache_aligned;
84 
85 struct perf_elt {
86 	uint64_t timestamp;
87 } __rte_cache_aligned;
88 
89 #define BURST_SIZE 16
90 
91 #define PERF_WORKER_INIT\
92 	struct worker_data *w  = arg;\
93 	struct test_perf *t = w->t;\
94 	struct evt_options *opt = t->opt;\
95 	const uint8_t dev = w->dev_id;\
96 	const uint8_t port = w->port_id;\
97 	uint8_t *const sched_type_list = &t->sched_type_list[0];\
98 	struct rte_mempool *const pool = t->pool;\
99 	const uint8_t nb_stages = t->opt->nb_stages;\
100 	const uint8_t laststage = nb_stages - 1;\
101 	uint8_t cnt = 0;\
102 	void *bufs[16] __rte_cache_aligned;\
103 	int const sz = RTE_DIM(bufs);\
104 	if (opt->verbose_level > 1)\
105 		printf("%s(): lcore %d dev_id %d port=%d\n", __func__,\
106 				rte_lcore_id(), dev, port)
107 
108 static inline __attribute__((always_inline)) int
109 perf_process_last_stage(struct rte_mempool *const pool,
110 		struct rte_event *const ev, struct worker_data *const w,
111 		void *bufs[], int const buf_sz, uint8_t count)
112 {
113 	bufs[count++] = ev->event_ptr;
114 	w->processed_pkts++;
115 	rte_smp_wmb();
116 
117 	if (unlikely(count == buf_sz)) {
118 		count = 0;
119 		rte_mempool_put_bulk(pool, bufs, buf_sz);
120 	}
121 	return count;
122 }
123 
124 static inline __attribute__((always_inline)) uint8_t
125 perf_process_last_stage_latency(struct rte_mempool *const pool,
126 		struct rte_event *const ev, struct worker_data *const w,
127 		void *bufs[], int const buf_sz, uint8_t count)
128 {
129 	uint64_t latency;
130 	struct perf_elt *const m = ev->event_ptr;
131 
132 	bufs[count++] = ev->event_ptr;
133 	w->processed_pkts++;
134 
135 	if (unlikely(count == buf_sz)) {
136 		count = 0;
137 		latency = rte_get_timer_cycles() - m->timestamp;
138 		rte_mempool_put_bulk(pool, bufs, buf_sz);
139 	} else {
140 		latency = rte_get_timer_cycles() - m->timestamp;
141 	}
142 
143 	w->latency += latency;
144 	rte_smp_wmb();
145 	return count;
146 }
147 
148 
149 static inline int
150 perf_nb_event_ports(struct evt_options *opt)
151 {
152 	return evt_nr_active_lcores(opt->wlcores) +
153 			evt_nr_active_lcores(opt->plcores);
154 }
155 
156 int perf_test_result(struct evt_test *test, struct evt_options *opt);
157 int perf_opt_check(struct evt_options *opt, uint64_t nb_queues);
158 int perf_test_setup(struct evt_test *test, struct evt_options *opt);
159 int perf_mempool_setup(struct evt_test *test, struct evt_options *opt);
160 int perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt,
161 				uint8_t stride, uint8_t nb_queues);
162 int perf_event_dev_service_setup(uint8_t dev_id);
163 int perf_launch_lcores(struct evt_test *test, struct evt_options *opt,
164 		int (*worker)(void *));
165 void perf_opt_dump(struct evt_options *opt, uint8_t nb_queues);
166 void perf_test_destroy(struct evt_test *test, struct evt_options *opt);
167 void perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt);
168 void perf_mempool_destroy(struct evt_test *test, struct evt_options *opt);
169 
170 #endif /* _TEST_PERF_COMMON_ */
171