FD.io VPP  v20.05.1-6-gf53edbc3b
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 struct _segment_manager
46 {
47  /** Pool of segments allocated by this manager */
48  fifo_segment_t *segments;
49 
50  /** rwlock that protects the segments pool */
51  clib_rwlock_t segments_rwlock;
52 
53  /** Owner app worker index */
54  u32 app_wrk_index;
55 
56  /**
57  * First segment should not be deleted unless segment manger is deleted.
58  * This also indicates that the segment manager is the first to have been
59  * allocated for the app.
60  */
61  u8 first_is_protected;
62 
63  /**
64  * App event queue allocated in first segment
65  */
66  svm_msg_q_t *event_queue;
67 
68  u32 max_fifo_size;
69  u8 high_watermark;
70  u8 low_watermark;
72 
74 {
78 
79 #define SEGMENT_MANAGER_INVALID_APP_INDEX ((u32) ~0)
80 
83 
84 /**
85  * Cleanup segment manager
86  *
87  * @param sm segment manager to be freed
88  */
90 
91 /**
92  * Initiate segment manager cleanup
93  *
94  * @param sm segment manager to be freed
95  */
100 
101 int segment_manager_add_segment (segment_manager_t * sm, uword segment_size);
103  fifo_segment_t * fs);
105  u32 segment_index);
108  u32 segment_index);
110  u32 segment_size);
112  u32 segment_index);
114  fifo_segment_t * segment);
117 
119  u32 thread_index,
120  svm_fifo_t ** rx_fifo,
121  svm_fifo_t ** tx_fifo);
123  u32 thread_index,
124  u32 rx_fifo_size, u32 tx_fifo_size,
125  svm_fifo_t ** rx_fifo,
126  svm_fifo_t ** tx_fifo);
128  svm_fifo_t * tx_fifo);
131  session_t * s);
132 
134  u8 high_watermark, u8 low_watermark);
135 
137 
139  segment_manager_props_t * props);
143 
146 
147 /**
148  * Cleanup segment manager sessions
149  *
150  * Initiates disconnects for all sessions 'owned' by a segment manager by
151  * leveraging the backpointers that fifos keep.
152  *
153  * @param sm segment manager whose sessions are to be disconnected
154  */
156 void segment_manager_format_sessions (segment_manager_t * sm, int verbose);
157 
159 
161  sm);
162 
163 static inline void
164 segment_manager_parse_segment_handle (u64 segment_handle, u32 * sm_index,
165  u32 * segment_index)
166 {
167  *sm_index = segment_handle >> 32;
168  *segment_index = segment_handle & 0xFFFFFFFF;
169 }
170 
171 #endif /* SRC_VNET_SESSION_SEGMENT_MANAGER_H_ */
172 /*
173  * fd.io coding-style-patch-verification: ON
174  *
175  * Local Variables:
176  * eval: (c-set-style "gnu")
177  * End:
178  */
void segment_manager_free(segment_manager_t *sm)
Cleanup segment manager.
u32 segment_manager_index(segment_manager_t *sm)
int segment_manager_init(segment_manager_t *sm)
Initializes segment manager based on options provided.
a
Definition: bitmap.h:538
unsigned long u64
Definition: types.h:89
struct segment_manager_main_init_args_ segment_manager_main_init_args_t
static void segment_manager_parse_segment_handle(u64 segment_handle, u32 *sm_index, u32 *segment_index)
fifo_segment_t * segment_manager_get_segment_w_handle(u64 sh)
unsigned char u8
Definition: types.h:56
u8 segment_manager_has_fifos(segment_manager_t *sm)
segment_manager_t * segment_manager_get(u32 index)
void segment_manager_segment_reader_unlock(segment_manager_t *sm)
enum ssvm_segment_type_ ssvm_segment_type_t
segment_manager_props_t * segment_manager_props_init(segment_manager_props_t *sm)
void segment_manager_app_detach(segment_manager_t *sm)
static CLIB_NOSANITIZE_ADDR void add_segment(mstate m, char *tbase, size_t tsize, flag_t mmapped)
Definition: dlmalloc.c:2585
int segment_manager_add_first_segment(segment_manager_t *sm, u32 segment_size)
Simple first-fit virtual space allocator.
segment_manager_t * segment_manager_alloc(void)
unsigned int u32
Definition: types.h:88
segment_manager_t * segment_manager_get_if_valid(u32 index)
u32 segment_manager_evt_q_expected_size(u32 q_size)
svm_msg_q_t * segment_manager_event_queue(segment_manager_t *sm)
int segment_manager_alloc_session_fifos(segment_manager_t *sm, u32 thread_index, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
u64 segment_manager_make_segment_handle(u32 segment_manager_index, u32 segment_index)
svm_msg_q_t * segment_manager_alloc_queue(fifo_segment_t *fs, segment_manager_props_t *props)
Allocates shm queue in the first segment.
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
void segment_manager_set_watermarks(segment_manager_t *sm, u8 high_watermark, u8 low_watermark)
struct _segment_manager_props segment_manager_props_t
int segment_manager_add_segment(segment_manager_t *sm, uword segment_size)
Adds segment to segment manager&#39;s pool.
void segment_manager_del_segment(segment_manager_t *sm, fifo_segment_t *fs)
Remove segment without lock.
fifo_segment_t * segment_manager_get_segment(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager&#39;s pool without lock.
u8 segment_manager_app_detached(segment_manager_t *sm)
Unidirectional shared-memory multi-ring message queue.
void segment_manager_detach_fifo(segment_manager_t *sm, svm_fifo_t *f)
void segment_manager_segment_writer_unlock(segment_manager_t *sm)
u64 segment_manager_segment_handle(segment_manager_t *sm, fifo_segment_t *segment)
void segment_manager_attach_fifo(segment_manager_t *sm, svm_fifo_t *f, session_t *s)
u64 uword
Definition: types.h:112
struct _segment_manager segment_manager_t
struct _svm_queue svm_queue_t
void segment_manager_dealloc_queue(segment_manager_t *sm, svm_queue_t *q)
Frees shm queue allocated in the first segment.
void segment_manager_init_free(segment_manager_t *sm)
Initiate segment manager cleanup.
void segment_manager_format_sessions(segment_manager_t *sm, int verbose)
fifo_segment_t * segment_manager_get_segment_w_lock(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager&#39;s pool and acquires reader lock.
void segment_manager_main_init(segment_manager_main_init_args_t *a)
struct _svm_fifo svm_fifo_t
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)
void segment_manager_del_sessions(segment_manager_t *sm)
Cleanup segment manager sessions.