FD.io VPP  v18.07-34-g55fbdb9
Vector Packet Processing
segment_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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/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  /** Session fifo sizes. */
28  u32 rx_fifo_size;
29  u32 tx_fifo_size;
30  u32 evt_q_size;
31 
32  /** Configured additional segment size */
33  u32 add_segment_size;
34 
35  /** Flag that indicates if additional segments should be created */
36  u8 add_segment;
37 
38  /** Segment type: if set to SSVM_N_TYPES, private segments are used */
39  ssvm_segment_type_t segment_type;
40 
42 
43 typedef struct _segment_manager
44 {
45  /** Pool of segments allocated by this manager */
47 
48  /** rwlock that protects the segments pool */
49  clib_rwlock_t segments_rwlock;
50 
51  /** Owner app index */
52  u32 app_index;
53 
54  /**
55  * First segment should not be deleted unless segment manger is deleted.
56  * This also indicates that the segment manager is the first to have been
57  * allocated for the app.
58  */
59  u8 first_is_protected;
60 
61  /**
62  * App event queue allocated in first segment
63  */
64  svm_queue_t *event_queue;
66 
67 #define segment_manager_foreach_segment_w_lock(VAR, SM, BODY) \
68 do { \
69  clib_rwlock_reader_lock (&(SM)->segments_rwlock); \
70  pool_foreach((VAR), ((SM)->segments), (BODY)); \
71  clib_rwlock_reader_unlock (&(SM)->segments_rwlock); \
72 } while (0)
73 
74 typedef struct segment_manager_main_
75 {
76  /** Pool of segment managers */
78 
79  /** Virtual address allocator */
81 
83 
85 
87 {
91 
92 #define SEGMENT_MANAGER_INVALID_APP_INDEX ((u32) ~0)
93 
94 /** Pool of segment managers */
96 
99 {
100  return pool_elt_at_index (segment_manager_main.segment_managers, index);
101 }
102 
105 {
106  if (pool_is_free_index (segment_manager_main.segment_managers, index))
107  return 0;
108  return pool_elt_at_index (segment_manager_main.segment_managers, index);
109 }
110 
113 {
114  return sm - segment_manager_main.segment_managers;
115 }
116 
119 {
120  return sm->event_queue;
121 }
122 
124 int segment_manager_init (segment_manager_t * sm, u32 first_seg_size,
125  u32 prealloc_fifo_pairs);
126 
128  sm,
129  u32 segment_index);
132  u32 segment_index);
133 int segment_manager_add_segment (segment_manager_t * sm, u32 segment_size);
138 
140  u32 segment_size);
146  svm_fifo_t ** server_rx_fifo,
147  svm_fifo_t ** server_tx_fifo,
148  u32 * fifo_segment_index);
150  u32 rx_fifo_size, u32 tx_fifo_size,
151  svm_fifo_t ** rx_fifo,
152  svm_fifo_t ** tx_fifo);
153 void segment_manager_dealloc_fifos (u32 segment_index, svm_fifo_t * rx_fifo,
154  svm_fifo_t * tx_fifo);
156  u32 queue_size);
159 
163 
164 #endif /* SRC_VNET_SESSION_SEGMENT_MANAGER_H_ */
165 /*
166  * fd.io coding-style-patch-verification: ON
167  *
168  * Local Variables:
169  * eval: (c-set-style "gnu")
170  * End:
171  */
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
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:92
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.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:464
svm_fifo_segment_private_t * segment_manager_get_segment(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager&#39;s pool without lock.
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)
void segment_manager_dealloc_fifos(u32 segment_index, svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:271
void segment_manager_segment_writer_unlock(segment_manager_t *sm)
static u32 segment_manager_index(segment_manager_t *sm)
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.
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.
void segment_manager_main_init(segment_manager_main_init_args_t *a)
svm_queue_t * segment_manager_alloc_queue(svm_fifo_segment_private_t *fs, u32 queue_size)
Allocates shm queue in the first segment.
static svm_queue_t * segment_manager_event_queue(segment_manager_t *sm)
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()