20ed590f5f8c237a3b370cf8d69cd5c7ac177f64
[dpdk.git] / examples / qos_sched / main.h
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  * 
7  *   Redistribution and use in source and binary forms, with or without 
8  *   modification, are permitted provided that the following conditions 
9  *   are met:
10  * 
11  *     * Redistributions of source code must retain the above copyright 
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright 
14  *       notice, this list of conditions and the following disclaimer in 
15  *       the documentation and/or other materials provided with the 
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its 
18  *       contributors may be used to endorse or promote products derived 
19  *       from this software without specific prior written permission.
20  * 
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  * 
33  */
34
35 #ifndef _MAIN_H_
36 #define _MAIN_H_
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 #include <rte_sched.h>
43
44 #ifdef RTE_EXEC_ENV_BAREMETAL
45 #error "Baremetal is not supported"
46 #else
47 #define MAIN main
48 #endif
49
50 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
51
52 /*
53  * Configurable number of RX/TX ring descriptors
54  */
55 #define APP_RX_DESC_DEFAULT 128
56 #define APP_TX_DESC_DEFAULT 256
57
58 #define MBUF_SIZE (1528 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
59 #define APP_RING_SIZE (8*1024)
60 #define NB_MBUF   (2*1024*1024)
61
62 #define MAX_PKT_RX_BURST 64
63 #define PKT_ENQUEUE 64
64 #define PKT_DEQUEUE 32
65 #define MAX_PKT_TX_BURST 64
66
67 #define RX_PTHRESH 8 /**< Default values of RX prefetch threshold reg. */
68 #define RX_HTHRESH 8 /**< Default values of RX host threshold reg. */
69 #define RX_WTHRESH 4 /**< Default values of RX write-back threshold reg. */
70
71 #define TX_PTHRESH 36 /**< Default values of TX prefetch threshold reg. */
72 #define TX_HTHRESH 0  /**< Default values of TX host threshold reg. */
73 #define TX_WTHRESH 0  /**< Default values of TX write-back threshold reg. */
74
75 #define BURST_TX_DRAIN_US 100
76
77 #define MAX_DATA_STREAMS (RTE_MAX_LCORE/2)
78 #define MAX_SCHED_SUBPORTS              8
79 #define MAX_SCHED_PIPES                 4096
80
81 #ifndef APP_COLLECT_STAT
82 #define APP_COLLECT_STAT                1
83 #endif
84
85 #if APP_COLLECT_STAT
86 #define APP_STATS_ADD(stat,val) (stat) += (val)
87 #else
88 #define APP_STATS_ADD(stat,val) do {(void) (val);} while (0)
89 #endif
90
91 struct thread_stat
92 {
93         uint64_t nb_rx;
94         uint64_t nb_drop;
95 };
96
97
98 struct thread_conf
99 {
100         uint32_t counter;
101         uint32_t n_mbufs;
102         struct rte_mbuf **m_table;
103
104         uint8_t rx_port;
105         uint8_t tx_port;
106         uint16_t rx_queue;
107         uint16_t tx_queue;
108         struct rte_ring *rx_ring;
109         struct rte_ring *tx_ring;
110         struct rte_sched_port *sched_port;
111
112 #if APP_COLLECT_STAT
113         struct thread_stat stat;
114 #endif
115 } __rte_cache_aligned;
116
117
118 struct flow_conf
119 {
120         uint32_t rx_core;
121         uint32_t wt_core;
122         uint32_t tx_core;
123         uint8_t rx_port;
124         uint8_t tx_port;
125         uint16_t rx_queue;
126         uint16_t tx_queue;
127         struct rte_ring *rx_ring;
128         struct rte_ring *tx_ring;
129         struct rte_sched_port *sched_port;
130         struct rte_mempool *mbuf_pool;
131
132         struct thread_conf rx_thread;
133         struct thread_conf wt_thread;
134         struct thread_conf tx_thread;
135 };
136
137
138 struct ring_conf
139 {
140         uint32_t rx_size;
141         uint32_t ring_size;
142         uint32_t tx_size;
143 };
144
145 struct burst_conf
146 {
147         uint16_t rx_burst;
148         uint16_t ring_burst;
149         uint16_t qos_dequeue;
150         uint16_t tx_burst;
151 };
152
153 struct ring_thresh
154 {
155         uint8_t pthresh; /**< Ring prefetch threshold. */
156         uint8_t hthresh; /**< Ring host threshold. */
157         uint8_t wthresh; /**< Ring writeback threshold. */
158 };
159
160 extern uint32_t nb_pfc;
161 extern const char *cfg_profile;
162 extern int mp_size;
163 extern struct flow_conf qos_conf[];
164 extern int app_pipe_to_profile[MAX_SCHED_SUBPORTS][MAX_SCHED_PIPES];
165
166 extern struct ring_conf ring_conf;
167 extern struct burst_conf burst_conf;
168 extern struct ring_thresh rx_thresh;
169 extern struct ring_thresh tx_thresh;
170
171 extern struct rte_sched_port_params port_params;
172
173 int MAIN(int argc, char **argv);
174 int app_parse_args(int argc, char **argv);
175 int app_init(void);
176
177 void app_rx_thread(struct thread_conf **qconf);
178 void app_tx_thread(struct thread_conf **qconf);
179 void app_worker_thread(struct thread_conf **qconf);
180 void app_mixed_thread(struct thread_conf **qconf);
181
182
183 #ifdef __cplusplus
184 }
185 #endif
186
187 #endif /* _MAIN_H_ */