4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
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.
33 #ifndef _RTE_DIST_PRIV_H_
34 #define _RTE_DIST_PRIV_H_
40 * The distributor is a component which is designed to pass packets
41 * one-at-a-time to workers, with dynamic load balancing.
49 #define RTE_DISTRIB_PREFIX "DT_"
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.
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 */
64 #define RTE_DISTRIB_BACKLOG_SIZE 8
65 #define RTE_DISTRIB_BACKLOG_MASK (RTE_DISTRIB_BACKLOG_SIZE - 1)
67 #define RTE_DISTRIB_MAX_RETURNS 128
68 #define RTE_DISTRIB_RETURNS_MASK (RTE_DISTRIB_MAX_RETURNS - 1)
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
75 #define RTE_DISTRIB_MAX_WORKERS 64
77 #define RTE_DISTRIBUTOR_NAMESIZE 32 /**< Length of name for instance */
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.
86 union rte_distributor_buffer_v20 {
87 volatile int64_t bufptr64;
88 char pad[RTE_CACHE_LINE_SIZE*3];
89 } __rte_cache_aligned;
92 * Transfer up to 8 mbufs at a time to/from workers, and
93 * flow matching algorithm optimised for 8 flow IDs at a time
95 #define RTE_DIST_BURST_SIZE 8
97 struct rte_distributor_backlog {
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;
105 struct rte_distributor_returned_pkts {
108 struct rte_mbuf *mbufs[RTE_DISTRIB_MAX_RETURNS];
111 struct rte_distributor_v20 {
112 TAILQ_ENTRY(rte_distributor_v20) next; /**< Next in list. */
114 char name[RTE_DISTRIBUTOR_NAMESIZE]; /**< Name of the ring. */
115 unsigned int num_workers; /**< Number of workers polling */
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.
125 struct rte_distributor_backlog backlog[RTE_DISTRIB_MAX_WORKERS];
127 union rte_distributor_buffer_v20 bufs[RTE_DISTRIB_MAX_WORKERS];
129 struct rte_distributor_returned_pkts returns;
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
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.
147 struct rte_distributor_buffer {
148 volatile int64_t bufptr64[RTE_DIST_BURST_SIZE]
149 __rte_cache_aligned; /* <= outgoing to worker */
151 int64_t pad1 __rte_cache_aligned; /* <= one cache line */
153 volatile int64_t retptr64[RTE_DIST_BURST_SIZE]
154 __rte_cache_aligned; /* <= incoming from worker */
156 int64_t pad2 __rte_cache_aligned; /* <= one cache line */
158 int count __rte_cache_aligned; /* <= number of current mbufs */
161 struct rte_distributor {
162 TAILQ_ENTRY(rte_distributor) next; /**< Next in list. */
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 */
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.
173 uint16_t in_flight_tags[RTE_DISTRIB_MAX_WORKERS][RTE_DIST_BURST_SIZE*2]
176 struct rte_distributor_backlog backlog[RTE_DISTRIB_MAX_WORKERS]
179 struct rte_distributor_buffer bufs[RTE_DISTRIB_MAX_WORKERS];
181 struct rte_distributor_returned_pkts returns;
183 enum rte_distributor_match_function dist_match_fn;
185 struct rte_distributor_v20 *d_v20;
189 find_match_scalar(struct rte_distributor *d,
191 uint16_t *output_ptr);
194 find_match_vec(struct rte_distributor *d,
196 uint16_t *output_ptr);