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 | |
| 16 | #include <vnet/session/segment_manager.h> |
| 17 | #include <vnet/session/session.h> |
| 18 | #include <vnet/session/application.h> |
| 19 | |
| 20 | /** |
| 21 | * Counter used to build segment names |
| 22 | */ |
| 23 | u32 segment_name_counter = 0; |
| 24 | |
| 25 | /** |
| 26 | * Pool of segment managers |
| 27 | */ |
| 28 | segment_manager_t *segment_managers = 0; |
| 29 | |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 30 | /* |
| 31 | * Pool of segment manager properties |
| 32 | */ |
| 33 | static segment_manager_properties_t *segment_manager_properties_pool; |
| 34 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 35 | /** |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 36 | * Process private segment index |
| 37 | */ |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 38 | u32 *private_segment_indices; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 41 | * Default fifo and segment size. TODO config. |
| 42 | */ |
| 43 | u32 default_fifo_size = 1 << 16; |
| 44 | u32 default_segment_size = 1 << 20; |
| 45 | |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 46 | segment_manager_properties_t * |
| 47 | segment_manager_properties_alloc (void) |
| 48 | { |
| 49 | segment_manager_properties_t *props; |
| 50 | pool_get (segment_manager_properties_pool, props); |
| 51 | memset (props, 0, sizeof (*props)); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 52 | props->add_segment_size = default_segment_size; |
| 53 | props->rx_fifo_size = default_fifo_size; |
| 54 | props->tx_fifo_size = default_fifo_size; |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 55 | return props; |
| 56 | } |
| 57 | |
| 58 | void |
| 59 | segment_manager_properties_free (segment_manager_properties_t * props) |
| 60 | { |
| 61 | pool_put (segment_manager_properties_pool, props); |
| 62 | memset (props, 0xFB, sizeof (*props)); |
| 63 | } |
| 64 | |
| 65 | segment_manager_properties_t * |
| 66 | segment_manager_properties_get (u32 smp_index) |
| 67 | { |
| 68 | if (pool_is_free_index (segment_manager_properties_pool, smp_index)) |
| 69 | return 0; |
| 70 | return pool_elt_at_index (segment_manager_properties_pool, smp_index); |
| 71 | } |
| 72 | |
| 73 | u32 |
| 74 | segment_manager_properties_index (segment_manager_properties_t * p) |
| 75 | { |
| 76 | return p - segment_manager_properties_pool; |
| 77 | } |
| 78 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 79 | svm_fifo_segment_private_t * |
| 80 | segment_manager_get_segment (u32 segment_index) |
| 81 | { |
| 82 | return svm_fifo_segment_get_segment (segment_index); |
| 83 | } |
| 84 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 85 | void |
| 86 | segment_manager_get_segment_info (u32 index, u8 ** name, u32 * size) |
| 87 | { |
| 88 | svm_fifo_segment_private_t *s; |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 89 | s = svm_fifo_segment_get_segment (index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 90 | *name = s->ssvm.name; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 91 | *size = s->ssvm.ssvm_size; |
| 92 | } |
| 93 | |
| 94 | always_inline int |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 95 | segment_manager_add_segment_i (segment_manager_t * sm, u32 segment_size, |
| 96 | u32 protected_space) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 97 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 98 | svm_fifo_segment_create_args_t _ca = { 0 }, *ca = &_ca; |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 99 | segment_manager_properties_t *props; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 100 | |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 101 | props = segment_manager_properties_get (sm->properties_index); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 102 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 103 | /* Not configured for addition of new segments and not first */ |
| 104 | if (!props->add_segment && !segment_size) |
| 105 | { |
| 106 | clib_warning ("cannot allocate new segment"); |
| 107 | return VNET_API_ERROR_INVALID_VALUE; |
| 108 | } |
| 109 | |
| 110 | ca->segment_size = segment_size ? segment_size : props->add_segment_size; |
| 111 | ca->rx_fifo_size = props->rx_fifo_size; |
| 112 | ca->tx_fifo_size = props->tx_fifo_size; |
| 113 | ca->preallocated_fifo_pairs = props->preallocated_fifo_pairs; |
| 114 | ca->seg_protected_space = protected_space ? protected_space : 0; |
| 115 | |
| 116 | if (props->segment_type != SSVM_N_SEGMENT_TYPES) |
| 117 | { |
| 118 | ca->segment_name = (char *) format (0, "%d-%d%c", getpid (), |
| 119 | segment_name_counter++, 0); |
| 120 | ca->segment_type = props->segment_type; |
| 121 | if (svm_fifo_segment_create (ca)) |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 122 | { |
| 123 | clib_warning ("svm_fifo_segment_create ('%s', %d) failed", |
| 124 | ca->segment_name, ca->segment_size); |
| 125 | return VNET_API_ERROR_SVM_SEGMENT_CREATE_FAIL; |
| 126 | } |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 127 | vec_free (ca->segment_name); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 128 | } |
| 129 | else |
| 130 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 131 | u32 rx_fifo_size, tx_fifo_size; |
| 132 | u32 rx_rounded_data_size, tx_rounded_data_size; |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 133 | u32 approx_segment_count; |
| 134 | u64 approx_total_size; |
| 135 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 136 | ca->segment_name = "process-private-segment"; |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 137 | ca->private_segment_count = props->private_segment_count; |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 138 | |
| 139 | /* Calculate space requirements */ |
| 140 | rx_rounded_data_size = (1 << (max_log2 (ca->rx_fifo_size))); |
| 141 | tx_rounded_data_size = (1 << (max_log2 (ca->tx_fifo_size))); |
| 142 | |
| 143 | rx_fifo_size = sizeof (svm_fifo_t) + rx_rounded_data_size; |
| 144 | tx_fifo_size = sizeof (svm_fifo_t) + tx_rounded_data_size; |
| 145 | |
| 146 | approx_total_size = (u64) ca->preallocated_fifo_pairs |
| 147 | * (rx_fifo_size + tx_fifo_size); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 148 | approx_segment_count = (approx_total_size + protected_space |
| 149 | + (ca->segment_size - |
| 150 | 1)) / (u64) ca->segment_size; |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 151 | |
| 152 | /* The user asked us to figure it out... */ |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 153 | if (ca->private_segment_count == 0 |
| 154 | || approx_segment_count < ca->private_segment_count) |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 155 | { |
| 156 | ca->private_segment_count = approx_segment_count; |
| 157 | } |
| 158 | /* Follow directions, but issue a warning */ |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 159 | else if (approx_segment_count < ca->private_segment_count) |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 160 | { |
Florin Coras | ff6e769 | 2017-12-11 04:59:01 -0800 | [diff] [blame] | 161 | clib_warning ("Honoring segment count %u, calculated count was %u", |
| 162 | ca->private_segment_count, approx_segment_count); |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 163 | } |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 164 | else if (approx_segment_count > ca->private_segment_count) |
| 165 | { |
| 166 | clib_warning ("Segment count too low %u, calculated %u.", |
| 167 | ca->private_segment_count, approx_segment_count); |
| 168 | return VNET_API_ERROR_INVALID_VALUE; |
| 169 | } |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 170 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 171 | if (svm_fifo_segment_create_process_private (ca)) |
| 172 | clib_warning ("Failed to create process private segment"); |
| 173 | |
| 174 | ASSERT (vec_len (ca->new_segment_indices)); |
| 175 | } |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 176 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 177 | vec_append (sm->segment_indices, ca->new_segment_indices); |
| 178 | vec_free (ca->new_segment_indices); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | int |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 183 | segment_manager_add_segment (segment_manager_t * sm) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 184 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 185 | return segment_manager_add_segment_i (sm, 0, 0); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 188 | segment_manager_t * |
| 189 | segment_manager_new () |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 190 | { |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 191 | segment_manager_t *sm; |
| 192 | pool_get (segment_managers, sm); |
| 193 | memset (sm, 0, sizeof (*sm)); |
| 194 | return sm; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 197 | /** |
| 198 | * Initializes segment manager based on options provided. |
| 199 | * Returns error if svm segment allocation fails. |
| 200 | */ |
| 201 | int |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 202 | segment_manager_init (segment_manager_t * sm, u32 props_index, |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 203 | u32 first_seg_size, u32 evt_q_size) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 204 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 205 | u32 protected_space; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 206 | int rv; |
| 207 | |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 208 | sm->properties_index = props_index; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 209 | |
| 210 | protected_space = max_pow2 (sizeof (svm_queue_t) |
| 211 | + evt_q_size * sizeof (session_fifo_event_t)); |
| 212 | protected_space = round_pow2_u64 (protected_space, CLIB_CACHE_LINE_BYTES); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 213 | first_seg_size = first_seg_size > 0 ? first_seg_size : default_segment_size; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 214 | rv = segment_manager_add_segment_i (sm, first_seg_size, protected_space); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 215 | if (rv) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 216 | { |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 217 | clib_warning ("Failed to allocate segment"); |
| 218 | return rv; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 219 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 220 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 221 | clib_spinlock_init (&sm->lockp); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 222 | return 0; |
| 223 | } |
| 224 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 225 | u8 |
| 226 | segment_manager_has_fifos (segment_manager_t * sm) |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 227 | { |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 228 | svm_fifo_segment_private_t *segment; |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 229 | int i; |
| 230 | |
| 231 | for (i = 0; i < vec_len (sm->segment_indices); i++) |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 232 | { |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 233 | segment = svm_fifo_segment_get_segment (sm->segment_indices[i]); |
| 234 | if (CLIB_DEBUG && i && !svm_fifo_segment_has_fifos (segment) |
| 235 | && !(segment->h->flags & FIFO_SEGMENT_F_IS_PREALLOCATED)) |
| 236 | clib_warning ("segment %d has no fifos!", sm->segment_indices[i]); |
| 237 | if (svm_fifo_segment_has_fifos (segment)) |
| 238 | return 1; |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 239 | } |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | static u8 |
| 244 | segment_manager_app_detached (segment_manager_t * sm) |
| 245 | { |
| 246 | return (sm->app_index == SEGMENT_MANAGER_INVALID_APP_INDEX); |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 247 | } |
| 248 | |
Florin Coras | 4e4531e | 2017-11-06 23:27:56 -0800 | [diff] [blame] | 249 | void |
| 250 | segment_manager_app_detach (segment_manager_t * sm) |
| 251 | { |
| 252 | sm->app_index = SEGMENT_MANAGER_INVALID_APP_INDEX; |
| 253 | } |
| 254 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 255 | static void |
| 256 | segment_manager_del_segment (segment_manager_t * sm, u32 segment_index) |
| 257 | { |
| 258 | svm_fifo_segment_private_t *fifo_segment; |
| 259 | u32 svm_segment_index; |
| 260 | clib_spinlock_lock (&sm->lockp); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 261 | svm_segment_index = vec_elt (sm->segment_indices, segment_index); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 262 | fifo_segment = svm_fifo_segment_get_segment (svm_segment_index); |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 263 | if (!fifo_segment |
| 264 | || ((fifo_segment->h->flags & FIFO_SEGMENT_F_IS_PREALLOCATED) |
| 265 | && !segment_manager_app_detached (sm))) |
| 266 | { |
| 267 | clib_spinlock_unlock (&sm->lockp); |
| 268 | return; |
| 269 | } |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 270 | svm_fifo_segment_delete (fifo_segment); |
| 271 | vec_del1 (sm->segment_indices, segment_index); |
| 272 | clib_spinlock_unlock (&sm->lockp); |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Initiate disconnects for all sessions 'owned' by a segment manager |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 277 | */ |
| 278 | void |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 279 | segment_manager_del_sessions (segment_manager_t * sm) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 280 | { |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 281 | int j; |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 282 | svm_fifo_segment_private_t *fifo_segment; |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 283 | svm_fifo_t *fifo; |
| 284 | |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 285 | ASSERT (vec_len (sm->segment_indices)); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 286 | |
| 287 | /* Across all fifo segments used by the server */ |
| 288 | for (j = 0; j < vec_len (sm->segment_indices); j++) |
| 289 | { |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 290 | fifo_segment = svm_fifo_segment_get_segment (sm->segment_indices[j]); |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 291 | fifo = svm_fifo_segment_get_fifo_list (fifo_segment); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 292 | |
| 293 | /* |
| 294 | * Remove any residual sessions from the session lookup table |
| 295 | * Don't bother deleting the individual fifos, we're going to |
| 296 | * throw away the fifo segment in a minute. |
| 297 | */ |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 298 | while (fifo) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 299 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 300 | u32 session_index, thread_index; |
| 301 | stream_session_t *session; |
| 302 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 303 | session_index = fifo->master_session_index; |
| 304 | thread_index = fifo->master_thread_index; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 305 | session = session_get (session_index, thread_index); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 306 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 307 | /* Instead of directly removing the session call disconnect */ |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 308 | if (session->session_state != SESSION_STATE_CLOSED) |
| 309 | { |
| 310 | session->session_state = SESSION_STATE_CLOSED; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 311 | session_send_session_evt_to_thread (session_handle (session), |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 312 | FIFO_EVENT_DISCONNECT, |
| 313 | thread_index); |
| 314 | } |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 315 | fifo = fifo->next; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 318 | /* Instead of removing the segment, test when cleaning up disconnected |
| 319 | * sessions if the segment can be removed. |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 320 | */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 321 | } |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 322 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 323 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 324 | /** |
| 325 | * Removes segment manager. |
| 326 | * |
| 327 | * Since the fifos allocated in the segment keep backpointers to the sessions |
| 328 | * prior to removing the segment, we call session disconnect. This |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 329 | * subsequently propagates into transport. |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 330 | */ |
| 331 | void |
| 332 | segment_manager_del (segment_manager_t * sm) |
| 333 | { |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 334 | int i; |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 335 | |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 336 | ASSERT (!segment_manager_has_fifos (sm) |
| 337 | && segment_manager_app_detached (sm)); |
| 338 | |
| 339 | /* If we have empty preallocated segments that haven't been removed, remove |
| 340 | * them now. Apart from that, the first segment in the first segment manager |
| 341 | * is not removed when all fifos are removed. It can only be removed when |
| 342 | * the manager is explicitly deleted/detached by the app. */ |
| 343 | for (i = vec_len (sm->segment_indices) - 1; i >= 0; i--) |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 344 | { |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 345 | if (CLIB_DEBUG) |
| 346 | { |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 347 | svm_fifo_segment_private_t *segment; |
| 348 | segment = svm_fifo_segment_get_segment (sm->segment_indices[i]); |
| 349 | ASSERT (!svm_fifo_segment_has_fifos (segment)); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 350 | } |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 351 | segment_manager_del_segment (sm, i); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 352 | } |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 353 | clib_spinlock_free (&sm->lockp); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 354 | if (CLIB_DEBUG) |
| 355 | memset (sm, 0xfe, sizeof (*sm)); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 356 | pool_put (segment_managers, sm); |
| 357 | } |
| 358 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 359 | void |
| 360 | segment_manager_init_del (segment_manager_t * sm) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 361 | { |
Florin Coras | 4e4531e | 2017-11-06 23:27:56 -0800 | [diff] [blame] | 362 | segment_manager_app_detach (sm); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 363 | if (segment_manager_has_fifos (sm)) |
| 364 | segment_manager_del_sessions (sm); |
| 365 | else |
| 366 | { |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 367 | ASSERT (!sm->first_is_protected || segment_manager_app_detached (sm)); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 368 | segment_manager_del (sm); |
| 369 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | int |
| 373 | segment_manager_alloc_session_fifos (segment_manager_t * sm, |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 374 | svm_fifo_t ** rx_fifo, |
| 375 | svm_fifo_t ** tx_fifo, |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 376 | u32 * fifo_segment_index) |
| 377 | { |
| 378 | svm_fifo_segment_private_t *fifo_segment; |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 379 | segment_manager_properties_t *props; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 380 | u32 fifo_size, sm_index; |
| 381 | u8 added_a_segment = 0; |
| 382 | int i; |
| 383 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 384 | ASSERT (vec_len (sm->segment_indices)); |
| 385 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 386 | /* Make sure we don't have multiple threads trying to allocate segments |
| 387 | * at the same time. */ |
| 388 | clib_spinlock_lock (&sm->lockp); |
| 389 | |
| 390 | /* Allocate svm fifos */ |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 391 | props = segment_manager_properties_get (sm->properties_index); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 392 | again: |
| 393 | for (i = 0; i < vec_len (sm->segment_indices); i++) |
| 394 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 395 | *fifo_segment_index = vec_elt (sm->segment_indices, i); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 396 | fifo_segment = svm_fifo_segment_get_segment (*fifo_segment_index); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 397 | |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 398 | fifo_size = props->rx_fifo_size; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 399 | fifo_size = (fifo_size == 0) ? default_fifo_size : fifo_size; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 400 | *rx_fifo = svm_fifo_segment_alloc_fifo (fifo_segment, fifo_size, |
| 401 | FIFO_SEGMENT_RX_FREELIST); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 402 | |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 403 | fifo_size = props->tx_fifo_size; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 404 | fifo_size = (fifo_size == 0) ? default_fifo_size : fifo_size; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 405 | *tx_fifo = svm_fifo_segment_alloc_fifo (fifo_segment, fifo_size, |
| 406 | FIFO_SEGMENT_TX_FREELIST); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 407 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 408 | if (*rx_fifo == 0) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 409 | { |
| 410 | /* This would be very odd, but handle it... */ |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 411 | if (*tx_fifo != 0) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 412 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 413 | svm_fifo_segment_free_fifo (fifo_segment, *tx_fifo, |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 414 | FIFO_SEGMENT_TX_FREELIST); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 415 | *tx_fifo = 0; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 416 | } |
| 417 | continue; |
| 418 | } |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 419 | if (*tx_fifo == 0) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 420 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 421 | if (*rx_fifo != 0) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 422 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 423 | svm_fifo_segment_free_fifo (fifo_segment, *rx_fifo, |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 424 | FIFO_SEGMENT_RX_FREELIST); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 425 | *rx_fifo = 0; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 426 | } |
| 427 | continue; |
| 428 | } |
| 429 | break; |
| 430 | } |
| 431 | |
| 432 | /* See if we're supposed to create another segment */ |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 433 | if (*rx_fifo == 0) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 434 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 435 | if (props->add_segment && !props->segment_type) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 436 | { |
| 437 | if (added_a_segment) |
| 438 | { |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 439 | clib_warning ("added a segment, still can't allocate a fifo"); |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 440 | clib_spinlock_unlock (&sm->lockp); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 441 | return SESSION_ERROR_NEW_SEG_NO_SPACE; |
| 442 | } |
| 443 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 444 | if (segment_manager_add_segment (sm)) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 445 | { |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 446 | clib_spinlock_unlock (&sm->lockp); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 447 | return VNET_API_ERROR_URI_FIFO_CREATE_FAILED; |
| 448 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 449 | |
| 450 | added_a_segment = 1; |
| 451 | goto again; |
| 452 | } |
| 453 | else |
| 454 | { |
| 455 | clib_warning ("No space to allocate fifos!"); |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 456 | clib_spinlock_unlock (&sm->lockp); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 457 | return SESSION_ERROR_NO_SPACE; |
| 458 | } |
| 459 | } |
| 460 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 461 | /* Backpointers to segment manager */ |
| 462 | sm_index = segment_manager_index (sm); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 463 | (*tx_fifo)->segment_manager = sm_index; |
| 464 | (*rx_fifo)->segment_manager = sm_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 465 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 466 | clib_spinlock_unlock (&sm->lockp); |
| 467 | |
| 468 | if (added_a_segment) |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 469 | return application_add_segment_notify (sm->app_index, |
| 470 | *fifo_segment_index); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 471 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | void |
| 476 | segment_manager_dealloc_fifos (u32 svm_segment_index, svm_fifo_t * rx_fifo, |
| 477 | svm_fifo_t * tx_fifo) |
| 478 | { |
| 479 | segment_manager_t *sm; |
| 480 | svm_fifo_segment_private_t *fifo_segment; |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 481 | u32 i, segment_index = ~0; |
| 482 | u8 is_first; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 483 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 484 | sm = segment_manager_get_if_valid (rx_fifo->segment_manager); |
| 485 | |
| 486 | /* It's possible to have no segment manager if the session was removed |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 487 | * as result of a detach. */ |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 488 | if (!sm) |
| 489 | return; |
| 490 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 491 | fifo_segment = svm_fifo_segment_get_segment (svm_segment_index); |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 492 | svm_fifo_segment_free_fifo (fifo_segment, rx_fifo, |
| 493 | FIFO_SEGMENT_RX_FREELIST); |
| 494 | svm_fifo_segment_free_fifo (fifo_segment, tx_fifo, |
| 495 | FIFO_SEGMENT_TX_FREELIST); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 496 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 497 | /* |
| 498 | * Try to remove svm segment if it has no fifos. This can be done only if |
| 499 | * the segment is not the first in the segment manager or if it is first |
| 500 | * and it is not protected. Moreover, if the segment is first and the app |
| 501 | * has detached from the segment manager, remove the segment manager. |
| 502 | */ |
| 503 | if (!svm_fifo_segment_has_fifos (fifo_segment)) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 504 | { |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 505 | is_first = sm->segment_indices[0] == svm_segment_index; |
| 506 | |
| 507 | /* Remove segment if it holds no fifos or first but not protected */ |
| 508 | if (!is_first || !sm->first_is_protected) |
| 509 | { |
| 510 | /* Find the segment manager segment index */ |
| 511 | for (i = 0; i < vec_len (sm->segment_indices); i++) |
| 512 | if (sm->segment_indices[i] == svm_segment_index) |
| 513 | { |
| 514 | segment_index = i; |
| 515 | break; |
| 516 | } |
| 517 | ASSERT (segment_index != (u32) ~ 0); |
| 518 | segment_manager_del_segment (sm, segment_index); |
| 519 | } |
| 520 | |
| 521 | /* Remove segment manager if no sessions and detached from app */ |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 522 | if (segment_manager_app_detached (sm) |
| 523 | && !segment_manager_has_fifos (sm)) |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 524 | segment_manager_del (sm); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 528 | /** |
| 529 | * Allocates shm queue in the first segment |
| 530 | */ |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 531 | svm_queue_t * |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 532 | segment_manager_alloc_queue (segment_manager_t * sm, u32 queue_size) |
| 533 | { |
| 534 | ssvm_shared_header_t *sh; |
| 535 | svm_fifo_segment_private_t *segment; |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 536 | svm_queue_t *q; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 537 | void *oldheap; |
| 538 | |
| 539 | ASSERT (sm->segment_indices != 0); |
| 540 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 541 | segment = svm_fifo_segment_get_segment (sm->segment_indices[0]); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 542 | sh = segment->ssvm.sh; |
| 543 | |
| 544 | oldheap = ssvm_push_heap (sh); |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 545 | q = svm_queue_init (queue_size, |
| 546 | sizeof (session_fifo_event_t), 0 /* consumer pid */ , |
| 547 | 0 /* signal when queue non-empty */ ); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 548 | ssvm_pop_heap (oldheap); |
| 549 | return q; |
| 550 | } |
| 551 | |
| 552 | /** |
| 553 | * Frees shm queue allocated in the first segment |
| 554 | */ |
| 555 | void |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 556 | segment_manager_dealloc_queue (segment_manager_t * sm, svm_queue_t * q) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 557 | { |
| 558 | ssvm_shared_header_t *sh; |
| 559 | svm_fifo_segment_private_t *segment; |
| 560 | void *oldheap; |
| 561 | |
| 562 | ASSERT (sm->segment_indices != 0); |
| 563 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 564 | segment = svm_fifo_segment_get_segment (sm->segment_indices[0]); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 565 | sh = segment->ssvm.sh; |
| 566 | |
| 567 | oldheap = ssvm_push_heap (sh); |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 568 | svm_queue_free (q); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 569 | ssvm_pop_heap (oldheap); |
| 570 | } |
| 571 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 572 | static clib_error_t * |
| 573 | segment_manager_show_fn (vlib_main_t * vm, unformat_input_t * input, |
| 574 | vlib_cli_command_t * cmd) |
| 575 | { |
| 576 | svm_fifo_segment_private_t *segments, *seg; |
| 577 | segment_manager_t *sm; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 578 | u8 show_segments = 0, verbose = 0; |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 579 | uword address; |
| 580 | u64 size; |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 581 | u32 active_fifos; |
| 582 | u32 free_fifos; |
| 583 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 584 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 585 | { |
| 586 | if (unformat (input, "segments")) |
| 587 | show_segments = 1; |
| 588 | else if (unformat (input, "verbose")) |
| 589 | verbose = 1; |
| 590 | else |
| 591 | return clib_error_return (0, "unknown input `%U'", |
| 592 | format_unformat_error, input); |
| 593 | } |
| 594 | vlib_cli_output (vm, "%d segment managers allocated", |
| 595 | pool_elts (segment_managers)); |
| 596 | if (verbose && pool_elts (segment_managers)) |
| 597 | { |
| 598 | vlib_cli_output (vm, "%-10s%=15s%=12s", "Index", "App Index", |
| 599 | "Segments"); |
| 600 | |
| 601 | /* *INDENT-OFF* */ |
| 602 | pool_foreach (sm, segment_managers, ({ |
| 603 | vlib_cli_output (vm, "%-10d%=15d%=12d", segment_manager_index(sm), |
| 604 | sm->app_index, vec_len (sm->segment_indices)); |
| 605 | })); |
| 606 | /* *INDENT-ON* */ |
| 607 | |
| 608 | } |
| 609 | if (show_segments) |
| 610 | { |
| 611 | segments = svm_fifo_segment_segments_pool (); |
| 612 | vlib_cli_output (vm, "%d svm fifo segments allocated", |
| 613 | pool_elts (segments)); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 614 | vlib_cli_output (vm, "%-15s%10s%15s%15s%15s%15s", "Name", "Type", |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 615 | "HeapSize (M)", "ActiveFifos", "FreeFifos", "Address"); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 616 | |
| 617 | /* *INDENT-OFF* */ |
| 618 | pool_foreach (seg, segments, ({ |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 619 | svm_fifo_segment_info (seg, &address, &size); |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 620 | active_fifos = svm_fifo_segment_num_fifos (seg); |
| 621 | free_fifos = svm_fifo_segment_num_free_fifos (seg, ~0 /* size */); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 622 | vlib_cli_output (vm, "%-15v%10U%15llu%15u%15u%15llx", |
| 623 | ssvm_name (&seg->ssvm), format_svm_fifo_segment_type, |
| 624 | seg, size >> 20ULL, active_fifos, free_fifos, |
| 625 | address); |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 626 | if (verbose) |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 627 | vlib_cli_output (vm, "%U", format_svm_fifo_segment, seg, verbose); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 628 | })); |
| 629 | /* *INDENT-ON* */ |
| 630 | |
| 631 | } |
| 632 | return 0; |
| 633 | } |
| 634 | |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 635 | /* *INDENT-OFF* */ |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 636 | VLIB_CLI_COMMAND (segment_manager_show_command, static) = |
| 637 | { |
| 638 | .path = "show segment-manager", |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 639 | .short_help = "show segment-manager [segments][verbose]", |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 640 | .function = segment_manager_show_fn, |
| 641 | }; |
| 642 | /* *INDENT-ON* */ |
| 643 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 644 | /* |
| 645 | * fd.io coding-style-patch-verification: ON |
| 646 | * |
| 647 | * Local Variables: |
| 648 | * eval: (c-set-style "gnu") |
| 649 | * End: |
| 650 | */ |