FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
segment_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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 #ifndef SRC_VNET_SESSION_SEGMENT_MANAGER_H_
16 #define SRC_VNET_SESSION_SEGMENT_MANAGER_H_
17 
18 #include <svm/message_queue.h>
19 #include <vppinfra/lock.h>
20 #include <vppinfra/valloc.h>
21 #include <svm/fifo_segment.h>
23 
24 typedef struct _segment_manager_props
25 {
26  u32 rx_fifo_size; /**< receive fifo size */
27  u32 tx_fifo_size; /**< transmit fifo size */
28  u32 evt_q_size; /**< event queue length */
29  u32 prealloc_fifos; /**< preallocated fifo pairs */
30  u32 prealloc_fifo_hdrs; /**< preallocated fifo hdrs */
31  uword segment_size; /**< first segment size */
32  uword add_segment_size; /**< additional segment size */
33  u8 add_segment:1; /**< can add new segments flag */
34  u8 use_mq_eventfd:1; /**< use eventfds for mqs flag */
35  u8 reserved:6; /**< reserved flags */
36  u8 n_slices; /**< number of fs slices/threads */
37  ssvm_segment_type_t segment_type; /**< seg type: if set to SSVM_N_TYPES,
38  private segments are used */
39  u32 max_fifo_size; /**< max fifo size */
40  u8 high_watermark; /**< memory usage high watermark % */
41  u8 low_watermark; /**< memory usage low watermark % */
42  u8 pct_first_alloc; /**< pct of fifo size to alloc */
44 
45 typedef enum seg_manager_flag_
46 {
50 
51 typedef struct _segment_manager
52 {
53  /** Pool of segments allocated by this manager */
54  fifo_segment_t *segments;
55 
56  /** rwlock that protects the segments pool */
57  clib_rwlock_t segments_rwlock;
58 
59  /** Owner app worker index */
60  u32 app_wrk_index;
61 
62  /**
63  * First segment should not be deleted unless segment manger is deleted.
64  * This also indicates that the segment manager is the first to have been
65  * allocated for the app.
66  */
67  u8 first_is_protected;
68 
69  /**
70  * App event queue allocated in first segment
71  */
72  svm_msg_q_t *event_queue;
73 
74  u8 flags;
75 
76  u32 max_fifo_size;
77  u8 high_watermark;
78  u8 low_watermark;
80 
81 #define SEGMENT_MANAGER_INVALID_APP_INDEX ((u32) ~0)
82 
86 
87 /**
88  * Cleanup segment manager
89  *
90  * @param sm segment manager to be freed
91  */
94 
95 /**
96  * Initiate segment manager cleanup
97  *
98  * @param sm segment manager to be freed
99  */
104 
106  u8 notify_app);
108  u8 flags);
110  fifo_segment_t * fs);
112  u32 fs_index);
114  u32 segment_index);
117  u32 segment_index);
119  u32 segment_size);
121  u32 segment_index);
123  fifo_segment_t * segment);
126 
129  svm_fifo_t ** rx_fifo,
130  svm_fifo_t ** tx_fifo);
133  u32 rx_fifo_size, u32 tx_fifo_size,
134  svm_fifo_t ** rx_fifo,
135  svm_fifo_t ** tx_fifo);
137  svm_fifo_t * tx_fifo);
140  session_t *s);
141 
143  u8 high_watermark, u8 low_watermark);
144 
146 
148  segment_manager_props_t * props);
152 
155 
156 /**
157  * Cleanup segment manager sessions
158  *
159  * Initiates disconnects for all sessions 'owned' by a segment manager by
160  * leveraging the backpointers that fifos keep.
161  *
162  * @param sm segment manager whose sessions are to be disconnected
163  */
166  session_state_t *states);
167 void segment_manager_format_sessions (segment_manager_t * sm, int verbose);
168 
169 void segment_manager_main_init (void);
170 
172  sm);
173 
174 static inline void
175 segment_manager_parse_segment_handle (u64 segment_handle, u32 * sm_index,
176  u32 * segment_index)
177 {
178  *sm_index = segment_handle >> 32;
179  *segment_index = segment_handle & 0xFFFFFFFF;
180 }
181 
182 #endif /* SRC_VNET_SESSION_SEGMENT_MANAGER_H_ */
183 /*
184  * fd.io coding-style-patch-verification: ON
185  *
186  * Local Variables:
187  * eval: (c-set-style "gnu")
188  * End:
189  */
segment_manager_alloc
segment_manager_t * segment_manager_alloc(void)
Definition: segment_manager.c:336
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
segment_manager_init_free
void segment_manager_init_free(segment_manager_t *sm)
Initiate segment manager cleanup.
Definition: segment_manager.c:532
session_types.h
segment_manager_get_if_valid
segment_manager_t * segment_manager_get_if_valid(u32 index)
Definition: segment_manager.c:553
seg_manager_flag_
seg_manager_flag_
Definition: segment_manager.h:45
segment_manager_segment_handle
u64 segment_manager_segment_handle(segment_manager_t *sm, fifo_segment_t *segment)
Definition: segment_manager.c:275
f
vlib_frame_t * f
Definition: interface_output.c:1098
segment_manager_alloc_session_fifos
int segment_manager_alloc_session_fifos(segment_manager_t *sm, u32 thread_index, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
Definition: segment_manager.c:737
segment_manager_make_segment_handle
u64 segment_manager_make_segment_handle(u32 segment_manager_index, u32 segment_index)
Definition: segment_manager.c:283
segment_manager_dealloc_queue
void segment_manager_dealloc_queue(segment_manager_t *sm, svm_queue_t *q)
Frees shm queue allocated in the first segment.
Definition: segment_manager.c:954
fifo_segment_t
Definition: fifo_segment.h:68
session_
Definition: session_types.h:175
segment_manager_t
struct _segment_manager segment_manager_t
svm_queue_t
struct _svm_queue svm_queue_t
message_queue.h
Unidirectional shared-memory multi-ring message queue.
segment_manager_app_detach
void segment_manager_app_detach(segment_manager_t *sm)
Definition: segment_manager.c:73
segment_manager_format_sessions
void segment_manager_format_sessions(segment_manager_t *sm, int verbose)
Definition: segment_manager.c:1062
segment_manager_get_segment_w_lock
fifo_segment_t * segment_manager_get_segment_w_lock(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager's pool and acquires reader lock.
Definition: segment_manager.c:311
segment_manager_event_queue
svm_msg_q_t * segment_manager_event_queue(segment_manager_t *sm)
Definition: segment_manager.c:945
segment_manager_free
void segment_manager_free(segment_manager_t *sm)
Cleanup segment manager.
Definition: segment_manager.c:471
segment_manager_app_detached
u8 segment_manager_app_detached(segment_manager_t *sm)
Definition: segment_manager.c:67
segment_manager_parse_segment_handle
static void segment_manager_parse_segment_handle(u64 segment_handle, u32 *sm_index, u32 *segment_index)
Definition: segment_manager.h:175
segment_manager_add_segment2
int segment_manager_add_segment2(segment_manager_t *sm, uword segment_size, u8 flags)
Definition: segment_manager.c:193
ssvm_segment_type_t
enum ssvm_segment_type_ ssvm_segment_type_t
svm_fifo_t
struct _svm_fifo svm_fifo_t
segment_manager_add_segment
int segment_manager_add_segment(segment_manager_t *sm, uword segment_size, u8 notify_app)
Definition: segment_manager.c:186
segment_manager_props_init
segment_manager_props_t * segment_manager_props_init(segment_manager_props_t *sm)
Definition: segment_manager.c:53
SEG_MANAGER_F_DETACHED_LISTENER
@ SEG_MANAGER_F_DETACHED_LISTENER
Definition: segment_manager.h:48
segment_manager_attach_fifo
void segment_manager_attach_fifo(segment_manager_t *sm, svm_fifo_t **f, session_t *s)
Definition: segment_manager.c:878
segment_manager_props_t
struct _segment_manager_props segment_manager_props_t
lock.h
clib_rw_lock_
Definition: lock.h:139
segment_manager_free_safe
void segment_manager_free_safe(segment_manager_t *sm)
Definition: segment_manager.c:517
uword
u64 uword
Definition: types.h:112
segment_manager_get
segment_manager_t * segment_manager_get(u32 index)
Definition: segment_manager.c:547
segment_manager_del_sessions_filter
void segment_manager_del_sessions_filter(segment_manager_t *sm, session_state_t *states)
Initiate disconnects for sessions in specified state 'owned' by a segment manager.
Definition: segment_manager.c:649
segment_manager_dealloc_fifos
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
Definition: segment_manager.c:825
segment_manager_init
int segment_manager_init(segment_manager_t *sm)
Definition: segment_manager.c:347
segment_manager_del_sessions
void segment_manager_del_sessions(segment_manager_t *sm)
Cleanup segment manager sessions.
Definition: segment_manager.c:596
segment_manager_has_fifos
u8 segment_manager_has_fifos(segment_manager_t *sm)
Definition: segment_manager.c:567
svm_msg_q_
Definition: message_queue.h:72
valloc.h
Simple first-fit virtual space allocator.
add_segment
static CLIB_NOSANITIZE_ADDR void add_segment(mstate m, char *tbase, size_t tsize, flag_t mmapped)
Definition: dlmalloc.c:2585
segment_manager_index
u32 segment_manager_index(segment_manager_t *sm)
Definition: segment_manager.c:561
segment_manager_main_init
void segment_manager_main_init(void)
Definition: segment_manager.c:975
index
u32 index
Definition: flow_types.api:221
segment_manager_init_first
int segment_manager_init_first(segment_manager_t *sm)
Initializes segment manager based on options provided.
Definition: segment_manager.c:368
u64
unsigned long u64
Definition: types.h:89
session_state_t
session_state_t
Definition: session_types.h:143
u32
unsigned int u32
Definition: types.h:88
segment_manager_segment_reader_unlock
void segment_manager_segment_reader_unlock(segment_manager_t *sm)
Definition: segment_manager.c:324
seg_manager_flag_t
enum seg_manager_flag_ seg_manager_flag_t
segment_manager_try_alloc_fifos
int segment_manager_try_alloc_fifos(fifo_segment_t *fs, u32 thread_index, u32 rx_fifo_size, u32 tx_fifo_size, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
Definition: segment_manager.c:698
segment_manager_detach_fifo
void segment_manager_detach_fifo(segment_manager_t *sm, svm_fifo_t **f)
Definition: segment_manager.c:868
u8
unsigned char u8
Definition: types.h:56
segment_manager_get_segment_w_handle
fifo_segment_t * segment_manager_get_segment_w_handle(u64 sh)
Definition: segment_manager.c:290
segment_manager_set_watermarks
void segment_manager_set_watermarks(segment_manager_t *sm, u8 high_watermark, u8 low_watermark)
Definition: segment_manager.c:1126
segment_manager_alloc_queue
svm_msg_q_t * segment_manager_alloc_queue(fifo_segment_t *fs, segment_manager_props_t *props)
Allocates shm queue in the first segment.
Definition: segment_manager.c:914
segment_manager_del_segment
void segment_manager_del_segment(segment_manager_t *sm, fifo_segment_t *fs)
Remove segment without lock.
Definition: segment_manager.c:203
segment_manager_evt_q_expected_size
u32 segment_manager_evt_q_expected_size(u32 q_size)
Definition: segment_manager.c:892
segment_manager_get_segment
fifo_segment_t * segment_manager_get_segment(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager's pool without lock.
Definition: segment_manager.c:269
segment_manager_lock_and_del_segment
void segment_manager_lock_and_del_segment(segment_manager_t *sm, u32 fs_index)
Definition: segment_manager.c:260
fifo_segment.h
segment_manager_add_first_segment
int segment_manager_add_first_segment(segment_manager_t *sm, u32 segment_size)
segment_manager_segment_writer_unlock
void segment_manager_segment_writer_unlock(segment_manager_t *sm)
Definition: segment_manager.c:330
SEG_MANAGER_F_DETACHED
@ SEG_MANAGER_F_DETACHED
Definition: segment_manager.h:47
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105