lib: fix typos
[dpdk.git] / lib / librte_distributor / rte_distributor_private.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Intel Corporation nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _RTE_DIST_PRIV_H_
34 #define _RTE_DIST_PRIV_H_
35
36 /**
37  * @file
38  * RTE distributor
39  *
40  * The distributor is a component which is designed to pass packets
41  * one-at-a-time to workers, with dynamic load balancing.
42  */
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #define NO_FLAGS 0
49 #define RTE_DISTRIB_PREFIX "DT_"
50
51 /*
52  * We will use the bottom four bits of pointer for flags, shifting out
53  * the top four bits to make room (since a 64-bit pointer actually only uses
54  * 48 bits). An arithmetic-right-shift will then appropriately restore the
55  * original pointer value with proper sign extension into the top bits.
56  */
57 #define RTE_DISTRIB_FLAG_BITS 4
58 #define RTE_DISTRIB_FLAGS_MASK (0x0F)
59 #define RTE_DISTRIB_NO_BUF 0       /**< empty flags: no buffer requested */
60 #define RTE_DISTRIB_GET_BUF (1)    /**< worker requests a buffer, returns old */
61 #define RTE_DISTRIB_RETURN_BUF (2) /**< worker returns a buffer, no request */
62 #define RTE_DISTRIB_VALID_BUF (4)  /**< set if bufptr contains ptr */
63
64 #define RTE_DISTRIB_BACKLOG_SIZE 8
65 #define RTE_DISTRIB_BACKLOG_MASK (RTE_DISTRIB_BACKLOG_SIZE - 1)
66
67 #define RTE_DISTRIB_MAX_RETURNS 128
68 #define RTE_DISTRIB_RETURNS_MASK (RTE_DISTRIB_MAX_RETURNS - 1)
69
70 /**
71  * Maximum number of workers allowed.
72  * Be aware of increasing the limit, becaus it is limited by how we track
73  * in-flight tags. See in_flight_bitmask and rte_distributor_process
74  */
75 #define RTE_DISTRIB_MAX_WORKERS 64
76
77 #define RTE_DISTRIBUTOR_NAMESIZE 32 /**< Length of name for instance */
78
79 /**
80  * Buffer structure used to pass the pointer data between cores. This is cache
81  * line aligned, but to improve performance and prevent adjacent cache-line
82  * prefetches of buffers for other workers, e.g. when worker 1's buffer is on
83  * the next cache line to worker 0, we pad this out to three cache lines.
84  * Only 64-bits of the memory is actually used though.
85  */
86 union rte_distributor_buffer_v20 {
87         volatile int64_t bufptr64;
88         char pad[RTE_CACHE_LINE_SIZE*3];
89 } __rte_cache_aligned;
90
91 /*
92  * Transfer up to 8 mbufs at a time to/from workers, and
93  * flow matching algorithm optimized for 8 flow IDs at a time
94  */
95 #define RTE_DIST_BURST_SIZE 8
96
97 struct rte_distributor_backlog {
98         unsigned int start;
99         unsigned int count;
100         int64_t pkts[RTE_DIST_BURST_SIZE] __rte_cache_aligned;
101         uint16_t *tags; /* will point to second cacheline of inflights */
102 } __rte_cache_aligned;
103
104
105 struct rte_distributor_returned_pkts {
106         unsigned int start;
107         unsigned int count;
108         struct rte_mbuf *mbufs[RTE_DISTRIB_MAX_RETURNS];
109 };
110
111 struct rte_distributor_v20 {
112         TAILQ_ENTRY(rte_distributor_v20) next;    /**< Next in list. */
113
114         char name[RTE_DISTRIBUTOR_NAMESIZE];  /**< Name of the ring. */
115         unsigned int num_workers;             /**< Number of workers polling */
116
117         uint32_t in_flight_tags[RTE_DISTRIB_MAX_WORKERS];
118                 /**< Tracks the tag being processed per core */
119         uint64_t in_flight_bitmask;
120                 /**< on/off bits for in-flight tags.
121                  * Note that if RTE_DISTRIB_MAX_WORKERS is larger than 64 then
122                  * the bitmask has to expand.
123                  */
124
125         struct rte_distributor_backlog backlog[RTE_DISTRIB_MAX_WORKERS];
126
127         union rte_distributor_buffer_v20 bufs[RTE_DISTRIB_MAX_WORKERS];
128
129         struct rte_distributor_returned_pkts returns;
130 };
131
132 /* All different signature compare functions */
133 enum rte_distributor_match_function {
134         RTE_DIST_MATCH_SCALAR = 0,
135         RTE_DIST_MATCH_VECTOR,
136         RTE_DIST_NUM_MATCH_FNS
137 };
138
139 /**
140  * Buffer structure used to pass the pointer data between cores. This is cache
141  * line aligned, but to improve performance and prevent adjacent cache-line
142  * prefetches of buffers for other workers, e.g. when worker 1's buffer is on
143  * the next cache line to worker 0, we pad this out to two cache lines.
144  * We can pass up to 8 mbufs at a time in one cacheline.
145  * There is a separate cacheline for returns in the burst API.
146  */
147 struct rte_distributor_buffer {
148         volatile int64_t bufptr64[RTE_DIST_BURST_SIZE]
149                 __rte_cache_aligned; /* <= outgoing to worker */
150
151         int64_t pad1 __rte_cache_aligned;    /* <= one cache line  */
152
153         volatile int64_t retptr64[RTE_DIST_BURST_SIZE]
154                 __rte_cache_aligned; /* <= incoming from worker */
155
156         int64_t pad2 __rte_cache_aligned;    /* <= one cache line  */
157
158         int count __rte_cache_aligned;       /* <= number of current mbufs */
159 };
160
161 struct rte_distributor {
162         TAILQ_ENTRY(rte_distributor) next;    /**< Next in list. */
163
164         char name[RTE_DISTRIBUTOR_NAMESIZE];  /**< Name of the ring. */
165         unsigned int num_workers;             /**< Number of workers polling */
166         unsigned int alg_type;                /**< Number of alg types */
167
168         /**>
169          * First cache line in the this array are the tags inflight
170          * on the worker core. Second cache line are the backlog
171          * that are going to go to the worker core.
172          */
173         uint16_t in_flight_tags[RTE_DISTRIB_MAX_WORKERS][RTE_DIST_BURST_SIZE*2]
174                         __rte_cache_aligned;
175
176         struct rte_distributor_backlog backlog[RTE_DISTRIB_MAX_WORKERS]
177                         __rte_cache_aligned;
178
179         struct rte_distributor_buffer bufs[RTE_DISTRIB_MAX_WORKERS];
180
181         struct rte_distributor_returned_pkts returns;
182
183         enum rte_distributor_match_function dist_match_fn;
184
185         struct rte_distributor_v20 *d_v20;
186 };
187
188 void
189 find_match_scalar(struct rte_distributor *d,
190                         uint16_t *data_ptr,
191                         uint16_t *output_ptr);
192
193 void
194 find_match_vec(struct rte_distributor *d,
195                         uint16_t *data_ptr,
196                         uint16_t *output_ptr);
197
198 #ifdef __cplusplus
199 }
200 #endif
201
202 #endif