1103dd146d3ab1deb79c0075423a201f7b21476d
[dpdk.git] / app / test-eventdev / test_perf_common.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Cavium, Inc
3  */
4
5 #ifndef _TEST_PERF_COMMON_
6 #define _TEST_PERF_COMMON_
7
8 #include <stdio.h>
9 #include <stdbool.h>
10 #include <unistd.h>
11
12 #include <rte_cycles.h>
13 #include <rte_eventdev.h>
14 #include <rte_lcore.h>
15 #include <rte_malloc.h>
16 #include <rte_mempool.h>
17 #include <rte_prefetch.h>
18
19 #include "evt_common.h"
20 #include "evt_options.h"
21 #include "evt_test.h"
22
23 struct test_perf;
24
25 struct worker_data {
26         uint64_t processed_pkts;
27         uint64_t latency;
28         uint8_t dev_id;
29         uint8_t port_id;
30         struct test_perf *t;
31 } __rte_cache_aligned;
32
33 struct prod_data {
34         uint8_t dev_id;
35         uint8_t port_id;
36         uint8_t queue_id;
37         struct test_perf *t;
38 } __rte_cache_aligned;
39
40 struct test_perf {
41         /* Don't change the offset of "done". Signal handler use this memory
42          * to terminate all lcores work.
43          */
44         int done;
45         uint64_t outstand_pkts;
46         uint8_t nb_workers;
47         enum evt_test_result result;
48         uint32_t nb_flows;
49         uint64_t nb_pkts;
50         struct rte_mempool *pool;
51         struct prod_data prod[EVT_MAX_PORTS];
52         struct worker_data worker[EVT_MAX_PORTS];
53         struct evt_options *opt;
54         uint8_t sched_type_list[EVT_MAX_STAGES] __rte_cache_aligned;
55 } __rte_cache_aligned;
56
57 struct perf_elt {
58         uint64_t timestamp;
59 } __rte_cache_aligned;
60
61 #define BURST_SIZE 16
62
63 #define PERF_WORKER_INIT\
64         struct worker_data *w  = arg;\
65         struct test_perf *t = w->t;\
66         struct evt_options *opt = t->opt;\
67         const uint8_t dev = w->dev_id;\
68         const uint8_t port = w->port_id;\
69         uint8_t *const sched_type_list = &t->sched_type_list[0];\
70         struct rte_mempool *const pool = t->pool;\
71         const uint8_t nb_stages = t->opt->nb_stages;\
72         const uint8_t laststage = nb_stages - 1;\
73         uint8_t cnt = 0;\
74         void *bufs[16] __rte_cache_aligned;\
75         int const sz = RTE_DIM(bufs);\
76         if (opt->verbose_level > 1)\
77                 printf("%s(): lcore %d dev_id %d port=%d\n", __func__,\
78                                 rte_lcore_id(), dev, port)
79
80 static inline __attribute__((always_inline)) int
81 perf_process_last_stage(struct rte_mempool *const pool,
82                 struct rte_event *const ev, struct worker_data *const w,
83                 void *bufs[], int const buf_sz, uint8_t count)
84 {
85         bufs[count++] = ev->event_ptr;
86         w->processed_pkts++;
87         rte_smp_wmb();
88
89         if (unlikely(count == buf_sz)) {
90                 count = 0;
91                 rte_mempool_put_bulk(pool, bufs, buf_sz);
92         }
93         return count;
94 }
95
96 static inline __attribute__((always_inline)) uint8_t
97 perf_process_last_stage_latency(struct rte_mempool *const pool,
98                 struct rte_event *const ev, struct worker_data *const w,
99                 void *bufs[], int const buf_sz, uint8_t count)
100 {
101         uint64_t latency;
102         struct perf_elt *const m = ev->event_ptr;
103
104         bufs[count++] = ev->event_ptr;
105         w->processed_pkts++;
106
107         if (unlikely(count == buf_sz)) {
108                 count = 0;
109                 latency = rte_get_timer_cycles() - m->timestamp;
110                 rte_mempool_put_bulk(pool, bufs, buf_sz);
111         } else {
112                 latency = rte_get_timer_cycles() - m->timestamp;
113         }
114
115         w->latency += latency;
116         rte_smp_wmb();
117         return count;
118 }
119
120
121 static inline int
122 perf_nb_event_ports(struct evt_options *opt)
123 {
124         return evt_nr_active_lcores(opt->wlcores) +
125                         evt_nr_active_lcores(opt->plcores);
126 }
127
128 int perf_test_result(struct evt_test *test, struct evt_options *opt);
129 int perf_opt_check(struct evt_options *opt, uint64_t nb_queues);
130 int perf_test_setup(struct evt_test *test, struct evt_options *opt);
131 int perf_mempool_setup(struct evt_test *test, struct evt_options *opt);
132 int perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt,
133                                 uint8_t stride, uint8_t nb_queues);
134 int perf_event_dev_service_setup(uint8_t dev_id);
135 int perf_launch_lcores(struct evt_test *test, struct evt_options *opt,
136                 int (*worker)(void *));
137 void perf_opt_dump(struct evt_options *opt, uint8_t nb_queues);
138 void perf_test_destroy(struct evt_test *test, struct evt_options *opt);
139 void perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt);
140 void perf_mempool_destroy(struct evt_test *test, struct evt_options *opt);
141
142 #endif /* _TEST_PERF_COMMON_ */