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 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 20 | segment_manager_main_t segment_manager_main; |
| 21 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Counter used to build segment names |
| 24 | */ |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 25 | static u32 segment_name_counter = 0; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 28 | * Default fifo and segment size. TODO config. |
| 29 | */ |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 30 | static u32 default_fifo_size = 1 << 12; |
| 31 | static u32 default_segment_size = 1 << 20; |
| 32 | static u32 default_app_evt_queue_size = 128; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 33 | |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 34 | segment_manager_properties_t * |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 35 | segment_manager_properties_get (segment_manager_t * sm) |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 36 | { |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 37 | return application_get_segment_manager_properties (sm->app_index); |
| 38 | } |
| 39 | |
| 40 | segment_manager_properties_t * |
| 41 | segment_manager_properties_init (segment_manager_properties_t * props) |
| 42 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 43 | props->add_segment_size = default_segment_size; |
| 44 | props->rx_fifo_size = default_fifo_size; |
| 45 | props->tx_fifo_size = default_fifo_size; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 46 | props->evt_q_size = default_app_evt_queue_size; |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 47 | return props; |
| 48 | } |
| 49 | |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 50 | static u8 |
| 51 | segment_manager_app_detached (segment_manager_t * sm) |
| 52 | { |
| 53 | return (sm->app_index == SEGMENT_MANAGER_INVALID_APP_INDEX); |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 54 | } |
| 55 | |
Florin Coras | 4e4531e | 2017-11-06 23:27:56 -0800 | [diff] [blame] | 56 | void |
| 57 | segment_manager_app_detach (segment_manager_t * sm) |
| 58 | { |
| 59 | sm->app_index = SEGMENT_MANAGER_INVALID_APP_INDEX; |
| 60 | } |
| 61 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 62 | always_inline u32 |
| 63 | segment_manager_segment_index (segment_manager_t * sm, |
| 64 | svm_fifo_segment_private_t * seg) |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 65 | { |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 66 | return (seg - sm->segments); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Remove segment without lock |
| 71 | */ |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 72 | void |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 73 | segment_manager_del_segment (segment_manager_t * sm, |
| 74 | svm_fifo_segment_private_t * fs) |
| 75 | { |
| 76 | segment_manager_main_t *smm = &segment_manager_main; |
| 77 | |
| 78 | if (ssvm_type (&fs->ssvm) != SSVM_SEGMENT_PRIVATE) |
| 79 | clib_valloc_free (&smm->va_allocator, fs->ssvm.requested_va); |
| 80 | |
| 81 | ssvm_delete (&fs->ssvm); |
| 82 | |
| 83 | if (CLIB_DEBUG) |
| 84 | memset (fs, 0xfb, sizeof (*fs)); |
| 85 | pool_put (sm->segments, fs); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Removes segment after acquiring writer lock |
| 90 | */ |
| 91 | always_inline void |
| 92 | segment_manager_lock_and_del_segment (segment_manager_t * sm, u32 fs_index) |
| 93 | { |
| 94 | svm_fifo_segment_private_t *fs; |
| 95 | u8 is_prealloc; |
| 96 | |
| 97 | clib_rwlock_writer_lock (&sm->segments_rwlock); |
| 98 | fs = segment_manager_get_segment (sm, fs_index); |
| 99 | is_prealloc = svm_fifo_segment_flags (fs) & FIFO_SEGMENT_F_IS_PREALLOCATED; |
| 100 | if (is_prealloc && !segment_manager_app_detached (sm)) |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 101 | { |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 102 | clib_rwlock_writer_unlock (&sm->segments_rwlock); |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 103 | return; |
| 104 | } |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 105 | |
| 106 | segment_manager_del_segment (sm, fs); |
| 107 | clib_rwlock_writer_unlock (&sm->segments_rwlock); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Reads a segment from the segment manager's pool without lock |
| 112 | */ |
| 113 | svm_fifo_segment_private_t * |
| 114 | segment_manager_get_segment (segment_manager_t * sm, u32 segment_index) |
| 115 | { |
| 116 | return pool_elt_at_index (sm->segments, segment_index); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Reads a segment from the segment manager's pool and acquires reader lock |
| 121 | * |
| 122 | * Caller must drop the reader's lock by calling |
| 123 | * @ref segment_manager_segment_reader_unlock once it finishes working with |
| 124 | * the segment. |
| 125 | */ |
| 126 | svm_fifo_segment_private_t * |
| 127 | segment_manager_get_segment_w_lock (segment_manager_t * sm, u32 segment_index) |
| 128 | { |
| 129 | clib_rwlock_reader_lock (&sm->segments_rwlock); |
| 130 | return pool_elt_at_index (sm->segments, segment_index); |
| 131 | } |
| 132 | |
| 133 | void |
| 134 | segment_manager_segment_reader_unlock (segment_manager_t * sm) |
| 135 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 136 | ASSERT (sm->segments_rwlock->n_readers > 0); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 137 | clib_rwlock_reader_unlock (&sm->segments_rwlock); |
| 138 | } |
| 139 | |
| 140 | void |
| 141 | segment_manager_segment_writer_unlock (segment_manager_t * sm) |
| 142 | { |
| 143 | clib_rwlock_writer_unlock (&sm->segments_rwlock); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Adds segment to segment manager's pool |
| 148 | * |
| 149 | * If needed a writer's lock is acquired before allocating a new segment |
| 150 | * to avoid affecting any of the segments pool readers. |
| 151 | */ |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 152 | int |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 153 | segment_manager_add_segment (segment_manager_t * sm, u32 segment_size) |
| 154 | { |
| 155 | segment_manager_main_t *smm = &segment_manager_main; |
Florin Coras | 5da96a7 | 2018-07-12 01:45:13 -0700 | [diff] [blame] | 156 | u32 rnd_margin = 128 << 10, seg_index, page_size; |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 157 | segment_manager_properties_t *props; |
| 158 | uword baseva = (u64) ~ 0, alloc_size; |
| 159 | svm_fifo_segment_private_t *seg; |
| 160 | u8 *seg_name; |
| 161 | int rv; |
| 162 | |
| 163 | props = segment_manager_properties_get (sm); |
| 164 | |
| 165 | /* Not configured for addition of new segments and not first */ |
| 166 | if (!props->add_segment && !segment_size) |
| 167 | { |
| 168 | clib_warning ("cannot allocate new segment"); |
| 169 | return VNET_API_ERROR_INVALID_VALUE; |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * Allocate fifo segment and lock if needed |
| 174 | */ |
| 175 | if (vlib_num_workers ()) |
| 176 | { |
| 177 | clib_rwlock_writer_lock (&sm->segments_rwlock); |
| 178 | pool_get (sm->segments, seg); |
| 179 | } |
| 180 | else |
| 181 | { |
| 182 | pool_get (sm->segments, seg); |
| 183 | } |
| 184 | memset (seg, 0, sizeof (*seg)); |
| 185 | |
| 186 | /* |
| 187 | * Initialize ssvm segment and svm fifo private header |
| 188 | */ |
| 189 | segment_size = segment_size ? segment_size : props->add_segment_size; |
Florin Coras | 5da96a7 | 2018-07-12 01:45:13 -0700 | [diff] [blame] | 190 | page_size = clib_mem_get_page_size (); |
| 191 | segment_size = (segment_size + page_size - 1) & ~(page_size - 1); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 192 | if (props->segment_type != SSVM_SEGMENT_PRIVATE) |
| 193 | { |
| 194 | seg_name = format (0, "%d-%d%c", getpid (), segment_name_counter++, 0); |
| 195 | alloc_size = segment_size + rnd_margin; |
| 196 | baseva = clib_valloc_alloc (&smm->va_allocator, alloc_size, 0); |
| 197 | if (!baseva) |
| 198 | { |
| 199 | clib_warning ("out of space for segments"); |
| 200 | return -1; |
| 201 | } |
| 202 | } |
| 203 | else |
| 204 | seg_name = format (0, "%s%c", "process-private-segment", 0); |
| 205 | |
| 206 | seg->ssvm.ssvm_size = segment_size; |
| 207 | seg->ssvm.name = seg_name; |
| 208 | seg->ssvm.requested_va = baseva; |
| 209 | |
| 210 | if ((rv = ssvm_master_init (&seg->ssvm, props->segment_type))) |
| 211 | { |
| 212 | clib_warning ("svm_master_init ('%v', %u) failed", seg_name, |
| 213 | segment_size); |
| 214 | |
| 215 | if (props->segment_type != SSVM_SEGMENT_PRIVATE) |
| 216 | clib_valloc_free (&smm->va_allocator, baseva); |
| 217 | pool_put (sm->segments, seg); |
| 218 | return (rv); |
| 219 | } |
| 220 | |
| 221 | svm_fifo_segment_init (seg); |
| 222 | |
| 223 | /* |
| 224 | * Save segment index before dropping lock, if any held |
| 225 | */ |
| 226 | seg_index = seg - sm->segments; |
| 227 | |
| 228 | if (vlib_num_workers ()) |
| 229 | clib_rwlock_writer_unlock (&sm->segments_rwlock); |
| 230 | |
| 231 | return seg_index; |
| 232 | } |
| 233 | |
| 234 | segment_manager_t * |
| 235 | segment_manager_new () |
| 236 | { |
| 237 | segment_manager_main_t *smm = &segment_manager_main; |
| 238 | segment_manager_t *sm; |
| 239 | pool_get (smm->segment_managers, sm); |
| 240 | memset (sm, 0, sizeof (*sm)); |
| 241 | clib_rwlock_init (&sm->segments_rwlock); |
| 242 | return sm; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Initializes segment manager based on options provided. |
| 247 | * Returns error if ssvm segment(s) allocation fails. |
| 248 | */ |
| 249 | int |
| 250 | segment_manager_init (segment_manager_t * sm, u32 first_seg_size, |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 251 | u32 prealloc_fifo_pairs) |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 252 | { |
| 253 | u32 rx_fifo_size, tx_fifo_size, pair_size; |
| 254 | u32 rx_rounded_data_size, tx_rounded_data_size; |
| 255 | u64 approx_total_size, max_seg_size = |
| 256 | ((u64) 1 << 32) - clib_mem_get_page_size (); |
| 257 | segment_manager_properties_t *props; |
| 258 | svm_fifo_segment_private_t *segment; |
| 259 | u32 approx_segment_count; |
| 260 | int seg_index, i; |
| 261 | |
| 262 | props = segment_manager_properties_get (sm); |
| 263 | first_seg_size = clib_max (first_seg_size, default_segment_size); |
| 264 | |
| 265 | if (prealloc_fifo_pairs) |
| 266 | { |
| 267 | /* Figure out how many segments should be preallocated */ |
| 268 | rx_rounded_data_size = (1 << (max_log2 (props->rx_fifo_size))); |
| 269 | tx_rounded_data_size = (1 << (max_log2 (props->tx_fifo_size))); |
| 270 | |
| 271 | rx_fifo_size = sizeof (svm_fifo_t) + rx_rounded_data_size; |
| 272 | tx_fifo_size = sizeof (svm_fifo_t) + tx_rounded_data_size; |
| 273 | pair_size = rx_fifo_size + tx_fifo_size; |
| 274 | |
| 275 | approx_total_size = (u64) prealloc_fifo_pairs *pair_size; |
| 276 | if (first_seg_size > approx_total_size) |
| 277 | max_seg_size = first_seg_size; |
| 278 | approx_segment_count = (approx_total_size + (max_seg_size - 1)) |
| 279 | / max_seg_size; |
| 280 | |
| 281 | /* Allocate the segments */ |
| 282 | for (i = 0; i < approx_segment_count + 1; i++) |
| 283 | { |
| 284 | seg_index = segment_manager_add_segment (sm, max_seg_size); |
| 285 | if (seg_index < 0) |
| 286 | { |
| 287 | clib_warning ("Failed to preallocate segment %d", i); |
| 288 | return seg_index; |
| 289 | } |
| 290 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 291 | segment = segment_manager_get_segment (sm, seg_index); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 292 | if (i == 0) |
| 293 | sm->event_queue = segment_manager_alloc_queue (segment, |
| 294 | props->evt_q_size); |
| 295 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 296 | svm_fifo_segment_preallocate_fifo_pairs (segment, |
| 297 | props->rx_fifo_size, |
| 298 | props->tx_fifo_size, |
| 299 | &prealloc_fifo_pairs); |
| 300 | svm_fifo_segment_flags (segment) = FIFO_SEGMENT_F_IS_PREALLOCATED; |
| 301 | if (prealloc_fifo_pairs == 0) |
| 302 | break; |
| 303 | } |
| 304 | } |
| 305 | else |
| 306 | { |
| 307 | seg_index = segment_manager_add_segment (sm, first_seg_size); |
| 308 | if (seg_index) |
| 309 | { |
| 310 | clib_warning ("Failed to allocate segment"); |
| 311 | return seg_index; |
| 312 | } |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 313 | segment = segment_manager_get_segment (sm, seg_index); |
| 314 | sm->event_queue = segment_manager_alloc_queue (segment, |
| 315 | props->evt_q_size); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | u8 |
| 322 | segment_manager_has_fifos (segment_manager_t * sm) |
| 323 | { |
| 324 | svm_fifo_segment_private_t *seg; |
| 325 | u8 first = 1; |
| 326 | |
| 327 | /* *INDENT-OFF* */ |
| 328 | segment_manager_foreach_segment_w_lock (seg, sm, ({ |
| 329 | if (CLIB_DEBUG && !first && !svm_fifo_segment_has_fifos (seg) |
| 330 | && !(svm_fifo_segment_flags (seg) & FIFO_SEGMENT_F_IS_PREALLOCATED)) |
| 331 | { |
| 332 | clib_warning ("segment %d has no fifos!", |
| 333 | segment_manager_segment_index (sm, seg)); |
| 334 | first = 0; |
| 335 | } |
| 336 | if (svm_fifo_segment_has_fifos (seg)) |
| 337 | { |
| 338 | segment_manager_segment_reader_unlock (sm); |
| 339 | return 1; |
| 340 | } |
| 341 | })); |
| 342 | /* *INDENT-ON* */ |
| 343 | |
| 344 | return 0; |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Initiate disconnects for all sessions 'owned' by a segment manager |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 349 | */ |
| 350 | void |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 351 | segment_manager_del_sessions (segment_manager_t * sm) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 352 | { |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 353 | svm_fifo_segment_private_t *fifo_segment; |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 354 | stream_session_t *session; |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 355 | svm_fifo_t *fifo; |
| 356 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 357 | ASSERT (pool_elts (sm->segments) != 0); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 358 | |
| 359 | /* Across all fifo segments used by the server */ |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 360 | /* *INDENT-OFF* */ |
| 361 | segment_manager_foreach_segment_w_lock (fifo_segment, sm, ({ |
| 362 | fifo = svm_fifo_segment_get_fifo_list (fifo_segment); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 363 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 364 | /* |
| 365 | * Remove any residual sessions from the session lookup table |
| 366 | * Don't bother deleting the individual fifos, we're going to |
| 367 | * throw away the fifo segment in a minute. |
| 368 | */ |
| 369 | while (fifo) |
| 370 | { |
Florin Coras | f6647e0 | 2018-03-23 22:56:43 -0700 | [diff] [blame] | 371 | if (fifo->master_thread_index == 255) |
| 372 | { |
| 373 | svm_fifo_t *next = fifo->next; |
| 374 | application_local_session_disconnect_w_index (sm->app_index, |
| 375 | fifo->master_session_index); |
| 376 | fifo = next; |
| 377 | continue; |
| 378 | } |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 379 | session = session_get (fifo->master_session_index, |
| 380 | fifo->master_thread_index); |
| 381 | stream_session_disconnect (session); |
| 382 | fifo = fifo->next; |
| 383 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 384 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 385 | /* Instead of removing the segment, test when cleaning up disconnected |
| 386 | * sessions if the segment can be removed. |
| 387 | */ |
| 388 | })); |
| 389 | /* *INDENT-ON* */ |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 390 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 391 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 392 | /** |
| 393 | * Removes segment manager. |
| 394 | * |
| 395 | * Since the fifos allocated in the segment keep backpointers to the sessions |
| 396 | * prior to removing the segment, we call session disconnect. This |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 397 | * subsequently propagates into transport. |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 398 | */ |
| 399 | void |
| 400 | segment_manager_del (segment_manager_t * sm) |
| 401 | { |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 402 | segment_manager_main_t *smm = &segment_manager_main; |
| 403 | svm_fifo_segment_private_t *fifo_segment; |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 404 | |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 405 | ASSERT (!segment_manager_has_fifos (sm) |
| 406 | && segment_manager_app_detached (sm)); |
| 407 | |
| 408 | /* If we have empty preallocated segments that haven't been removed, remove |
| 409 | * them now. Apart from that, the first segment in the first segment manager |
| 410 | * is not removed when all fifos are removed. It can only be removed when |
| 411 | * the manager is explicitly deleted/detached by the app. */ |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 412 | clib_rwlock_writer_lock (&sm->segments_rwlock); |
| 413 | |
| 414 | /* *INDENT-OFF* */ |
| 415 | pool_foreach (fifo_segment, sm->segments, ({ |
| 416 | segment_manager_del_segment (sm, fifo_segment); |
| 417 | })); |
| 418 | /* *INDENT-ON* */ |
| 419 | |
| 420 | clib_rwlock_writer_unlock (&sm->segments_rwlock); |
| 421 | |
| 422 | clib_rwlock_free (&sm->segments_rwlock); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 423 | if (CLIB_DEBUG) |
| 424 | memset (sm, 0xfe, sizeof (*sm)); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 425 | pool_put (smm->segment_managers, sm); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 428 | void |
| 429 | segment_manager_init_del (segment_manager_t * sm) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 430 | { |
Florin Coras | 4e4531e | 2017-11-06 23:27:56 -0800 | [diff] [blame] | 431 | segment_manager_app_detach (sm); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 432 | if (segment_manager_has_fifos (sm)) |
| 433 | segment_manager_del_sessions (sm); |
| 434 | else |
| 435 | { |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 436 | ASSERT (!sm->first_is_protected || segment_manager_app_detached (sm)); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 437 | segment_manager_del (sm); |
| 438 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 441 | int |
| 442 | segment_manager_try_alloc_fifos (svm_fifo_segment_private_t * fifo_segment, |
| 443 | u32 rx_fifo_size, u32 tx_fifo_size, |
| 444 | svm_fifo_t ** rx_fifo, svm_fifo_t ** tx_fifo) |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 445 | { |
| 446 | rx_fifo_size = clib_max (rx_fifo_size, default_fifo_size); |
| 447 | *rx_fifo = svm_fifo_segment_alloc_fifo (fifo_segment, rx_fifo_size, |
| 448 | FIFO_SEGMENT_RX_FREELIST); |
| 449 | |
| 450 | tx_fifo_size = clib_max (tx_fifo_size, default_fifo_size); |
| 451 | *tx_fifo = svm_fifo_segment_alloc_fifo (fifo_segment, tx_fifo_size, |
| 452 | FIFO_SEGMENT_TX_FREELIST); |
| 453 | |
| 454 | if (*rx_fifo == 0) |
| 455 | { |
| 456 | /* This would be very odd, but handle it... */ |
| 457 | if (*tx_fifo != 0) |
| 458 | { |
| 459 | svm_fifo_segment_free_fifo (fifo_segment, *tx_fifo, |
| 460 | FIFO_SEGMENT_TX_FREELIST); |
| 461 | *tx_fifo = 0; |
| 462 | } |
| 463 | return -1; |
| 464 | } |
| 465 | if (*tx_fifo == 0) |
| 466 | { |
| 467 | if (*rx_fifo != 0) |
| 468 | { |
| 469 | svm_fifo_segment_free_fifo (fifo_segment, *rx_fifo, |
| 470 | FIFO_SEGMENT_RX_FREELIST); |
| 471 | *rx_fifo = 0; |
| 472 | } |
| 473 | return -1; |
| 474 | } |
| 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 479 | int |
| 480 | segment_manager_alloc_session_fifos (segment_manager_t * sm, |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 481 | svm_fifo_t ** rx_fifo, |
| 482 | svm_fifo_t ** tx_fifo, |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 483 | u32 * fifo_segment_index) |
| 484 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 485 | svm_fifo_segment_private_t *fifo_segment = 0; |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 486 | int alloc_fail = 1, rv = 0, new_fs_index; |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 487 | segment_manager_properties_t *props; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 488 | u8 added_a_segment = 0; |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 489 | u32 sm_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 490 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 491 | props = segment_manager_properties_get (sm); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 492 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 493 | /* |
| 494 | * Find the first free segment to allocate the fifos in |
| 495 | */ |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 496 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 497 | /* *INDENT-OFF* */ |
| 498 | segment_manager_foreach_segment_w_lock (fifo_segment, sm, ({ |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 499 | alloc_fail = segment_manager_try_alloc_fifos (fifo_segment, |
| 500 | props->rx_fifo_size, |
| 501 | props->tx_fifo_size, |
| 502 | rx_fifo, tx_fifo); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 503 | /* Exit with lock held, drop it after notifying app */ |
| 504 | if (!alloc_fail) |
| 505 | goto alloc_success; |
| 506 | })); |
| 507 | /* *INDENT-ON* */ |
| 508 | |
| 509 | alloc_check: |
| 510 | |
| 511 | if (!alloc_fail) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 512 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 513 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 514 | alloc_success: |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 515 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 516 | ASSERT (rx_fifo && tx_fifo); |
| 517 | sm_index = segment_manager_index (sm); |
| 518 | (*tx_fifo)->segment_manager = sm_index; |
| 519 | (*rx_fifo)->segment_manager = sm_index; |
| 520 | *fifo_segment_index = segment_manager_segment_index (sm, fifo_segment); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 521 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 522 | if (added_a_segment) |
| 523 | rv = application_add_segment_notify (sm->app_index, |
| 524 | &fifo_segment->ssvm); |
| 525 | /* Drop the lock after app is notified */ |
| 526 | segment_manager_segment_reader_unlock (sm); |
| 527 | return rv; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 530 | /* |
| 531 | * Allocation failed, see if we can add a new segment |
| 532 | */ |
| 533 | if (props->add_segment) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 534 | { |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 535 | if (added_a_segment) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 536 | { |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 537 | clib_warning ("Added a segment, still can't allocate a fifo"); |
| 538 | segment_manager_segment_reader_unlock (sm); |
| 539 | return SESSION_ERROR_NEW_SEG_NO_SPACE; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 540 | } |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 541 | if ((new_fs_index = segment_manager_add_segment (sm, 0)) < 0) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 542 | { |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 543 | clib_warning ("Failed to add new segment"); |
| 544 | return SESSION_ERROR_SEG_CREATE; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 545 | } |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 546 | fifo_segment = segment_manager_get_segment_w_lock (sm, new_fs_index); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 547 | alloc_fail = segment_manager_try_alloc_fifos (fifo_segment, |
| 548 | props->rx_fifo_size, |
| 549 | props->tx_fifo_size, |
| 550 | rx_fifo, tx_fifo); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 551 | added_a_segment = 1; |
| 552 | goto alloc_check; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 553 | } |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 554 | else |
| 555 | { |
| 556 | clib_warning ("Can't add new seg and no space to allocate fifos!"); |
| 557 | return SESSION_ERROR_NO_SPACE; |
| 558 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | void |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 562 | segment_manager_dealloc_fifos (u32 segment_index, svm_fifo_t * rx_fifo, |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 563 | svm_fifo_t * tx_fifo) |
| 564 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 565 | svm_fifo_segment_private_t *fifo_segment; |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 566 | segment_manager_t *sm; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 567 | |
| 568 | /* 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] | 569 | * as result of a detach. */ |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 570 | if (!(sm = segment_manager_get_if_valid (rx_fifo->segment_manager))) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 571 | return; |
| 572 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 573 | fifo_segment = segment_manager_get_segment_w_lock (sm, segment_index); |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 574 | svm_fifo_segment_free_fifo (fifo_segment, rx_fifo, |
| 575 | FIFO_SEGMENT_RX_FREELIST); |
| 576 | svm_fifo_segment_free_fifo (fifo_segment, tx_fifo, |
| 577 | FIFO_SEGMENT_TX_FREELIST); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 578 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 579 | /* |
| 580 | * Try to remove svm segment if it has no fifos. This can be done only if |
| 581 | * the segment is not the first in the segment manager or if it is first |
| 582 | * and it is not protected. Moreover, if the segment is first and the app |
| 583 | * has detached from the segment manager, remove the segment manager. |
| 584 | */ |
| 585 | if (!svm_fifo_segment_has_fifos (fifo_segment)) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 586 | { |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 587 | segment_manager_segment_reader_unlock (sm); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 588 | |
| 589 | /* Remove segment if it holds no fifos or first but not protected */ |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 590 | if (segment_index != 0 || !sm->first_is_protected) |
| 591 | segment_manager_lock_and_del_segment (sm, segment_index); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 592 | |
| 593 | /* Remove segment manager if no sessions and detached from app */ |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 594 | if (segment_manager_app_detached (sm) |
| 595 | && !segment_manager_has_fifos (sm)) |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 596 | segment_manager_del (sm); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 597 | } |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 598 | else |
| 599 | segment_manager_segment_reader_unlock (sm); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 602 | u32 |
| 603 | segment_manager_evt_q_expected_size (u32 q_len) |
| 604 | { |
| 605 | u32 fifo_evt_size, notif_q_size, q_hdrs; |
| 606 | u32 msg_q_sz, fifo_evt_ring_sz, session_ntf_ring_sz; |
| 607 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 608 | fifo_evt_size = 1 << max_log2 (sizeof (session_event_t)); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 609 | notif_q_size = clib_max (16, q_len >> 4); |
| 610 | |
| 611 | msg_q_sz = q_len * sizeof (svm_msg_q_msg_t); |
| 612 | fifo_evt_ring_sz = q_len * fifo_evt_size; |
| 613 | session_ntf_ring_sz = notif_q_size * 256; |
| 614 | q_hdrs = sizeof (svm_queue_t) + sizeof (svm_msg_q_t); |
| 615 | |
| 616 | return (msg_q_sz + fifo_evt_ring_sz + session_ntf_ring_sz + q_hdrs); |
| 617 | } |
| 618 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 619 | /** |
| 620 | * Allocates shm queue in the first segment |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 621 | * |
| 622 | * Must be called with lock held |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 623 | */ |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 624 | svm_msg_q_t * |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 625 | segment_manager_alloc_queue (svm_fifo_segment_private_t * segment, |
| 626 | u32 queue_size) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 627 | { |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 628 | u32 fifo_evt_size, session_evt_size = 256, notif_q_size; |
| 629 | svm_msg_q_cfg_t _cfg, *cfg = &_cfg; |
| 630 | svm_msg_q_t *q; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 631 | void *oldheap; |
| 632 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 633 | fifo_evt_size = sizeof (session_event_t); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 634 | notif_q_size = clib_max (16, queue_size >> 4); |
| 635 | /* *INDENT-OFF* */ |
| 636 | svm_msg_q_ring_cfg_t rc[SESSION_MQ_N_RINGS] = { |
| 637 | {queue_size, fifo_evt_size, 0}, |
| 638 | {notif_q_size, session_evt_size, 0} |
| 639 | }; |
| 640 | /* *INDENT-ON* */ |
| 641 | cfg->consumer_pid = 0; |
| 642 | cfg->n_rings = 2; |
| 643 | cfg->q_nitems = queue_size; |
| 644 | cfg->ring_cfgs = rc; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 645 | |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 646 | oldheap = ssvm_push_heap (segment->ssvm.sh); |
| 647 | q = svm_msg_q_alloc (cfg); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 648 | ssvm_pop_heap (oldheap); |
| 649 | return q; |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Frees shm queue allocated in the first segment |
| 654 | */ |
| 655 | void |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 656 | segment_manager_dealloc_queue (segment_manager_t * sm, svm_queue_t * q) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 657 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 658 | svm_fifo_segment_private_t *segment; |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 659 | ssvm_shared_header_t *sh; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 660 | void *oldheap; |
| 661 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 662 | ASSERT (!pool_is_free_index (sm->segments, 0)); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 663 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 664 | segment = segment_manager_get_segment_w_lock (sm, 0); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 665 | sh = segment->ssvm.sh; |
| 666 | |
| 667 | oldheap = ssvm_push_heap (sh); |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 668 | svm_queue_free (q); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 669 | ssvm_pop_heap (oldheap); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 670 | segment_manager_segment_reader_unlock (sm); |
| 671 | } |
| 672 | |
| 673 | /* |
| 674 | * Init segment vm address allocator |
| 675 | */ |
| 676 | void |
| 677 | segment_manager_main_init (segment_manager_main_init_args_t * a) |
| 678 | { |
| 679 | segment_manager_main_t *sm = &segment_manager_main; |
| 680 | clib_valloc_chunk_t _ip, *ip = &_ip; |
| 681 | |
| 682 | ip->baseva = a->baseva; |
| 683 | ip->size = a->size; |
| 684 | |
| 685 | clib_valloc_init (&sm->va_allocator, ip, 1 /* lock */ ); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 688 | static clib_error_t * |
| 689 | segment_manager_show_fn (vlib_main_t * vm, unformat_input_t * input, |
| 690 | vlib_cli_command_t * cmd) |
| 691 | { |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 692 | segment_manager_main_t *smm = &segment_manager_main; |
| 693 | svm_fifo_segment_private_t *seg; |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 694 | segment_manager_t *sm; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 695 | u8 show_segments = 0, verbose = 0; |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 696 | uword address; |
| 697 | u64 size; |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 698 | u32 active_fifos; |
| 699 | u32 free_fifos; |
| 700 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 701 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 702 | { |
| 703 | if (unformat (input, "segments")) |
| 704 | show_segments = 1; |
| 705 | else if (unformat (input, "verbose")) |
| 706 | verbose = 1; |
| 707 | else |
| 708 | return clib_error_return (0, "unknown input `%U'", |
| 709 | format_unformat_error, input); |
| 710 | } |
| 711 | vlib_cli_output (vm, "%d segment managers allocated", |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 712 | pool_elts (smm->segment_managers)); |
| 713 | if (verbose && pool_elts (smm->segment_managers)) |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 714 | { |
| 715 | vlib_cli_output (vm, "%-10s%=15s%=12s", "Index", "App Index", |
| 716 | "Segments"); |
| 717 | |
| 718 | /* *INDENT-OFF* */ |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 719 | pool_foreach (sm, smm->segment_managers, ({ |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 720 | vlib_cli_output (vm, "%-10d%=15d%=12d", segment_manager_index(sm), |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 721 | sm->app_index, pool_elts (sm->segments)); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 722 | })); |
| 723 | /* *INDENT-ON* */ |
| 724 | |
| 725 | } |
| 726 | if (show_segments) |
| 727 | { |
Florin Coras | 2f8d8fa | 2018-01-26 06:36:04 -0800 | [diff] [blame] | 728 | vlib_cli_output (vm, "%-15s%15s%15s%15s%15s%15s", "Name", "Type", |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 729 | "HeapSize (M)", "ActiveFifos", "FreeFifos", "Address"); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 730 | |
| 731 | /* *INDENT-OFF* */ |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 732 | pool_foreach (sm, smm->segment_managers, ({ |
| 733 | segment_manager_foreach_segment_w_lock (seg, sm, ({ |
| 734 | svm_fifo_segment_info (seg, &address, &size); |
| 735 | active_fifos = svm_fifo_segment_num_fifos (seg); |
| 736 | free_fifos = svm_fifo_segment_num_free_fifos (seg, ~0 /* size */); |
| 737 | vlib_cli_output (vm, "%-15v%15U%15llu%15u%15u%15llx", |
| 738 | ssvm_name (&seg->ssvm), format_svm_fifo_segment_type, |
| 739 | seg, size >> 20ULL, active_fifos, free_fifos, |
| 740 | address); |
| 741 | if (verbose) |
| 742 | vlib_cli_output (vm, "%U", format_svm_fifo_segment, seg, verbose); |
| 743 | })); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 744 | })); |
| 745 | /* *INDENT-ON* */ |
| 746 | |
| 747 | } |
| 748 | return 0; |
| 749 | } |
| 750 | |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 751 | /* *INDENT-OFF* */ |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 752 | VLIB_CLI_COMMAND (segment_manager_show_command, static) = |
| 753 | { |
| 754 | .path = "show segment-manager", |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 755 | .short_help = "show segment-manager [segments][verbose]", |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 756 | .function = segment_manager_show_fn, |
| 757 | }; |
| 758 | /* *INDENT-ON* */ |
| 759 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 760 | /* |
| 761 | * fd.io coding-style-patch-verification: ON |
| 762 | * |
| 763 | * Local Variables: |
| 764 | * eval: (c-set-style "gnu") |
| 765 | * End: |
| 766 | */ |