xref: /dpdk/examples/qos_sched/main.h (revision daa02b5cddbb8e11b31d41e2bf7bb1ae64dcae2f)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 #ifndef _MAIN_H_
6 #define _MAIN_H_
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <rte_sched.h>
13 
14 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
15 
16 /*
17  * Configurable number of RX/TX ring descriptors
18  */
19 #define APP_INTERACTIVE_DEFAULT 0
20 
21 #define APP_RX_DESC_DEFAULT 1024
22 #define APP_TX_DESC_DEFAULT 1024
23 
24 #define APP_RING_SIZE (8*1024)
25 #define NB_MBUF   (2*1024*1024)
26 
27 #define MAX_PKT_RX_BURST 64
28 #define PKT_ENQUEUE 64
29 #define PKT_DEQUEUE 32
30 #define MAX_PKT_TX_BURST 64
31 
32 #define RX_PTHRESH 8 /**< Default values of RX prefetch threshold reg. */
33 #define RX_HTHRESH 8 /**< Default values of RX host threshold reg. */
34 #define RX_WTHRESH 4 /**< Default values of RX write-back threshold reg. */
35 
36 #define TX_PTHRESH 36 /**< Default values of TX prefetch threshold reg. */
37 #define TX_HTHRESH 0  /**< Default values of TX host threshold reg. */
38 #define TX_WTHRESH 0  /**< Default values of TX write-back threshold reg. */
39 
40 #define BURST_TX_DRAIN_US 100
41 
42 #ifndef APP_MAX_LCORE
43 #if (RTE_MAX_LCORE > 64)
44 #define APP_MAX_LCORE 64
45 #else
46 #define APP_MAX_LCORE RTE_MAX_LCORE
47 #endif
48 #endif
49 
50 #define MAX_DATA_STREAMS (APP_MAX_LCORE/2)
51 #define MAX_SCHED_SUBPORTS		8
52 #define MAX_SCHED_PIPES		4096
53 #define MAX_SCHED_PIPE_PROFILES		256
54 #define MAX_SCHED_SUBPORT_PROFILES	8
55 
56 #ifndef APP_COLLECT_STAT
57 #define APP_COLLECT_STAT		1
58 #endif
59 
60 #if APP_COLLECT_STAT
61 #define APP_STATS_ADD(stat,val) (stat) += (val)
62 #else
63 #define APP_STATS_ADD(stat,val) do {(void) (val);} while (0)
64 #endif
65 
66 #define APP_QAVG_NTIMES 10
67 #define APP_QAVG_PERIOD 100
68 
69 struct thread_stat
70 {
71 	uint64_t nb_rx;
72 	uint64_t nb_drop;
73 };
74 
75 
76 struct thread_conf
77 {
78 	uint32_t counter;
79 	uint32_t n_mbufs;
80 	struct rte_mbuf **m_table;
81 
82 	uint16_t rx_port;
83 	uint16_t tx_port;
84 	uint16_t rx_queue;
85 	uint16_t tx_queue;
86 	struct rte_ring *rx_ring;
87 	struct rte_ring *tx_ring;
88 	struct rte_sched_port *sched_port;
89 
90 #if APP_COLLECT_STAT
91 	struct thread_stat stat;
92 #endif
93 } __rte_cache_aligned;
94 
95 
96 struct flow_conf
97 {
98 	uint32_t rx_core;
99 	uint32_t wt_core;
100 	uint32_t tx_core;
101 	uint16_t rx_port;
102 	uint16_t tx_port;
103 	uint16_t rx_queue;
104 	uint16_t tx_queue;
105 	struct rte_ring *rx_ring;
106 	struct rte_ring *tx_ring;
107 	struct rte_sched_port *sched_port;
108 	struct rte_mempool *mbuf_pool;
109 
110 	struct thread_conf rx_thread;
111 	struct thread_conf wt_thread;
112 	struct thread_conf tx_thread;
113 };
114 
115 
116 struct ring_conf
117 {
118 	uint32_t rx_size;
119 	uint32_t ring_size;
120 	uint32_t tx_size;
121 };
122 
123 struct burst_conf
124 {
125 	uint16_t rx_burst;
126 	uint16_t ring_burst;
127 	uint16_t qos_dequeue;
128 	uint16_t tx_burst;
129 };
130 
131 struct ring_thresh
132 {
133 	uint8_t pthresh; /**< Ring prefetch threshold. */
134 	uint8_t hthresh; /**< Ring host threshold. */
135 	uint8_t wthresh; /**< Ring writeback threshold. */
136 };
137 
138 extern uint8_t interactive;
139 extern uint32_t qavg_period;
140 extern uint32_t qavg_ntimes;
141 extern uint32_t nb_pfc;
142 extern const char *cfg_profile;
143 extern int mp_size;
144 extern struct flow_conf qos_conf[];
145 extern int app_pipe_to_profile[MAX_SCHED_SUBPORTS][MAX_SCHED_PIPES];
146 
147 extern struct ring_conf ring_conf;
148 extern struct burst_conf burst_conf;
149 extern struct ring_thresh rx_thresh;
150 extern struct ring_thresh tx_thresh;
151 
152 extern uint32_t active_queues[RTE_SCHED_QUEUES_PER_PIPE];
153 extern uint32_t n_active_queues;
154 
155 extern struct rte_sched_port_params port_params;
156 extern struct rte_sched_subport_params subport_params[MAX_SCHED_SUBPORTS];
157 
158 int app_parse_args(int argc, char **argv);
159 int app_init(void);
160 
161 void prompt(void);
162 void app_rx_thread(struct thread_conf **qconf);
163 void app_tx_thread(struct thread_conf **qconf);
164 void app_worker_thread(struct thread_conf **qconf);
165 void app_mixed_thread(struct thread_conf **qconf);
166 
167 void app_stat(void);
168 int subport_stat(uint16_t port_id, uint32_t subport_id);
169 int pipe_stat(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id);
170 int qavg_q(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id,
171 	   uint8_t tc, uint8_t q);
172 int qavg_tcpipe(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id,
173 		uint8_t tc);
174 int qavg_pipe(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id);
175 int qavg_tcsubport(uint16_t port_id, uint32_t subport_id, uint8_t tc);
176 int qavg_subport(uint16_t port_id, uint32_t subport_id);
177 
178 #ifdef __cplusplus
179 }
180 #endif
181 
182 #endif /* _MAIN_H_ */
183