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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef SRC_SVM_FIFO_TYPES_H_
17 #define SRC_SVM_FIFO_TYPES_H_
20 #include <vppinfra/clib.h>
21 #include <vppinfra/rbtree.h>
23 #define SVM_FIFO_TRACE (0)
24 #define SVM_FIFO_MAX_EVT_SUBSCRIBERS 7
26 typedef struct fifo_segment_header_ fifo_segment_header_t;
28 typedef struct svm_fifo_chunk_
30 u32 start_byte; /**< chunk start byte */
31 u32 length; /**< length of chunk in bytes */
32 struct svm_fifo_chunk_ *next; /**< pointer to next chunk in linked-lists */
33 rb_node_index_t enq_rb_index; /**< enq node index if chunk in rbtree */
34 rb_node_index_t deq_rb_index; /**< deq node index if chunk in rbtree */
35 u8 data[0]; /**< start of chunk data */
40 u32 next; /**< Next linked-list element pool index */
41 u32 prev; /**< Previous linked-list element pool index */
42 u32 start; /**< Start of segment, normalized*/
43 u32 length; /**< Length of segment */
51 } svm_fifo_trace_elem_t;
53 typedef struct _svm_fifo
55 CLIB_CACHE_LINE_ALIGN_MARK (shared_first);
56 fifo_segment_header_t *fs_hdr;/**< fifo segment header for fifo */
57 svm_fifo_chunk_t *start_chunk;/**< first chunk in fifo chunk list */
58 svm_fifo_chunk_t *end_chunk; /**< end chunk in fifo chunk list */
59 u32 min_alloc; /**< min chunk alloc if space available */
60 u32 size; /**< size of the fifo in bytes */
61 u8 flags; /**< fifo flags */
62 u8 slice_index; /**< segment slice for fifo */
64 CLIB_CACHE_LINE_ALIGN_MARK (shared_second);
65 volatile u32 has_event; /**< non-zero if deq event exists */
66 u32 master_session_index; /**< session layer session index */
67 u32 client_session_index; /**< app session index */
68 u8 master_thread_index; /**< session layer thread index */
69 u8 client_thread_index; /**< app worker index */
70 i8 refcnt; /**< reference count */
71 u32 segment_manager; /**< session layer segment manager index */
72 u32 segment_index; /**< segment index in segment manager */
73 struct _svm_fifo *next; /**< next in freelist/active chain */
74 struct _svm_fifo *prev; /**< prev in active chain */
76 CLIB_CACHE_LINE_ALIGN_MARK (consumer);
77 rb_tree_t ooo_deq_lookup; /**< rbtree for ooo deq chunk lookup */
78 svm_fifo_chunk_t *head_chunk; /**< tracks chunk where head lands */
79 svm_fifo_chunk_t *ooo_deq; /**< last chunk used for ooo dequeue */
80 u32 head; /**< fifo head position/byte */
81 volatile u32 want_deq_ntf; /**< producer wants nudge */
82 volatile u32 has_deq_ntf;
84 CLIB_CACHE_LINE_ALIGN_MARK (producer);
85 rb_tree_t ooo_enq_lookup; /**< rbtree for ooo enq chunk lookup */
86 u32 tail; /**< fifo tail position/byte */
87 u32 ooos_list_head; /**< Head of out-of-order linked-list */
88 svm_fifo_chunk_t *tail_chunk; /**< tracks chunk where tail lands */
89 svm_fifo_chunk_t *ooo_enq; /**< last chunk used for ooo enqueue */
90 ooo_segment_t *ooo_segments; /**< Pool of ooo segments */
91 u32 ooos_newest; /**< Last segment to have been updated */
92 volatile u8 n_subscribers; /**< Number of subscribers for io events */
93 u8 subscribers[SVM_FIFO_MAX_EVT_SUBSCRIBERS];
96 svm_fifo_trace_elem_t *trace;
101 typedef struct fifo_segment_slice_
103 svm_fifo_t *fifos; /**< Linked list of active RX fifos */
104 svm_fifo_t *free_fifos; /**< Freelists by fifo size */
105 svm_fifo_chunk_t **free_chunks; /**< Freelists by chunk size */
106 uword n_fl_chunk_bytes; /**< Chunk bytes on freelist */
107 clib_spinlock_t chunk_lock;
108 } fifo_segment_slice_t;
110 struct fifo_segment_header_
112 fifo_segment_slice_t *slices; /** Fixed array of slices */
113 ssvm_shared_header_t *ssvm_sh; /**< Pointer to fs ssvm shared hdr */
114 uword n_free_bytes; /**< Segment free bytes */
115 uword n_cached_bytes; /**< Cached bytes */
116 u32 n_active_fifos; /**< Number of active fifos */
117 u32 n_reserved_bytes; /**< Bytes not to be allocated */
118 u32 max_log2_chunk_size; /**< Max log2(chunk size) for fs */
119 u8 flags; /**< Segment flags */
120 u8 n_slices; /**< Number of slices */
121 u8 high_watermark; /**< Memory pressure watermark high */
122 u8 low_watermark; /**< Memory pressure watermark low */
123 u8 pct_first_alloc; /**< Pct of fifo size to alloc */
126 #endif /* SRC_SVM_FIFO_TYPES_H_ */
129 * fd.io coding-style-patch-verification: ON
132 * eval: (c-set-style "gnu")