FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
fifo_types.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SRC_SVM_FIFO_TYPES_H_
17 #define SRC_SVM_FIFO_TYPES_H_
18 
19 #include <svm/ssvm.h>
20 #include <vppinfra/clib.h>
21 #include <vppinfra/rbtree.h>
22 #include <vppinfra/lock.h>
23 
24 #define SVM_FIFO_TRACE (0)
25 #define SVM_FIFO_MAX_EVT_SUBSCRIBERS 7
26 
28 
29 typedef struct svm_fifo_chunk_
30 {
31  u32 start_byte; /**< chunk start byte */
32  u32 length; /**< length of chunk in bytes */
33  struct svm_fifo_chunk_ *next; /**< pointer to next chunk in linked-lists */
34  rb_node_index_t enq_rb_index; /**< enq node index if chunk in rbtree */
35  rb_node_index_t deq_rb_index; /**< deq node index if chunk in rbtree */
36  u8 data[0]; /**< start of chunk data */
38 
39 typedef struct
40 {
41  u32 next; /**< Next linked-list element pool index */
42  u32 prev; /**< Previous linked-list element pool index */
43  u32 start; /**< Start of segment, normalized*/
44  u32 length; /**< Length of segment */
46 
47 typedef struct
48 {
53 
54 typedef struct _svm_fifo
55 {
56  CLIB_CACHE_LINE_ALIGN_MARK (shared_first);
57  fifo_segment_header_t *fs_hdr;/**< fifo segment header for fifo */
58  svm_fifo_chunk_t *start_chunk;/**< first chunk in fifo chunk list */
59  svm_fifo_chunk_t *end_chunk; /**< end chunk in fifo chunk list */
60  u32 min_alloc; /**< min chunk alloc if space available */
61  u32 size; /**< size of the fifo in bytes */
62  u8 flags; /**< fifo flags */
63  u8 slice_index; /**< segment slice for fifo */
64 
65  CLIB_CACHE_LINE_ALIGN_MARK (shared_second);
66  volatile u32 has_event; /**< non-zero if deq event exists */
67  u32 master_session_index; /**< session layer session index */
68  u32 client_session_index; /**< app session index */
69  u8 master_thread_index; /**< session layer thread index */
70  u8 client_thread_index; /**< app worker index */
71  i8 refcnt; /**< reference count */
72  u32 segment_manager; /**< session layer segment manager index */
73  u32 segment_index; /**< segment index in segment manager */
74  struct _svm_fifo *next; /**< next in freelist/active chain */
75  struct _svm_fifo *prev; /**< prev in active chain */
76 
77  CLIB_CACHE_LINE_ALIGN_MARK (consumer);
78  rb_tree_t ooo_deq_lookup; /**< rbtree for ooo deq chunk lookup */
79  svm_fifo_chunk_t *head_chunk; /**< tracks chunk where head lands */
80  svm_fifo_chunk_t *ooo_deq; /**< last chunk used for ooo dequeue */
81  u32 head; /**< fifo head position/byte */
82  volatile u32 want_deq_ntf; /**< producer wants nudge */
83  volatile u32 has_deq_ntf;
84 
85  CLIB_CACHE_LINE_ALIGN_MARK (producer);
86  rb_tree_t ooo_enq_lookup; /**< rbtree for ooo enq chunk lookup */
87  u32 tail; /**< fifo tail position/byte */
88  u32 ooos_list_head; /**< Head of out-of-order linked-list */
89  svm_fifo_chunk_t *tail_chunk; /**< tracks chunk where tail lands */
90  svm_fifo_chunk_t *ooo_enq; /**< last chunk used for ooo enqueue */
91  ooo_segment_t *ooo_segments; /**< Pool of ooo segments */
92  u32 ooos_newest; /**< Last segment to have been updated */
93  volatile u8 n_subscribers; /**< Number of subscribers for io events */
94  u8 subscribers[SVM_FIFO_MAX_EVT_SUBSCRIBERS];
95 
96 #if SVM_FIFO_TRACE
98 #endif
99 
100 } svm_fifo_t;
101 
102 typedef struct fifo_segment_slice_
103 {
104  svm_fifo_t *fifos; /**< Linked list of active RX fifos */
105  svm_fifo_t *free_fifos; /**< Freelists by fifo size */
106  svm_fifo_chunk_t **free_chunks; /**< Freelists by chunk size */
107  u32 *num_chunks; /**< Allocated chunks by chunk size */
108  uword n_fl_chunk_bytes; /**< Chunk bytes on freelist */
109  uword virtual_mem; /**< Slice sum of all fifo sizes */
112 
114 {
115  fifo_segment_slice_t *slices; /** Fixed array of slices */
116  ssvm_shared_header_t *ssvm_sh; /**< Pointer to fs ssvm shared hdr */
117  uword n_free_bytes; /**< Segment free bytes */
118  uword n_cached_bytes; /**< Cached bytes */
119  u32 n_active_fifos; /**< Number of active fifos */
120  u32 n_reserved_bytes; /**< Bytes not to be allocated */
121  u32 max_log2_chunk_size; /**< Max log2(chunk size) for fs */
122  u8 flags; /**< Segment flags */
123  u8 n_slices; /**< Number of slices */
124  u8 high_watermark; /**< Memory pressure watermark high */
125  u8 low_watermark; /**< Memory pressure watermark low */
126  u8 pct_first_alloc; /**< Pct of fifo size to alloc */
127 };
128 
129 void fsh_virtual_mem_update (fifo_segment_header_t * fsh, u32 slice_index,
130  int n_bytes);
131 
132 #endif /* SRC_SVM_FIFO_TYPES_H_ */
133 
134 /*
135  * fd.io coding-style-patch-verification: ON
136  *
137  * Local Variables:
138  * eval: (c-set-style "gnu")
139  * End:
140  */
u32 length
length of chunk in bytes
Definition: fifo_types.h:32
u8 low_watermark
Memory pressure watermark low.
Definition: fifo_types.h:125
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
Definition: vlib_api_cli.c:899
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
ssvm_shared_header_t * ssvm_sh
Fixed array of slices.
Definition: fifo_types.h:116
u8 pct_first_alloc
Pct of fifo size to alloc.
Definition: fifo_types.h:126
u8 n_slices
Number of slices.
Definition: fifo_types.h:123
u32 prev
Previous linked-list element pool index.
Definition: fifo_types.h:42
struct fifo_segment_slice_ fifo_segment_slice_t
u32 max_log2_chunk_size
Max log2(chunk size) for fs.
Definition: fifo_types.h:121
unsigned char u8
Definition: types.h:56
u32 n_active_fifos
Number of active fifos.
Definition: fifo_types.h:119
uword virtual_mem
Slice sum of all fifo sizes.
Definition: fifo_types.h:109
uword n_fl_chunk_bytes
Chunk bytes on freelist.
Definition: fifo_types.h:108
unsigned int u32
Definition: types.h:88
uword n_cached_bytes
Cached bytes.
Definition: fifo_types.h:118
u8 high_watermark
Memory pressure watermark high.
Definition: fifo_types.h:124
struct svm_fifo_chunk_ * next
pointer to next chunk in linked-lists
Definition: fifo_types.h:33
svm_fifo_t * free_fifos
Freelists by fifo size.
Definition: fifo_types.h:105
u32 n_reserved_bytes
Bytes not to be allocated.
Definition: fifo_types.h:120
u64 size
Definition: vhost_user.h:150
u32 rb_node_index_t
Definition: rbtree.h:24
#define SVM_FIFO_MAX_EVT_SUBSCRIBERS
Definition: fifo_types.h:25
fifo_segment_slice_t * slices
Definition: fifo_types.h:115
signed char i8
Definition: types.h:45
clib_spinlock_t chunk_lock
Definition: fifo_types.h:110
u32 * num_chunks
Allocated chunks by chunk size.
Definition: fifo_types.h:107
svm_fifo_t * fifos
Linked list of active RX fifos.
Definition: fifo_types.h:104
u32 flags
Definition: vhost_user.h:248
u32 start_byte
chunk start byte
Definition: fifo_types.h:31
void fsh_virtual_mem_update(fifo_segment_header_t *fsh, u32 slice_index, int n_bytes)
Definition: fifo_segment.c:115
rb_node_index_t deq_rb_index
deq node index if chunk in rbtree
Definition: fifo_types.h:35
u8 data[0]
start of chunk data
Definition: fifo_types.h:36
u32 length
Length of segment.
Definition: fifo_types.h:44
u32 next
Next linked-list element pool index.
Definition: fifo_types.h:41
u8 flags
Segment flags.
Definition: fifo_types.h:122
u64 uword
Definition: types.h:112
rb_node_index_t enq_rb_index
enq node index if chunk in rbtree
Definition: fifo_types.h:34
struct _svm_fifo svm_fifo_t
u32 start
Start of segment, normalized.
Definition: fifo_types.h:43
svm_fifo_chunk_t ** free_chunks
Freelists by chunk size.
Definition: fifo_types.h:106
uword n_free_bytes
Segment free bytes.
Definition: fifo_types.h:117
struct svm_fifo_chunk_ svm_fifo_chunk_t