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>
22 #include <vppinfra/lock.h>
24 #define SVM_FIFO_TRACE (0)
25 #define SVM_FIFO_MAX_EVT_SUBSCRIBERS 7
27 typedef struct fifo_segment_header_ fifo_segment_header_t;
29 typedef struct svm_fifo_chunk_
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 */
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 */
52 } svm_fifo_trace_elem_t;
54 typedef struct _svm_fifo
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 */
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 */
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;
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];
97 svm_fifo_trace_elem_t *trace;
102 typedef struct fifo_segment_slice_
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 */
110 clib_spinlock_t chunk_lock;
111 } fifo_segment_slice_t;
113 struct fifo_segment_header_
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 */
129 void fsh_virtual_mem_update (fifo_segment_header_t * fsh, u32 slice_index,
132 #endif /* SRC_SVM_FIFO_TYPES_H_ */
135 * fd.io coding-style-patch-verification: ON
138 * eval: (c-set-style "gnu")