FD.io VPP  v18.04-17-g3a0d853
Vector Packet Processing
segment_manager.c
Go to the documentation of this file.
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 
17 #include <vnet/session/session.h>
19 
21 
22 /**
23  * Counter used to build segment names
24  */
26 
27 /**
28  * Default fifo and segment size. TODO config.
29  */
30 static u32 default_fifo_size = 1 << 12;
31 static u32 default_segment_size = 1 << 20;
33 
36 {
37  return application_get_segment_manager_properties (sm->app_index);
38 }
39 
42 {
43  props->add_segment_size = default_segment_size;
44  props->rx_fifo_size = default_fifo_size;
45  props->tx_fifo_size = default_fifo_size;
46  props->evt_q_size = default_app_evt_queue_size;
47  return props;
48 }
49 
50 static u8
52 {
53  return (sm->app_index == SEGMENT_MANAGER_INVALID_APP_INDEX);
54 }
55 
56 void
58 {
59  sm->app_index = SEGMENT_MANAGER_INVALID_APP_INDEX;
60 }
61 
65 {
66  return (seg - sm->segments);
67 }
68 
69 /**
70  * Remove segment without lock
71  */
72 void
75 {
77 
78  if (ssvm_type (&fs->ssvm) != SSVM_SEGMENT_PRIVATE)
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
93 {
95  u8 is_prealloc;
96 
97  clib_rwlock_writer_lock (&sm->segments_rwlock);
98  fs = segment_manager_get_segment (sm, fs_index);
100  if (is_prealloc && !segment_manager_app_detached (sm))
101  {
102  clib_rwlock_writer_unlock (&sm->segments_rwlock);
103  return;
104  }
105 
107  clib_rwlock_writer_unlock (&sm->segments_rwlock);
108 }
109 
110 /**
111  * Reads a segment from the segment manager's pool without lock
112  */
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  */
128 {
129  clib_rwlock_reader_lock (&sm->segments_rwlock);
130  return pool_elt_at_index (sm->segments, segment_index);
131 }
132 
133 void
135 {
136  ASSERT (sm->segments_rwlock->n_readers > 0);
137  clib_rwlock_reader_unlock (&sm->segments_rwlock);
138 }
139 
140 void
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  */
152 int
154 {
156  u32 rnd_margin = 128 << 10, seg_index;
158  uword baseva = (u64) ~ 0, alloc_size;
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;
190  if (props->segment_type != SSVM_SEGMENT_PRIVATE)
191  {
192  seg_name = format (0, "%d-%d%c", getpid (), segment_name_counter++, 0);
193  alloc_size = segment_size + rnd_margin;
194  baseva = clib_valloc_alloc (&smm->va_allocator, alloc_size, 0);
195  if (!baseva)
196  {
197  clib_warning ("out of space for segments");
198  return -1;
199  }
200  }
201  else
202  seg_name = format (0, "%s%c", "process-private-segment", 0);
203 
204  seg->ssvm.ssvm_size = segment_size;
205  seg->ssvm.name = seg_name;
206  seg->ssvm.requested_va = baseva;
207 
208  if ((rv = ssvm_master_init (&seg->ssvm, props->segment_type)))
209  {
210  clib_warning ("svm_master_init ('%v', %u) failed", seg_name,
211  segment_size);
212 
213  if (props->segment_type != SSVM_SEGMENT_PRIVATE)
214  clib_valloc_free (&smm->va_allocator, baseva);
215  pool_put (sm->segments, seg);
216  return (rv);
217  }
218 
219  svm_fifo_segment_init (seg);
220 
221  /*
222  * Save segment index before dropping lock, if any held
223  */
224  seg_index = seg - sm->segments;
225 
226  if (vlib_num_workers ())
227  clib_rwlock_writer_unlock (&sm->segments_rwlock);
228 
229  return seg_index;
230 }
231 
234 {
236  segment_manager_t *sm;
237  pool_get (smm->segment_managers, sm);
238  memset (sm, 0, sizeof (*sm));
239  clib_rwlock_init (&sm->segments_rwlock);
240  return sm;
241 }
242 
243 /**
244  * Initializes segment manager based on options provided.
245  * Returns error if ssvm segment(s) allocation fails.
246  */
247 int
249  u32 prealloc_fifo_pairs)
250 {
251  u32 rx_fifo_size, tx_fifo_size, pair_size;
252  u32 rx_rounded_data_size, tx_rounded_data_size;
253  u64 approx_total_size, max_seg_size =
254  ((u64) 1 << 32) - clib_mem_get_page_size ();
257  u32 approx_segment_count;
258  int seg_index, i;
259 
260  props = segment_manager_properties_get (sm);
261  first_seg_size = clib_max (first_seg_size, default_segment_size);
262 
263  if (prealloc_fifo_pairs)
264  {
265  /* Figure out how many segments should be preallocated */
266  rx_rounded_data_size = (1 << (max_log2 (props->rx_fifo_size)));
267  tx_rounded_data_size = (1 << (max_log2 (props->tx_fifo_size)));
268 
269  rx_fifo_size = sizeof (svm_fifo_t) + rx_rounded_data_size;
270  tx_fifo_size = sizeof (svm_fifo_t) + tx_rounded_data_size;
271  pair_size = rx_fifo_size + tx_fifo_size;
272 
273  approx_total_size = (u64) prealloc_fifo_pairs *pair_size;
274  if (first_seg_size > approx_total_size)
275  max_seg_size = first_seg_size;
276  approx_segment_count = (approx_total_size + (max_seg_size - 1))
277  / max_seg_size;
278 
279  /* Allocate the segments */
280  for (i = 0; i < approx_segment_count + 1; i++)
281  {
282  seg_index = segment_manager_add_segment (sm, max_seg_size);
283  if (seg_index < 0)
284  {
285  clib_warning ("Failed to preallocate segment %d", i);
286  return seg_index;
287  }
288 
289  segment = segment_manager_get_segment (sm, seg_index);
290  if (i == 0)
291  sm->event_queue = segment_manager_alloc_queue (segment,
292  props->evt_q_size);
293 
295  props->rx_fifo_size,
296  props->tx_fifo_size,
297  &prealloc_fifo_pairs);
299  if (prealloc_fifo_pairs == 0)
300  break;
301  }
302  }
303  else
304  {
305  seg_index = segment_manager_add_segment (sm, first_seg_size);
306  if (seg_index)
307  {
308  clib_warning ("Failed to allocate segment");
309  return seg_index;
310  }
311  segment = segment_manager_get_segment (sm, seg_index);
312  sm->event_queue = segment_manager_alloc_queue (segment,
313  props->evt_q_size);
314  }
315 
316  return 0;
317 }
318 
319 u8
321 {
323  u8 first = 1;
324 
325  /* *INDENT-OFF* */
327  if (CLIB_DEBUG && !first && !svm_fifo_segment_has_fifos (seg)
329  {
330  clib_warning ("segment %d has no fifos!",
332  first = 0;
333  }
334  if (svm_fifo_segment_has_fifos (seg))
335  {
337  return 1;
338  }
339  }));
340  /* *INDENT-ON* */
341 
342  return 0;
343 }
344 
345 /**
346  * Initiate disconnects for all sessions 'owned' by a segment manager
347  */
348 void
350 {
351  svm_fifo_segment_private_t *fifo_segment;
352  stream_session_t *session;
353  svm_fifo_t *fifo;
354 
355  ASSERT (pool_elts (sm->segments) != 0);
356 
357  /* Across all fifo segments used by the server */
358  /* *INDENT-OFF* */
359  segment_manager_foreach_segment_w_lock (fifo_segment, sm, ({
360  fifo = svm_fifo_segment_get_fifo_list (fifo_segment);
361 
362  /*
363  * Remove any residual sessions from the session lookup table
364  * Don't bother deleting the individual fifos, we're going to
365  * throw away the fifo segment in a minute.
366  */
367  while (fifo)
368  {
369  if (fifo->master_thread_index == 255)
370  {
371  svm_fifo_t *next = fifo->next;
373  fifo->master_session_index);
374  fifo = next;
375  continue;
376  }
377  session = session_get (fifo->master_session_index,
378  fifo->master_thread_index);
379  stream_session_disconnect (session);
380  fifo = fifo->next;
381  }
382 
383  /* Instead of removing the segment, test when cleaning up disconnected
384  * sessions if the segment can be removed.
385  */
386  }));
387  /* *INDENT-ON* */
388 }
389 
390 /**
391  * Removes segment manager.
392  *
393  * Since the fifos allocated in the segment keep backpointers to the sessions
394  * prior to removing the segment, we call session disconnect. This
395  * subsequently propagates into transport.
396  */
397 void
399 {
401  svm_fifo_segment_private_t *fifo_segment;
402 
405 
406  /* If we have empty preallocated segments that haven't been removed, remove
407  * them now. Apart from that, the first segment in the first segment manager
408  * is not removed when all fifos are removed. It can only be removed when
409  * the manager is explicitly deleted/detached by the app. */
410  clib_rwlock_writer_lock (&sm->segments_rwlock);
411 
412  /* *INDENT-OFF* */
413  pool_foreach (fifo_segment, sm->segments, ({
414  segment_manager_del_segment (sm, fifo_segment);
415  }));
416  /* *INDENT-ON* */
417 
418  clib_rwlock_writer_unlock (&sm->segments_rwlock);
419 
420  clib_rwlock_free (&sm->segments_rwlock);
421  if (CLIB_DEBUG)
422  memset (sm, 0xfe, sizeof (*sm));
423  pool_put (smm->segment_managers, sm);
424 }
425 
426 void
428 {
430  if (segment_manager_has_fifos (sm))
432  else
433  {
434  ASSERT (!sm->first_is_protected || segment_manager_app_detached (sm));
435  segment_manager_del (sm);
436  }
437 }
438 
439 int
441  u32 rx_fifo_size, u32 tx_fifo_size,
442  svm_fifo_t ** rx_fifo, svm_fifo_t ** tx_fifo)
443 {
444  rx_fifo_size = clib_max (rx_fifo_size, default_fifo_size);
445  *rx_fifo = svm_fifo_segment_alloc_fifo (fifo_segment, rx_fifo_size,
447 
448  tx_fifo_size = clib_max (tx_fifo_size, default_fifo_size);
449  *tx_fifo = svm_fifo_segment_alloc_fifo (fifo_segment, tx_fifo_size,
451 
452  if (*rx_fifo == 0)
453  {
454  /* This would be very odd, but handle it... */
455  if (*tx_fifo != 0)
456  {
457  svm_fifo_segment_free_fifo (fifo_segment, *tx_fifo,
459  *tx_fifo = 0;
460  }
461  return -1;
462  }
463  if (*tx_fifo == 0)
464  {
465  if (*rx_fifo != 0)
466  {
467  svm_fifo_segment_free_fifo (fifo_segment, *rx_fifo,
469  *rx_fifo = 0;
470  }
471  return -1;
472  }
473 
474  return 0;
475 }
476 
477 int
479  svm_fifo_t ** rx_fifo,
480  svm_fifo_t ** tx_fifo,
481  u32 * fifo_segment_index)
482 {
483  svm_fifo_segment_private_t *fifo_segment = 0;
484  int alloc_fail = 1, rv = 0, new_fs_index;
486  u8 added_a_segment = 0;
487  u32 sm_index;
488 
489  props = segment_manager_properties_get (sm);
490 
491  /*
492  * Find the first free segment to allocate the fifos in
493  */
494 
495  /* *INDENT-OFF* */
496  segment_manager_foreach_segment_w_lock (fifo_segment, sm, ({
497  alloc_fail = segment_manager_try_alloc_fifos (fifo_segment,
498  props->rx_fifo_size,
499  props->tx_fifo_size,
500  rx_fifo, tx_fifo);
501  /* Exit with lock held, drop it after notifying app */
502  if (!alloc_fail)
503  goto alloc_success;
504  }));
505  /* *INDENT-ON* */
506 
507 alloc_check:
508 
509  if (!alloc_fail)
510  {
511 
512  alloc_success:
513 
514  ASSERT (rx_fifo && tx_fifo);
515  sm_index = segment_manager_index (sm);
516  (*tx_fifo)->segment_manager = sm_index;
517  (*rx_fifo)->segment_manager = sm_index;
518  *fifo_segment_index = segment_manager_segment_index (sm, fifo_segment);
519 
520  if (added_a_segment)
521  rv = application_add_segment_notify (sm->app_index,
522  &fifo_segment->ssvm);
523  /* Drop the lock after app is notified */
525  return rv;
526  }
527 
528  /*
529  * Allocation failed, see if we can add a new segment
530  */
531  if (props->add_segment)
532  {
533  if (added_a_segment)
534  {
535  clib_warning ("Added a segment, still can't allocate a fifo");
537  return SESSION_ERROR_NEW_SEG_NO_SPACE;
538  }
539  if ((new_fs_index = segment_manager_add_segment (sm, 0)) < 0)
540  {
541  clib_warning ("Failed to add new segment");
542  return SESSION_ERROR_SEG_CREATE;
543  }
544  fifo_segment = segment_manager_get_segment_w_lock (sm, new_fs_index);
545  alloc_fail = segment_manager_try_alloc_fifos (fifo_segment,
546  props->rx_fifo_size,
547  props->tx_fifo_size,
548  rx_fifo, tx_fifo);
549  added_a_segment = 1;
550  goto alloc_check;
551  }
552  else
553  {
554  clib_warning ("Can't add new seg and no space to allocate fifos!");
555  return SESSION_ERROR_NO_SPACE;
556  }
557 }
558 
559 void
560 segment_manager_dealloc_fifos (u32 segment_index, svm_fifo_t * rx_fifo,
561  svm_fifo_t * tx_fifo)
562 {
563  svm_fifo_segment_private_t *fifo_segment;
564  segment_manager_t *sm;
565 
566  /* It's possible to have no segment manager if the session was removed
567  * as result of a detach. */
568  if (!(sm = segment_manager_get_if_valid (rx_fifo->segment_manager)))
569  return;
570 
571  fifo_segment = segment_manager_get_segment_w_lock (sm, segment_index);
572  svm_fifo_segment_free_fifo (fifo_segment, rx_fifo,
574  svm_fifo_segment_free_fifo (fifo_segment, tx_fifo,
576 
577  /*
578  * Try to remove svm segment if it has no fifos. This can be done only if
579  * the segment is not the first in the segment manager or if it is first
580  * and it is not protected. Moreover, if the segment is first and the app
581  * has detached from the segment manager, remove the segment manager.
582  */
583  if (!svm_fifo_segment_has_fifos (fifo_segment))
584  {
586 
587  /* Remove segment if it holds no fifos or first but not protected */
588  if (segment_index != 0 || !sm->first_is_protected)
589  segment_manager_lock_and_del_segment (sm, segment_index);
590 
591  /* Remove segment manager if no sessions and detached from app */
593  && !segment_manager_has_fifos (sm))
594  segment_manager_del (sm);
595  }
596  else
598 }
599 
600 /**
601  * Allocates shm queue in the first segment
602  *
603  * Must be called with lock held
604  */
605 svm_queue_t *
607  u32 queue_size)
608 {
610  svm_queue_t *q;
611  void *oldheap;
612 
613  sh = segment->ssvm.sh;
614 
615  oldheap = ssvm_push_heap (sh);
616  q = svm_queue_init (queue_size, sizeof (session_fifo_event_t),
617  0 /* consumer pid */ ,
618  0 /* signal when queue non-empty */ );
619  ssvm_pop_heap (oldheap);
620  return q;
621 }
622 
623 /**
624  * Frees shm queue allocated in the first segment
625  */
626 void
628 {
631  void *oldheap;
632 
633  ASSERT (!pool_is_free_index (sm->segments, 0));
634 
635  segment = segment_manager_get_segment_w_lock (sm, 0);
636  sh = segment->ssvm.sh;
637 
638  oldheap = ssvm_push_heap (sh);
639  svm_queue_free (q);
640  ssvm_pop_heap (oldheap);
642 }
643 
644 /*
645  * Init segment vm address allocator
646  */
647 void
649 {
651  clib_valloc_chunk_t _ip, *ip = &_ip;
652 
653  ip->baseva = a->baseva;
654  ip->size = a->size;
655 
656  clib_valloc_init (&sm->va_allocator, ip, 1 /* lock */ );
657 }
658 
659 static clib_error_t *
661  vlib_cli_command_t * cmd)
662 {
665  segment_manager_t *sm;
666  u8 show_segments = 0, verbose = 0;
667  uword address;
668  u64 size;
669  u32 active_fifos;
670  u32 free_fifos;
671 
673  {
674  if (unformat (input, "segments"))
675  show_segments = 1;
676  else if (unformat (input, "verbose"))
677  verbose = 1;
678  else
679  return clib_error_return (0, "unknown input `%U'",
680  format_unformat_error, input);
681  }
682  vlib_cli_output (vm, "%d segment managers allocated",
683  pool_elts (smm->segment_managers));
684  if (verbose && pool_elts (smm->segment_managers))
685  {
686  vlib_cli_output (vm, "%-10s%=15s%=12s", "Index", "App Index",
687  "Segments");
688 
689  /* *INDENT-OFF* */
690  pool_foreach (sm, smm->segment_managers, ({
691  vlib_cli_output (vm, "%-10d%=15d%=12d", segment_manager_index(sm),
692  sm->app_index, pool_elts (sm->segments));
693  }));
694  /* *INDENT-ON* */
695 
696  }
697  if (show_segments)
698  {
699  vlib_cli_output (vm, "%-15s%15s%15s%15s%15s%15s", "Name", "Type",
700  "HeapSize (M)", "ActiveFifos", "FreeFifos", "Address");
701 
702  /* *INDENT-OFF* */
703  pool_foreach (sm, smm->segment_managers, ({
704  segment_manager_foreach_segment_w_lock (seg, sm, ({
705  svm_fifo_segment_info (seg, &address, &size);
706  active_fifos = svm_fifo_segment_num_fifos (seg);
707  free_fifos = svm_fifo_segment_num_free_fifos (seg, ~0 /* size */);
708  vlib_cli_output (vm, "%-15v%15U%15llu%15u%15u%15llx",
709  ssvm_name (&seg->ssvm), format_svm_fifo_segment_type,
710  seg, size >> 20ULL, active_fifos, free_fifos,
711  address);
712  if (verbose)
713  vlib_cli_output (vm, "%U", format_svm_fifo_segment, seg, verbose);
714  }));
715  }));
716  /* *INDENT-ON* */
717 
718  }
719  return 0;
720 }
721 
722 /* *INDENT-OFF* */
723 VLIB_CLI_COMMAND (segment_manager_show_command, static) =
724 {
725  .path = "show segment-manager",
726  .short_help = "show segment-manager [segments][verbose]",
727  .function = segment_manager_show_fn,
728 };
729 /* *INDENT-ON* */
730 
731 /*
732  * fd.io coding-style-patch-verification: ON
733  *
734  * Local Variables:
735  * eval: (c-set-style "gnu")
736  * End:
737  */
segment_manager_main_t segment_manager_main
static void clib_rwlock_reader_lock(clib_rwlock_t *p)
Definition: lock.h:139
u64 ssvm_size
Definition: ssvm.h:84
svm_queue_t * segment_manager_alloc_queue(svm_fifo_segment_private_t *segment, u32 queue_size)
Allocates shm queue in the first segment.
void segment_manager_segment_reader_unlock(segment_manager_t *sm)
uword requested_va
Definition: ssvm.h:87
static segment_manager_t * segment_manager_get_if_valid(u32 index)
a
Definition: bitmap.h:516
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
Definition: lock.h:177
struct _segment_manager_properties segment_manager_properties_t
segment_manager_properties_t * application_get_segment_manager_properties(u32 app_index)
Definition: application.c:802
static u32 default_segment_size
static void clib_rwlock_free(clib_rwlock_t *p)
Definition: lock.h:129
static u32 default_app_evt_queue_size
clib_valloc_main_t va_allocator
Virtual address allocator.
#define FIFO_SEGMENT_F_IS_PREALLOCATED
int i
ssvm_shared_header_t * sh
Definition: ssvm.h:83
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
void segment_manager_dealloc_fifos(u32 segment_index, svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
segment_manager_properties_t * segment_manager_properties_init(segment_manager_properties_t *props)
#define segment_manager_foreach_segment_w_lock(VAR, SM, BODY)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:227
void svm_fifo_segment_preallocate_fifo_pairs(svm_fifo_segment_private_t *s, u32 rx_fifo_size, u32 tx_fifo_size, u32 *n_fifo_pairs)
Pre-allocates fifo pairs in fifo segment.
segment_manager_t * segment_managers
Pool of segment managers.
int segment_manager_init(segment_manager_t *sm, u32 first_seg_size, u32 prealloc_fifo_pairs)
Initializes segment manager based on options provided.
void ssvm_delete(ssvm_private_t *ssvm)
Definition: ssvm.c:387
struct _svm_fifo svm_fifo_t
svm_queue_t * svm_queue_init(int nels, int elsize, int consumer_pid, int signal_when_queue_non_empty)
Definition: queue.c:51
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:440
static u8 segment_manager_app_detached(segment_manager_t *sm)
#define always_inline
Definition: clib.h:92
svm_fifo_segment_private_t * segment_manager_get_segment_w_lock(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager&#39;s pool and acquires reader lock.
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
Definition: ssvm.h:144
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned long u64
Definition: types.h:89
struct _stream_session_t stream_session_t
static void segment_manager_lock_and_del_segment(segment_manager_t *sm, u32 fs_index)
Removes segment after acquiring writer lock.
int ssvm_master_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
Definition: ssvm.c:375
static void ssvm_pop_heap(void *oldheap)
Definition: ssvm.h:152
segment_manager_t * segment_manager_new()
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
#define svm_fifo_segment_flags(_seg)
int application_add_segment_notify(u32 app_index, ssvm_private_t *fs)
Send an API message to the external app, to map new segment.
Definition: application.c:598
int segment_manager_alloc_session_fifos(segment_manager_t *sm, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo, u32 *fifo_segment_index)
static svm_fifo_t * svm_fifo_segment_get_fifo_list(svm_fifo_segment_private_t *fifo_segment)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:461
u32 size
static void clib_rwlock_init(clib_rwlock_t *p)
Definition: lock.h:122
static void clib_rwlock_reader_unlock(clib_rwlock_t *p)
Definition: lock.h:157
void segment_manager_app_detach(segment_manager_t *sm)
void segment_manager_dealloc_queue(segment_manager_t *sm, svm_queue_t *q)
Frees shm queue allocated in the first segment.
struct _unformat_input_t unformat_input_t
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:273
svm_fifo_segment_private_t * segment_manager_get_segment(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager&#39;s pool without lock.
u8 segment_manager_has_fifos(segment_manager_t *sm)
segment_manager_properties_t * segment_manager_properties_get(segment_manager_t *sm)
uword size
size in bytes of this chunk
Definition: valloc.h:33
void segment_manager_del_segment(segment_manager_t *sm, svm_fifo_segment_private_t *fs)
Remove segment without lock.
int segment_manager_add_segment(segment_manager_t *sm, u32 segment_size)
Adds segment to segment manager&#39;s pool.
static stream_session_t * session_get(u32 si, u32 thread_index)
Definition: session.h:241
uword baseva
base VA for this chunk
Definition: valloc.h:32
#define SEGMENT_MANAGER_INVALID_APP_INDEX
static u8 svm_fifo_segment_has_fifos(svm_fifo_segment_private_t *fifo_segment)
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
Definition: lock.h:185
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
vlib_main_t * vm
Definition: buffer.c:294
#define clib_warning(format, args...)
Definition: error.h:59
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:270
int application_local_session_disconnect_w_index(u32 app_index, u32 ls_index)
Definition: application.c:1160
int segment_manager_try_alloc_fifos(svm_fifo_segment_private_t *fifo_segment, u32 rx_fifo_size, u32 tx_fifo_size, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
static u32 segment_manager_index(segment_manager_t *sm)
void svm_queue_free(svm_queue_t *q)
Definition: queue.c:95
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
uword clib_valloc_alloc(clib_valloc_main_t *vam, uword size, int os_out_of_memory_on_failure)
Allocate virtual space.
Definition: valloc.c:151
void segment_manager_init_del(segment_manager_t *sm)
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
void segment_manager_main_init(segment_manager_main_init_args_t *a)
static u32 segment_manager_segment_index(segment_manager_t *sm, svm_fifo_segment_private_t *seg)
void stream_session_disconnect(stream_session_t *s)
Initialize session disconnect.
Definition: session.c:1018
void svm_fifo_segment_free_fifo(svm_fifo_segment_private_t *s, svm_fifo_t *f, svm_fifo_segment_freelist_t list_index)
#define clib_max(x, y)
Definition: clib.h:333
u8 * name
Definition: ssvm.h:86
u64 uword
Definition: types.h:112
void segment_manager_segment_writer_unlock(segment_manager_t *sm)
void segment_manager_del(segment_manager_t *sm)
Removes segment manager.
unsigned char u8
Definition: types.h:56
static uword max_log2(uword x)
Definition: clib.h:236
static u32 segment_name_counter
Counter used to build segment names.
void segment_manager_del_sessions(segment_manager_t *sm)
Initiate disconnects for all sessions &#39;owned&#39; by a segment manager.
uword clib_valloc_free(clib_valloc_main_t *vam, uword baseva)
Free virtual space.
Definition: valloc.c:228
struct _segment_manager segment_manager_t
struct _svm_queue svm_queue_t
int svm_fifo_segment_init(svm_fifo_segment_private_t *s)
Initialize svm fifo segment shared header.
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
void clib_valloc_init(clib_valloc_main_t *vam, clib_valloc_chunk_t *template, int need_lock)
Initialize a virtual memory allocation arena.
Definition: valloc.c:129
static u32 vlib_num_workers()
Definition: threads.h:368
static clib_error_t * segment_manager_show_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static u32 default_fifo_size
Default fifo and segment size.
uword clib_mem_get_page_size(void)
Definition: mem_mheap.c:110
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
svm_fifo_t * svm_fifo_segment_alloc_fifo(svm_fifo_segment_private_t *s, u32 data_size_in_bytes, svm_fifo_segment_freelist_t list_index)
Allocate fifo in svm segment.
ssvm_segment_type_t ssvm_type(const ssvm_private_t *ssvm)
Definition: ssvm.c:393
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128