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 | |
| 31 | /** Configured additional segment size */ |
| 32 | u32 add_segment_size; |
| 33 | |
| 34 | /** Flag that indicates if additional segments should be created */ |
| 35 | u8 add_segment; |
| 36 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 37 | /** Use private memory segment instead of shared memory */ |
| 38 | u8 use_private_segment; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 39 | } segment_manager_properties_t; |
| 40 | |
| 41 | typedef struct _segment_manager |
| 42 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 43 | clib_spinlock_t lockp; |
| 44 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 45 | /** segments mapped by this manager */ |
| 46 | u32 *segment_indices; |
| 47 | |
| 48 | /** Owner app index */ |
| 49 | u32 app_index; |
| 50 | |
| 51 | /** Pointer to manager properties. Could be shared among all of |
| 52 | * an app's segment managers s*/ |
| 53 | segment_manager_properties_t *properties; |
| 54 | } segment_manager_t; |
| 55 | |
| 56 | /** Pool of segment managers */ |
| 57 | extern segment_manager_t *segment_managers; |
| 58 | |
| 59 | always_inline segment_manager_t * |
| 60 | segment_manager_new () |
| 61 | { |
| 62 | segment_manager_t *sm; |
| 63 | pool_get (segment_managers, sm); |
| 64 | memset (sm, 0, sizeof (*sm)); |
| 65 | return sm; |
| 66 | } |
| 67 | |
| 68 | always_inline segment_manager_t * |
| 69 | segment_manager_get (u32 index) |
| 70 | { |
| 71 | return pool_elt_at_index (segment_managers, index); |
| 72 | } |
| 73 | |
| 74 | always_inline segment_manager_t * |
| 75 | segment_manager_get_if_valid (u32 index) |
| 76 | { |
| 77 | if (pool_is_free_index (segment_managers, index)) |
| 78 | return 0; |
| 79 | return pool_elt_at_index (segment_managers, index); |
| 80 | } |
| 81 | |
| 82 | always_inline u32 |
| 83 | segment_manager_index (segment_manager_t * sm) |
| 84 | { |
| 85 | return sm - segment_managers; |
| 86 | } |
| 87 | |
| 88 | int |
| 89 | segment_manager_init (segment_manager_t * sm, |
| 90 | segment_manager_properties_t * properties, |
| 91 | u32 seg_size); |
| 92 | |
| 93 | void segment_manager_get_segment_info (u32 index, u8 ** name, u32 * size); |
| 94 | int |
| 95 | session_manager_add_first_segment (segment_manager_t * sm, u32 segment_size); |
| 96 | int session_manager_add_segment (segment_manager_t * sm); |
| 97 | void segment_manager_del (segment_manager_t * sm); |
| 98 | int |
| 99 | segment_manager_alloc_session_fifos (segment_manager_t * sm, |
| 100 | svm_fifo_t ** server_rx_fifo, |
| 101 | svm_fifo_t ** server_tx_fifo, |
| 102 | u32 * fifo_segment_index); |
| 103 | void |
| 104 | segment_manager_dealloc_fifos (u32 svm_segment_index, svm_fifo_t * rx_fifo, |
| 105 | svm_fifo_t * tx_fifo); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 106 | unix_shared_memory_queue_t *segment_manager_alloc_queue (segment_manager_t * |
| 107 | sm, u32 queue_size); |
| 108 | void segment_manager_dealloc_queue (segment_manager_t * sm, |
| 109 | unix_shared_memory_queue_t * q); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 110 | |
| 111 | #endif /* SRC_VNET_SESSION_SEGMENT_MANAGER_H_ */ |
| 112 | /* |
| 113 | * fd.io coding-style-patch-verification: ON |
| 114 | * |
| 115 | * Local Variables: |
| 116 | * eval: (c-set-style "gnu") |
| 117 | * End: |
| 118 | */ |