xref: /dpdk/examples/qos_sched/main.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
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 #include <rte_sched.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
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 63
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 MAX_DATA_STREAMS RTE_MAX_LCORE/2
41 #define MAX_SCHED_SUBPORTS		8
42 #define MAX_SCHED_PIPES		4096
43 #define MAX_SCHED_PIPE_PROFILES		256
44 #define MAX_SCHED_SUBPORT_PROFILES	8
45 
46 #ifndef APP_COLLECT_STAT
47 #define APP_COLLECT_STAT		1
48 #endif
49 
50 #if APP_COLLECT_STAT
51 #define APP_STATS_ADD(stat,val) (stat) += (val)
52 #else
53 #define APP_STATS_ADD(stat,val) do {(void) (val);} while (0)
54 #endif
55 
56 #define APP_QAVG_NTIMES 10
57 #define APP_QAVG_PERIOD 100
58 
59 struct thread_stat
60 {
61 	uint64_t nb_rx;
62 	uint64_t nb_drop;
63 };
64 
65 
66 struct __rte_cache_aligned thread_conf
67 {
68 	uint16_t rx_port;
69 	uint16_t tx_port;
70 	uint16_t rx_queue;
71 	uint16_t tx_queue;
72 	struct rte_ring *rx_ring;
73 	struct rte_ring *tx_ring;
74 	struct rte_sched_port *sched_port;
75 
76 #if APP_COLLECT_STAT
77 	struct thread_stat stat;
78 #endif
79 };
80 
81 
82 struct flow_conf
83 {
84 	uint32_t rx_core;
85 	uint32_t wt_core;
86 	uint32_t tx_core;
87 	uint16_t rx_port;
88 	uint16_t tx_port;
89 	uint16_t rx_queue;
90 	uint16_t tx_queue;
91 	struct rte_ring *rx_ring;
92 	struct rte_ring *tx_ring;
93 	struct rte_sched_port *sched_port;
94 	struct rte_mempool *mbuf_pool;
95 
96 	struct thread_conf rx_thread;
97 	struct thread_conf wt_thread;
98 	struct thread_conf tx_thread;
99 };
100 
101 
102 struct ring_conf
103 {
104 	uint32_t rx_size;
105 	uint32_t ring_size;
106 	uint32_t tx_size;
107 };
108 
109 struct burst_conf
110 {
111 	uint16_t rx_burst;
112 	uint16_t ring_burst;
113 	uint16_t qos_dequeue;
114 	uint16_t tx_burst;
115 };
116 
117 struct ring_thresh
118 {
119 	uint8_t pthresh; /**< Ring prefetch threshold. */
120 	uint8_t hthresh; /**< Ring host threshold. */
121 	uint8_t wthresh; /**< Ring writeback threshold. */
122 };
123 
124 extern uint8_t interactive;
125 extern uint32_t qavg_period;
126 extern uint32_t qavg_ntimes;
127 extern uint32_t nb_pfc;
128 extern const char *cfg_profile;
129 extern int mp_size;
130 extern struct flow_conf qos_conf[];
131 extern int app_pipe_to_profile[MAX_SCHED_SUBPORTS][MAX_SCHED_PIPES];
132 
133 extern struct ring_conf ring_conf;
134 extern struct burst_conf burst_conf;
135 extern struct ring_thresh rx_thresh;
136 extern struct ring_thresh tx_thresh;
137 
138 extern uint32_t active_queues[RTE_SCHED_QUEUES_PER_PIPE];
139 extern uint32_t n_active_queues;
140 
141 extern struct rte_sched_port_params port_params;
142 extern struct rte_sched_cman_params cman_params;
143 extern struct rte_sched_subport_params subport_params[MAX_SCHED_SUBPORTS];
144 
145 int app_parse_args(int argc, char **argv);
146 int app_init(void);
147 
148 void prompt(void);
149 void app_rx_thread(struct thread_conf **qconf);
150 void app_tx_thread(struct thread_conf **qconf);
151 void app_worker_thread(struct thread_conf **qconf);
152 void app_mixed_thread(struct thread_conf **qconf);
153 
154 void app_stat(void);
155 int subport_stat(uint16_t port_id, uint32_t subport_id);
156 int pipe_stat(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id);
157 int qavg_q(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id,
158 	   uint8_t tc, uint8_t q);
159 int qavg_tcpipe(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id,
160 		uint8_t tc);
161 int qavg_pipe(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id);
162 int qavg_tcsubport(uint16_t port_id, uint32_t subport_id, uint8_t tc);
163 int qavg_subport(uint16_t port_id, uint32_t subport_id);
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif /* _MAIN_H_ */
170