4 * Copyright (C) Cavium, Inc 2017.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
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.
33 #ifndef _TEST_PERF_COMMON_
34 #define _TEST_PERF_COMMON_
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>
47 #include "evt_common.h"
48 #include "evt_options.h"
54 uint64_t processed_pkts;
59 } __rte_cache_aligned;
66 } __rte_cache_aligned;
69 /* Don't change the offset of "done". Signal handler use this memory
70 * to terminate all lcores work.
73 uint64_t outstand_pkts;
75 enum evt_test_result result;
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;
87 } __rte_cache_aligned;
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;\
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)
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)
113 bufs[count++] = ev->event_ptr;
117 if (unlikely(count == buf_sz)) {
119 rte_mempool_put_bulk(pool, bufs, buf_sz);
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)
130 struct perf_elt *const m = ev->event_ptr;
132 bufs[count++] = ev->event_ptr;
135 if (unlikely(count == buf_sz)) {
137 latency = rte_get_timer_cycles() - m->timestamp;
138 rte_mempool_put_bulk(pool, bufs, buf_sz);
140 latency = rte_get_timer_cycles() - m->timestamp;
143 w->latency += latency;
150 perf_nb_event_ports(struct evt_options *opt)
152 return evt_nr_active_lcores(opt->wlcores) +
153 evt_nr_active_lcores(opt->plcores);
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);
170 #endif /* _TEST_PERF_COMMON_ */