FD.io VPP  v19.04.4-rc0-5-ge88582fac
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 <vnet/vnet.h>
19 #include <svm/svm_fifo_segment.h>
20 #include <svm/message_queue.h>
21 #include <vlibmemory/api.h>
22 #include <vppinfra/lock.h>
23 #include <vppinfra/valloc.h>
24 
25 typedef struct _segment_manager_properties
26 {
27  u32 rx_fifo_size; /**< receive fifo size */
28  u32 tx_fifo_size; /**< transmit fifo size */
29  u32 evt_q_size; /**< event queue length */
30  u32 segment_size; /**< first segment size */
31  u32 prealloc_fifos; /**< preallocated fifo pairs */
32  u32 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  ssvm_segment_type_t segment_type; /**< seg type: if set to SSVM_N_TYPES,
37  private segments are used */
39 
40 typedef struct _segment_manager
41 {
42  /** Pool of segments allocated by this manager */
44 
45  /** rwlock that protects the segments pool */
46  clib_rwlock_t segments_rwlock;
47 
48  /** Owner app worker index */
49  u32 app_wrk_index;
50 
51  /**
52  * First segment should not be deleted unless segment manger is deleted.
53  * This also indicates that the segment manager is the first to have been
54  * allocated for the app.
55  */
56  u8 first_is_protected;
57 
58  /**
59  * App event queue allocated in first segment
60  */
61  svm_msg_q_t *event_queue;
63 
64 #define segment_manager_foreach_segment_w_lock(VAR, SM, BODY) \
65 do { \
66  clib_rwlock_reader_lock (&(SM)->segments_rwlock); \
67  pool_foreach((VAR), ((SM)->segments), (BODY)); \
68  clib_rwlock_reader_unlock (&(SM)->segments_rwlock); \
69 } while (0)
70 
71 typedef struct segment_manager_main_
72 {
73  /** Pool of segment managers */
75 
76  /** Virtual address allocator */
78 
80 
82 
84 {
88 
89 #define SEGMENT_MANAGER_INVALID_APP_INDEX ((u32) ~0)
90 
91 /** Pool of segment managers */
93 
96 {
97  return pool_elt_at_index (segment_manager_main.segment_managers, index);
98 }
99 
102 {
103  if (pool_is_free_index (segment_manager_main.segment_managers, index))
104  return 0;
105  return pool_elt_at_index (segment_manager_main.segment_managers, index);
106 }
107 
110 {
111  return sm - segment_manager_main.segment_managers;
112 }
113 
116 {
117  return sm->event_queue;
118 }
119 
122  u32 segment_index)
123 {
124  return (((u64) segment_manager_index << 32) | segment_index);
125 }
126 
128  svm_fifo_segment_private_t * segment);
129 
131 int segment_manager_init (segment_manager_t * sm, u32 first_seg_size,
132  u32 prealloc_fifo_pairs);
133 
135  u32 segment_index);
139  u32 segment_index);
140 int segment_manager_add_segment (segment_manager_t * sm, u32 segment_size);
145 
147  u32 segment_size);
153  svm_fifo_t ** server_rx_fifo,
154  svm_fifo_t ** server_tx_fifo,
155  u32 * fifo_segment_index);
157  u32 rx_fifo_size, u32 tx_fifo_size,
158  svm_fifo_t ** rx_fifo,
159  svm_fifo_t ** tx_fifo);
161  svm_fifo_t * tx_fifo);
165  props);
168 
172 
173 #endif /* SRC_VNET_SESSION_SEGMENT_MANAGER_H_ */
174 /*
175  * fd.io coding-style-patch-verification: ON
176  *
177  * Local Variables:
178  * eval: (c-set-style "gnu")
179  * End:
180  */
int segment_manager_alloc_session_fifos(segment_manager_t *sm, svm_fifo_t **server_rx_fifo, svm_fifo_t **server_tx_fifo, u32 *fifo_segment_index)
static segment_manager_t * segment_manager_get_if_valid(u32 index)
int segment_manager_try_alloc_fifos(svm_fifo_segment_private_t *fs, u32 rx_fifo_size, u32 tx_fifo_size, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
struct _segment_manager_properties segment_manager_properties_t
int segment_manager_init(segment_manager_t *sm, u32 first_seg_size, u32 prealloc_fifo_pairs)
Initializes segment manager based on options provided.
unsigned long u64
Definition: types.h:89
clib_valloc_main_t va_allocator
Virtual address allocator.
struct segment_manager_main_init_args_ segment_manager_main_init_args_t
svm_fifo_segment_private_t * segment_manager_get_segment_w_handle(u64)
segment_manager_t * segment_managers
Pool of segment managers.
segment_manager_main_t segment_manager_main
unsigned char u8
Definition: types.h:56
u8 segment_manager_has_fifos(segment_manager_t *sm)
struct _svm_fifo svm_fifo_t
void segment_manager_segment_reader_unlock(segment_manager_t *sm)
enum ssvm_segment_type_ ssvm_segment_type_t
void segment_manager_app_detach(segment_manager_t *sm)
#define always_inline
Definition: clib.h:98
int segment_manager_add_first_segment(segment_manager_t *sm, u32 segment_size)
Simple first-fit virtual space allocator.
unsigned int u32
Definition: types.h:88
void segment_manager_del_segment(segment_manager_t *sm, svm_fifo_segment_private_t *fs)
Remove segment without lock.
u64 segment_manager_segment_handle(segment_manager_t *sm, svm_fifo_segment_private_t *segment)
u32 segment_manager_evt_q_expected_size(u32 q_size)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
int segment_manager_add_segment(segment_manager_t *sm, u32 segment_size)
Adds segment to segment manager&#39;s pool.
segment_manager_properties_t * segment_manager_properties_init(segment_manager_properties_t *sm)
Unidirectional shared-memory multi-ring message queue.
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:283
void segment_manager_segment_writer_unlock(segment_manager_t *sm)
static u32 segment_manager_index(segment_manager_t *sm)
static u64 segment_manager_make_segment_handle(u32 segment_manager_index, u32 segment_index)
svm_msg_q_t * segment_manager_alloc_queue(svm_fifo_segment_private_t *fs, segment_manager_properties_t *props)
Allocates shm queue in the first segment.
svm_fifo_segment_private_t * segment_manager_get_segment(segment_manager_t *, u32 segment_index)
Reads a segment from the segment manager&#39;s pool without lock.
void segment_manager_init_del(segment_manager_t *sm)
struct segment_manager_main_ segment_manager_main_t
void segment_manager_del(segment_manager_t *sm)
Removes segment manager.
static svm_msg_q_t * segment_manager_event_queue(segment_manager_t *sm)
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.
svm_fifo_segment_private_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.
segment_manager_t * segment_managers
Pool of segment managers.
static void add_segment(mstate m, char *tbase, size_t tsize, flag_t mmapped)
Definition: dlmalloc.c:2576
void segment_manager_main_init(segment_manager_main_init_args_t *a)
void segment_manager_del_sessions(segment_manager_t *sm)
Initiate disconnects for all sessions &#39;owned&#39; by a segment manager.
static segment_manager_t * segment_manager_get(u32 index)
segment_manager_t * segment_manager_new()