Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 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 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 21 | #include <vlibmemory/unix_shared_memory_queue.h> |
| 22 | #include <vlibmemory/api.h> |
| 23 | #include <vppinfra/lock.h> |
| 24 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 25 | typedef struct _segment_manager_properties |
| 26 | { |
| 27 | /** Session fifo sizes. */ |
| 28 | u32 rx_fifo_size; |
| 29 | u32 tx_fifo_size; |
| 30 | |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 31 | /** Preallocated pool sizes */ |
| 32 | u32 preallocated_fifo_pairs; |
| 33 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 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 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 40 | /** Use private memory segment instead of shared memory */ |
| 41 | u8 use_private_segment; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 42 | |
| 43 | /** Use one or more private mheaps, instead of the global heap */ |
| 44 | u32 private_segment_count; |
| 45 | u32 private_segment_size; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 46 | } segment_manager_properties_t; |
| 47 | |
| 48 | typedef struct _segment_manager |
| 49 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 50 | clib_spinlock_t lockp; |
| 51 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 52 | /** segments mapped by this manager */ |
| 53 | u32 *segment_indices; |
| 54 | |
| 55 | /** Owner app index */ |
| 56 | u32 app_index; |
| 57 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 58 | /** |
| 59 | * Pointer to manager properties. Could be shared among all of |
| 60 | * an app's segment managers s |
| 61 | */ |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 62 | u32 properties_index; |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * First segment should not be deleted unless segment manger is deleted. |
| 66 | * This also indicates that the segment manager is the first to have been |
| 67 | * allocated for the app. |
| 68 | */ |
| 69 | u8 first_is_protected; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 70 | } segment_manager_t; |
| 71 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 72 | #define SEGMENT_MANAGER_INVALID_APP_INDEX ((u32) ~0) |
| 73 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 74 | /** Pool of segment managers */ |
| 75 | extern segment_manager_t *segment_managers; |
| 76 | |
| 77 | always_inline segment_manager_t * |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 78 | segment_manager_get (u32 index) |
| 79 | { |
| 80 | return pool_elt_at_index (segment_managers, index); |
| 81 | } |
| 82 | |
| 83 | always_inline segment_manager_t * |
| 84 | segment_manager_get_if_valid (u32 index) |
| 85 | { |
| 86 | if (pool_is_free_index (segment_managers, index)) |
| 87 | return 0; |
| 88 | return pool_elt_at_index (segment_managers, index); |
| 89 | } |
| 90 | |
| 91 | always_inline u32 |
| 92 | segment_manager_index (segment_manager_t * sm) |
| 93 | { |
| 94 | return sm - segment_managers; |
| 95 | } |
| 96 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 97 | segment_manager_t *segment_manager_new (); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 98 | int |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 99 | segment_manager_init (segment_manager_t * sm, u32 props_index, u32 seg_size); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 100 | |
| 101 | void segment_manager_get_segment_info (u32 index, u8 ** name, u32 * size); |
| 102 | int |
| 103 | session_manager_add_first_segment (segment_manager_t * sm, u32 segment_size); |
| 104 | int session_manager_add_segment (segment_manager_t * sm); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 105 | void segment_manager_del_sessions (segment_manager_t * sm); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 106 | void segment_manager_del (segment_manager_t * sm); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 107 | void segment_manager_init_del (segment_manager_t * sm); |
| 108 | u8 segment_manager_has_fifos (segment_manager_t * sm); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 109 | int |
| 110 | segment_manager_alloc_session_fifos (segment_manager_t * sm, |
| 111 | svm_fifo_t ** server_rx_fifo, |
| 112 | svm_fifo_t ** server_tx_fifo, |
| 113 | u32 * fifo_segment_index); |
| 114 | void |
| 115 | segment_manager_dealloc_fifos (u32 svm_segment_index, svm_fifo_t * rx_fifo, |
| 116 | svm_fifo_t * tx_fifo); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 117 | unix_shared_memory_queue_t *segment_manager_alloc_queue (segment_manager_t * |
| 118 | sm, u32 queue_size); |
| 119 | void segment_manager_dealloc_queue (segment_manager_t * sm, |
| 120 | unix_shared_memory_queue_t * q); |
Florin Coras | 4e4531e | 2017-11-06 23:27:56 -0800 | [diff] [blame] | 121 | void segment_manager_app_detach (segment_manager_t * sm); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 122 | |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 123 | segment_manager_properties_t *segment_manager_properties_alloc (void); |
| 124 | void segment_manager_properties_free (segment_manager_properties_t * p); |
| 125 | segment_manager_properties_t *segment_manager_properties_get (u32 smp_index); |
| 126 | u32 segment_manager_properties_index (segment_manager_properties_t * p); |
| 127 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 128 | #endif /* SRC_VNET_SESSION_SEGMENT_MANAGER_H_ */ |
| 129 | /* |
| 130 | * fd.io coding-style-patch-verification: ON |
| 131 | * |
| 132 | * Local Variables: |
| 133 | * eval: (c-set-style "gnu") |
| 134 | * End: |
| 135 | */ |