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 {
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 {
112 TAILQ_ENTRY(rte_distributor) 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 bufs[RTE_DISTRIB_MAX_WORKERS];
129 struct rte_distributor_returned_pkts returns;