blob: b2a792d206be37d021425905f7c48367598e4a35 [file] [log] [blame]
Florin Coras6cf30ad2017-04-04 23:08:23 -07001/*
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>
Florin Corase86a8ed2018-01-05 03:20:25 -080020#include <svm/queue.h>
Florin Corasa5464812017-04-19 13:00:05 -070021#include <vlibmemory/api.h>
22#include <vppinfra/lock.h>
23
Florin Coras6cf30ad2017-04-04 23:08:23 -070024typedef struct _segment_manager_properties
25{
26 /** Session fifo sizes. */
27 u32 rx_fifo_size;
28 u32 tx_fifo_size;
29
Dave Barach10d8cc62017-05-30 09:30:07 -040030 /** Preallocated pool sizes */
31 u32 preallocated_fifo_pairs;
32
Florin Coras6cf30ad2017-04-04 23:08:23 -070033 /** Configured additional segment size */
34 u32 add_segment_size;
35
36 /** Flag that indicates if additional segments should be created */
37 u8 add_segment;
38
Florin Corasb384b542018-01-15 01:08:33 -080039 /** Segment type: if set to SSVM_N_TYPES, private segments are used */
40 ssvm_segment_type_t segment_type;
Dave Barach2c25a622017-06-26 11:35:07 -040041
42 /** Use one or more private mheaps, instead of the global heap */
43 u32 private_segment_count;
Florin Coras6cf30ad2017-04-04 23:08:23 -070044} segment_manager_properties_t;
45
46typedef struct _segment_manager
47{
Florin Corasa5464812017-04-19 13:00:05 -070048 clib_spinlock_t lockp;
49
Florin Coras6cf30ad2017-04-04 23:08:23 -070050 /** segments mapped by this manager */
51 u32 *segment_indices;
52
53 /** Owner app index */
54 u32 app_index;
55
Florin Corasc87c91d2017-08-16 19:55:49 -070056 /**
57 * Pointer to manager properties. Could be shared among all of
58 * an app's segment managers s
59 */
Florin Corasad0c77f2017-11-09 18:00:15 -080060 u32 properties_index;
Florin Corasc87c91d2017-08-16 19:55:49 -070061
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;
Florin Coras6cf30ad2017-04-04 23:08:23 -070068} segment_manager_t;
69
Florin Corasc87c91d2017-08-16 19:55:49 -070070#define SEGMENT_MANAGER_INVALID_APP_INDEX ((u32) ~0)
71
Florin Coras6cf30ad2017-04-04 23:08:23 -070072/** Pool of segment managers */
73extern segment_manager_t *segment_managers;
74
75always_inline segment_manager_t *
Florin Coras6cf30ad2017-04-04 23:08:23 -070076segment_manager_get (u32 index)
77{
78 return pool_elt_at_index (segment_managers, index);
79}
80
81always_inline segment_manager_t *
82segment_manager_get_if_valid (u32 index)
83{
84 if (pool_is_free_index (segment_managers, index))
85 return 0;
86 return pool_elt_at_index (segment_managers, index);
87}
88
89always_inline u32
90segment_manager_index (segment_manager_t * sm)
91{
92 return sm - segment_managers;
93}
94
Florin Corasc87c91d2017-08-16 19:55:49 -070095segment_manager_t *segment_manager_new ();
Florin Corasb384b542018-01-15 01:08:33 -080096int segment_manager_init (segment_manager_t * sm, u32 props_index,
97 u32 seg_size, u32 evt_queue_size);
Florin Coras6cf30ad2017-04-04 23:08:23 -070098
Florin Corasb384b542018-01-15 01:08:33 -080099svm_fifo_segment_private_t *segment_manager_get_segment (u32 segment_index);
100int segment_manager_add_first_segment (segment_manager_t * sm,
101 u32 segment_size);
102int segment_manager_add_segment (segment_manager_t * sm);
Florin Corasc87c91d2017-08-16 19:55:49 -0700103void segment_manager_del_sessions (segment_manager_t * sm);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700104void segment_manager_del (segment_manager_t * sm);
Florin Corasc87c91d2017-08-16 19:55:49 -0700105void segment_manager_init_del (segment_manager_t * sm);
106u8 segment_manager_has_fifos (segment_manager_t * sm);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700107int
108segment_manager_alloc_session_fifos (segment_manager_t * sm,
109 svm_fifo_t ** server_rx_fifo,
110 svm_fifo_t ** server_tx_fifo,
111 u32 * fifo_segment_index);
112void
113segment_manager_dealloc_fifos (u32 svm_segment_index, svm_fifo_t * rx_fifo,
114 svm_fifo_t * tx_fifo);
Florin Corasb384b542018-01-15 01:08:33 -0800115svm_queue_t *segment_manager_alloc_queue (segment_manager_t * sm,
116 u32 queue_size);
Florin Corase86a8ed2018-01-05 03:20:25 -0800117void segment_manager_dealloc_queue (segment_manager_t * sm, svm_queue_t * q);
Florin Coras4e4531e2017-11-06 23:27:56 -0800118void segment_manager_app_detach (segment_manager_t * sm);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700119
Florin Corasad0c77f2017-11-09 18:00:15 -0800120segment_manager_properties_t *segment_manager_properties_alloc (void);
121void segment_manager_properties_free (segment_manager_properties_t * p);
122segment_manager_properties_t *segment_manager_properties_get (u32 smp_index);
123u32 segment_manager_properties_index (segment_manager_properties_t * p);
124
Florin Coras6cf30ad2017-04-04 23:08:23 -0700125#endif /* SRC_VNET_SESSION_SEGMENT_MANAGER_H_ */
126/*
127 * fd.io coding-style-patch-verification: ON
128 *
129 * Local Variables:
130 * eval: (c-set-style "gnu")
131 * End:
132 */