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