FD.io VPP  v18.01-8-g0eacf49
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 
22 #include <vlibmemory/api.h>
23 #include <vppinfra/lock.h>
24 
25 typedef struct _segment_manager_properties
26 {
27  /** Session fifo sizes. */
28  u32 rx_fifo_size;
29  u32 tx_fifo_size;
30 
31  /** Preallocated pool sizes */
32  u32 preallocated_fifo_pairs;
33 
34  /** Configured additional segment size */
35  u32 add_segment_size;
36 
37  /** Flag that indicates if additional segments should be created */
38  u8 add_segment;
39 
40  /** Use private memory segment instead of shared memory */
41  u8 use_private_segment;
42 
43  /** Use one or more private mheaps, instead of the global heap */
44  u32 private_segment_count;
46 
47 typedef struct _segment_manager
48 {
49  clib_spinlock_t lockp;
50 
51  /** segments mapped by this manager */
52  u32 *segment_indices;
53 
54  /** Owner app index */
55  u32 app_index;
56 
57  /**
58  * Pointer to manager properties. Could be shared among all of
59  * an app's segment managers s
60  */
61  u32 properties_index;
62 
63  /**
64  * First segment should not be deleted unless segment manger is deleted.
65  * This also indicates that the segment manager is the first to have been
66  * allocated for the app.
67  */
68  u8 first_is_protected;
70 
71 #define SEGMENT_MANAGER_INVALID_APP_INDEX ((u32) ~0)
72 
73 /** Pool of segment managers */
75 
78 {
79  return pool_elt_at_index (segment_managers, index);
80 }
81 
84 {
86  return 0;
87  return pool_elt_at_index (segment_managers, index);
88 }
89 
92 {
93  return sm - segment_managers;
94 }
95 
97 int
98 segment_manager_init (segment_manager_t * sm, u32 props_index, u32 seg_size);
99 
100 void segment_manager_get_segment_info (u32 index, u8 ** name, u32 * size);
101 int
108 int
110  svm_fifo_t ** server_rx_fifo,
111  svm_fifo_t ** server_tx_fifo,
112  u32 * fifo_segment_index);
113 void
114 segment_manager_dealloc_fifos (u32 svm_segment_index, svm_fifo_t * rx_fifo,
115  svm_fifo_t * tx_fifo);
117  sm, u32 queue_size);
121 
126 
127 #endif /* SRC_VNET_SESSION_SEGMENT_MANAGER_H_ */
128 /*
129  * fd.io coding-style-patch-verification: ON
130  *
131  * Local Variables:
132  * eval: (c-set-style "gnu")
133  * End:
134  */
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)
void segment_manager_get_segment_info(u32 index, u8 **name, u32 *size)
static segment_manager_t * segment_manager_get_if_valid(u32 index)
struct _segment_manager_properties segment_manager_properties_t
void segment_manager_dealloc_queue(segment_manager_t *sm, unix_shared_memory_queue_t *q)
Frees shm queue allocated in the first segment.
u8 segment_manager_has_fifos(segment_manager_t *sm)
struct _svm_fifo svm_fifo_t
void segment_manager_app_detach(segment_manager_t *sm)
#define always_inline
Definition: clib.h:92
int session_manager_add_segment(segment_manager_t *sm)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:459
void segment_manager_properties_free(segment_manager_properties_t *p)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:268
static u32 segment_manager_index(segment_manager_t *sm)
unsigned int u32
Definition: types.h:88
int segment_manager_init(segment_manager_t *sm, u32 props_index, u32 seg_size)
Initializes segment manager based on options provided.
u64 size
Definition: vhost-user.h:76
void segment_manager_init_del(segment_manager_t *sm)
void segment_manager_del(segment_manager_t *sm)
Removes segment manager.
static int app_index
unix_shared_memory_queue_t * segment_manager_alloc_queue(segment_manager_t *sm, u32 queue_size)
Allocates shm queue in the first segment.
unsigned char u8
Definition: types.h:56
u32 segment_manager_properties_index(segment_manager_properties_t *p)
struct _segment_manager segment_manager_t
int session_manager_add_first_segment(segment_manager_t *sm, u32 segment_size)
segment_manager_t * segment_managers
Pool of segment managers.
void segment_manager_dealloc_fifos(u32 svm_segment_index, svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
segment_manager_properties_t * segment_manager_properties_get(u32 smp_index)
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_properties_t * segment_manager_properties_alloc(void)
segment_manager_t * segment_manager_new()
struct _unix_shared_memory_queue unix_shared_memory_queue_t