FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
segment_manager.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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  app_worker_t *app_wrk = app_worker_get (sm->app_wrk_index);
39 }
40 
43 {
44  props->add_segment_size = default_segment_size;
45  props->rx_fifo_size = default_fifo_size;
46  props->tx_fifo_size = default_fifo_size;
47  props->evt_q_size = default_app_evt_queue_size;
48  return props;
49 }
50 
51 static u8
53 {
54  return (sm->app_wrk_index == SEGMENT_MANAGER_INVALID_APP_INDEX);
55 }
56 
57 void
59 {
60  sm->app_wrk_index = SEGMENT_MANAGER_INVALID_APP_INDEX;
61 }
62 
66 {
67  return (seg - sm->segments);
68 }
69 
70 /**
71  * Remove segment without lock
72  */
73 void
76 {
78 
79  if (ssvm_type (&fs->ssvm) != SSVM_SEGMENT_PRIVATE)
80  {
82 
83  if (sm->app_wrk_index != SEGMENT_MANAGER_INVALID_APP_INDEX)
84  {
85  app_worker_t *app_wrk;
86  u64 segment_handle;
87  app_wrk = app_worker_get (sm->app_wrk_index);
88  segment_handle = segment_manager_segment_handle (sm, fs);
89  app_worker_del_segment_notify (app_wrk, segment_handle);
90  }
91  }
92 
93  ssvm_delete (&fs->ssvm);
94 
95  if (CLIB_DEBUG)
96  clib_memset (fs, 0xfb, sizeof (*fs));
97  pool_put (sm->segments, fs);
98 }
99 
100 /**
101  * Removes segment after acquiring writer lock
102  */
103 static inline void
105 {
107  u8 is_prealloc;
108 
109  clib_rwlock_writer_lock (&sm->segments_rwlock);
110  fs = segment_manager_get_segment (sm, fs_index);
112  if (is_prealloc && !segment_manager_app_detached (sm))
113  {
114  clib_rwlock_writer_unlock (&sm->segments_rwlock);
115  return;
116  }
117 
119  clib_rwlock_writer_unlock (&sm->segments_rwlock);
120 }
121 
122 /**
123  * Reads a segment from the segment manager's pool without lock
124  */
127 {
128  return pool_elt_at_index (sm->segments, segment_index);
129 }
130 
131 u64
133  svm_fifo_segment_private_t * segment)
134 {
135  u32 segment_index = segment_manager_segment_index (sm, segment);
136  return (((u64) segment_manager_index (sm) << 32) | segment_index);
137 }
138 
139 void
140 segment_manager_parse_segment_handle (u64 segment_handle, u32 * sm_index,
141  u32 * segment_index)
142 {
143  *sm_index = segment_handle >> 32;
144  *segment_index = segment_handle & 0xFFFFFFFF;
145 }
146 
149 {
150  u32 sm_index, segment_index;
151  segment_manager_t *sm;
152 
153  segment_manager_parse_segment_handle (segment_handle, &sm_index,
154  &segment_index);
155  sm = segment_manager_get (sm_index);
156  if (!sm || pool_is_free_index (sm->segments, segment_index))
157  return 0;
158  return pool_elt_at_index (sm->segments, segment_index);
159 }
160 
161 /**
162  * Reads a segment from the segment manager's pool and acquires reader lock
163  *
164  * Caller must drop the reader's lock by calling
165  * @ref segment_manager_segment_reader_unlock once it finishes working with
166  * the segment.
167  */
170 {
171  clib_rwlock_reader_lock (&sm->segments_rwlock);
172  return pool_elt_at_index (sm->segments, segment_index);
173 }
174 
175 void
177 {
178  ASSERT (sm->segments_rwlock->n_readers > 0);
179  clib_rwlock_reader_unlock (&sm->segments_rwlock);
180 }
181 
182 void
184 {
185  clib_rwlock_writer_unlock (&sm->segments_rwlock);
186 }
187 
188 /**
189  * Adds segment to segment manager's pool
190  *
191  * If needed a writer's lock is acquired before allocating a new segment
192  * to avoid affecting any of the segments pool readers.
193  */
194 int
196 {
198  u32 rnd_margin = 128 << 10, seg_index = ~0, page_size;
200  uword baseva = (uword) ~ 0ULL, alloc_size;
202  u8 *seg_name;
203  int rv;
204 
205  props = segment_manager_properties_get (sm);
206 
207  /* Not configured for addition of new segments and not first */
208  if (!props->add_segment && !segment_size)
209  {
210  clib_warning ("cannot allocate new segment");
211  return VNET_API_ERROR_INVALID_VALUE;
212  }
213 
214  /*
215  * Allocate fifo segment and lock if needed
216  */
217  if (vlib_num_workers ())
218  clib_rwlock_writer_lock (&sm->segments_rwlock);
219 
220  pool_get_zero (sm->segments, seg);
221 
222  /*
223  * Initialize ssvm segment and svm fifo private header
224  */
225  segment_size = segment_size ? segment_size : props->add_segment_size;
226  page_size = clib_mem_get_page_size ();
227  /* Protect against segment size u32 wrap */
228  segment_size = clib_max (segment_size + page_size - 1, segment_size);
229  segment_size = segment_size & ~(page_size - 1);
230  if (props->segment_type != SSVM_SEGMENT_PRIVATE)
231  {
232  seg_name = format (0, "%d-%d%c", getpid (), segment_name_counter++, 0);
233  alloc_size = (uword) segment_size + rnd_margin;
234  baseva = clib_valloc_alloc (&smm->va_allocator, alloc_size, 0);
235  if (!baseva)
236  {
237  clib_warning ("out of space for segments");
238  pool_put (sm->segments, seg);
239  goto done;
240  }
241  }
242  else
243  seg_name = format (0, "%s%c", "process-private-segment", 0);
244 
245  seg->ssvm.ssvm_size = segment_size;
246  seg->ssvm.name = seg_name;
247  seg->ssvm.requested_va = baseva;
248 
249  if ((rv = ssvm_master_init (&seg->ssvm, props->segment_type)))
250  {
251  clib_warning ("svm_master_init ('%v', %u) failed", seg_name,
252  segment_size);
253 
254  if (props->segment_type != SSVM_SEGMENT_PRIVATE)
255  clib_valloc_free (&smm->va_allocator, baseva);
256  pool_put (sm->segments, seg);
257  goto done;
258  }
259 
260  svm_fifo_segment_init (seg);
261 
262  /*
263  * Save segment index before dropping lock, if any held
264  */
265  seg_index = seg - sm->segments;
266 
267 done:
268 
269  if (vlib_num_workers ())
270  clib_rwlock_writer_unlock (&sm->segments_rwlock);
271 
272  return seg_index;
273 }
274 
277 {
279  segment_manager_t *sm;
280  pool_get (smm->segment_managers, sm);
281  clib_memset (sm, 0, sizeof (*sm));
282  clib_rwlock_init (&sm->segments_rwlock);
283  return sm;
284 }
285 
286 /**
287  * Initializes segment manager based on options provided.
288  * Returns error if ssvm segment(s) allocation fails.
289  */
290 int
292  u32 prealloc_fifo_pairs)
293 {
294  u32 rx_fifo_size, tx_fifo_size, pair_size;
295  u32 rx_rounded_data_size, tx_rounded_data_size;
296  u64 approx_total_size, max_seg_size = ((u64) 1 << 32) - (128 << 10);
299  u32 approx_segment_count;
300  int seg_index, i;
301 
302  props = segment_manager_properties_get (sm);
303  first_seg_size = clib_max (first_seg_size, default_segment_size);
304 
305  if (prealloc_fifo_pairs)
306  {
307  /* Figure out how many segments should be preallocated */
308  rx_rounded_data_size = (1 << (max_log2 (props->rx_fifo_size)));
309  tx_rounded_data_size = (1 << (max_log2 (props->tx_fifo_size)));
310 
311  rx_fifo_size = sizeof (svm_fifo_t) + rx_rounded_data_size;
312  tx_fifo_size = sizeof (svm_fifo_t) + tx_rounded_data_size;
313  pair_size = rx_fifo_size + tx_fifo_size;
314 
315  approx_total_size = (u64) prealloc_fifo_pairs *pair_size;
316  if (first_seg_size > approx_total_size)
317  max_seg_size = first_seg_size;
318  approx_segment_count = (approx_total_size + (max_seg_size - 1))
319  / max_seg_size;
320 
321  /* Allocate the segments */
322  for (i = 0; i < approx_segment_count + 1; i++)
323  {
324  seg_index = segment_manager_add_segment (sm, max_seg_size);
325  if (seg_index < 0)
326  {
327  clib_warning ("Failed to preallocate segment %d", i);
328  return seg_index;
329  }
330 
331  segment = segment_manager_get_segment (sm, seg_index);
332  if (i == 0)
333  sm->event_queue = segment_manager_alloc_queue (segment, props);
334 
336  props->rx_fifo_size,
337  props->tx_fifo_size,
338  &prealloc_fifo_pairs);
340  if (prealloc_fifo_pairs == 0)
341  break;
342  }
343  }
344  else
345  {
346  seg_index = segment_manager_add_segment (sm, first_seg_size);
347  if (seg_index)
348  {
349  clib_warning ("Failed to allocate segment");
350  return seg_index;
351  }
352  segment = segment_manager_get_segment (sm, seg_index);
353  sm->event_queue = segment_manager_alloc_queue (segment, props);
354  }
355 
356  return 0;
357 }
358 
359 u8
361 {
363  u8 first = 1;
364 
365  /* *INDENT-OFF* */
367  if (CLIB_DEBUG && !first && !svm_fifo_segment_has_fifos (seg)
369  {
370  clib_warning ("segment %d has no fifos!",
372  first = 0;
373  }
374  if (svm_fifo_segment_has_fifos (seg))
375  {
377  return 1;
378  }
379  }));
380  /* *INDENT-ON* */
381 
382  return 0;
383 }
384 
385 /**
386  * Initiate disconnects for all sessions 'owned' by a segment manager
387  */
388 void
390 {
391  svm_fifo_segment_private_t *fifo_segment;
392  session_handle_t *handles = 0, *handle;
393  session_t *session;
394  svm_fifo_t *fifo;
395 
396  ASSERT (pool_elts (sm->segments) != 0);
397 
398  /* Across all fifo segments used by the server */
399  /* *INDENT-OFF* */
400  segment_manager_foreach_segment_w_lock (fifo_segment, sm, ({
401  fifo = svm_fifo_segment_get_fifo_list (fifo_segment);
402 
403  /*
404  * Remove any residual sessions from the session lookup table
405  * Don't bother deleting the individual fifos, we're going to
406  * throw away the fifo segment in a minute.
407  */
408  while (fifo)
409  {
410  session = session_get_if_valid (fifo->master_session_index,
411  fifo->master_thread_index);
412  if (session)
413  vec_add1 (handles, session_handle (session));
414  fifo = fifo->next;
415  }
416 
417  /* Instead of removing the segment, test when cleaning up disconnected
418  * sessions if the segment can be removed.
419  */
420  }));
421  /* *INDENT-ON* */
422 
423  vec_foreach (handle, handles)
425 }
426 
427 /**
428  * Removes segment manager.
429  *
430  * Since the fifos allocated in the segment keep backpointers to the sessions
431  * prior to removing the segment, we call session disconnect. This
432  * subsequently propagates into transport.
433  */
434 void
436 {
438  svm_fifo_segment_private_t *fifo_segment;
439 
442 
443  /* If we have empty preallocated segments that haven't been removed, remove
444  * them now. Apart from that, the first segment in the first segment manager
445  * is not removed when all fifos are removed. It can only be removed when
446  * the manager is explicitly deleted/detached by the app. */
447  clib_rwlock_writer_lock (&sm->segments_rwlock);
448 
449  /* *INDENT-OFF* */
450  pool_foreach (fifo_segment, sm->segments, ({
451  segment_manager_del_segment (sm, fifo_segment);
452  }));
453  /* *INDENT-ON* */
454 
455  clib_rwlock_writer_unlock (&sm->segments_rwlock);
456 
457  clib_rwlock_free (&sm->segments_rwlock);
458  if (CLIB_DEBUG)
459  clib_memset (sm, 0xfe, sizeof (*sm));
460  pool_put (smm->segment_managers, sm);
461 }
462 
463 void
465 {
467  if (segment_manager_has_fifos (sm))
469  else
470  {
471  ASSERT (!sm->first_is_protected || segment_manager_app_detached (sm));
472  segment_manager_del (sm);
473  }
474 }
475 
476 int
478  u32 rx_fifo_size, u32 tx_fifo_size,
479  svm_fifo_t ** rx_fifo, svm_fifo_t ** tx_fifo)
480 {
481  rx_fifo_size = clib_max (rx_fifo_size, default_fifo_size);
482  *rx_fifo = svm_fifo_segment_alloc_fifo (fifo_segment, rx_fifo_size,
484 
485  tx_fifo_size = clib_max (tx_fifo_size, default_fifo_size);
486  *tx_fifo = svm_fifo_segment_alloc_fifo (fifo_segment, tx_fifo_size,
488 
489  if (*rx_fifo == 0)
490  {
491  /* This would be very odd, but handle it... */
492  if (*tx_fifo != 0)
493  {
494  svm_fifo_segment_free_fifo (fifo_segment, *tx_fifo,
496  *tx_fifo = 0;
497  }
498  return -1;
499  }
500  if (*tx_fifo == 0)
501  {
502  if (*rx_fifo != 0)
503  {
504  svm_fifo_segment_free_fifo (fifo_segment, *rx_fifo,
506  *rx_fifo = 0;
507  }
508  return -1;
509  }
510 
511  return 0;
512 }
513 
514 int
516  svm_fifo_t ** rx_fifo,
517  svm_fifo_t ** tx_fifo,
518  u32 * fifo_segment_index)
519 {
520  svm_fifo_segment_private_t *fifo_segment = 0;
521  int alloc_fail = 1, rv = 0, new_fs_index;
523  u8 added_a_segment = 0;
524  u64 segment_handle;
525  u32 sm_index;
526 
527  props = segment_manager_properties_get (sm);
528 
529  /*
530  * Find the first free segment to allocate the fifos in
531  */
532 
533  /* *INDENT-OFF* */
534  segment_manager_foreach_segment_w_lock (fifo_segment, sm, ({
535  alloc_fail = segment_manager_try_alloc_fifos (fifo_segment,
536  props->rx_fifo_size,
537  props->tx_fifo_size,
538  rx_fifo, tx_fifo);
539  /* Exit with lock held, drop it after notifying app */
540  if (!alloc_fail)
541  goto alloc_success;
542  }));
543  /* *INDENT-ON* */
544 
545 alloc_check:
546 
547  if (!alloc_fail)
548  {
549 
550  alloc_success:
551 
552  ASSERT (rx_fifo && tx_fifo);
553  sm_index = segment_manager_index (sm);
554  *fifo_segment_index = segment_manager_segment_index (sm, fifo_segment);
555  (*tx_fifo)->segment_manager = sm_index;
556  (*rx_fifo)->segment_manager = sm_index;
557  (*tx_fifo)->segment_index = *fifo_segment_index;
558  (*rx_fifo)->segment_index = *fifo_segment_index;
559 
560  if (added_a_segment)
561  {
562  app_worker_t *app_wrk;
563  segment_handle = segment_manager_segment_handle (sm, fifo_segment);
564  app_wrk = app_worker_get (sm->app_wrk_index);
565  rv = app_worker_add_segment_notify (app_wrk, segment_handle);
566  }
567  /* Drop the lock after app is notified */
569  return rv;
570  }
571 
572  /*
573  * Allocation failed, see if we can add a new segment
574  */
575  if (props->add_segment)
576  {
577  if (added_a_segment)
578  {
579  clib_warning ("Added a segment, still can't allocate a fifo");
581  return SESSION_ERROR_NEW_SEG_NO_SPACE;
582  }
583  if ((new_fs_index = segment_manager_add_segment (sm, 0)) < 0)
584  {
585  clib_warning ("Failed to add new segment");
586  return SESSION_ERROR_SEG_CREATE;
587  }
588  fifo_segment = segment_manager_get_segment_w_lock (sm, new_fs_index);
589  alloc_fail = segment_manager_try_alloc_fifos (fifo_segment,
590  props->rx_fifo_size,
591  props->tx_fifo_size,
592  rx_fifo, tx_fifo);
593  added_a_segment = 1;
594  goto alloc_check;
595  }
596  else
597  {
598  clib_warning ("Can't add new seg and no space to allocate fifos!");
599  return SESSION_ERROR_NO_SPACE;
600  }
601 }
602 
603 void
605 {
606  svm_fifo_segment_private_t *fifo_segment;
607  segment_manager_t *sm;
608  u32 segment_index;
609 
610  if (!rx_fifo || !tx_fifo)
611  return;
612 
613  /* It's possible to have no segment manager if the session was removed
614  * as result of a detach. */
615  if (!(sm = segment_manager_get_if_valid (rx_fifo->segment_manager)))
616  return;
617 
618  segment_index = rx_fifo->segment_index;
619  fifo_segment = segment_manager_get_segment_w_lock (sm, segment_index);
620  svm_fifo_segment_free_fifo (fifo_segment, rx_fifo,
622  svm_fifo_segment_free_fifo (fifo_segment, tx_fifo,
624 
625  /*
626  * Try to remove svm segment if it has no fifos. This can be done only if
627  * the segment is not the first in the segment manager or if it is first
628  * and it is not protected. Moreover, if the segment is first and the app
629  * has detached from the segment manager, remove the segment manager.
630  */
631  if (!svm_fifo_segment_has_fifos (fifo_segment))
632  {
634 
635  /* Remove segment if it holds no fifos or first but not protected */
636  if (segment_index != 0 || !sm->first_is_protected)
637  segment_manager_lock_and_del_segment (sm, segment_index);
638 
639  /* Remove segment manager if no sessions and detached from app */
641  && !segment_manager_has_fifos (sm))
642  {
643  segment_manager_del (sm);
644  }
645  }
646  else
648 }
649 
650 u32
652 {
653  u32 fifo_evt_size, notif_q_size, q_hdrs;
654  u32 msg_q_sz, fifo_evt_ring_sz, session_ntf_ring_sz;
655 
656  fifo_evt_size = 1 << max_log2 (sizeof (session_event_t));
657  notif_q_size = clib_max (16, q_len >> 4);
658 
659  msg_q_sz = q_len * sizeof (svm_msg_q_msg_t);
660  fifo_evt_ring_sz = q_len * fifo_evt_size;
661  session_ntf_ring_sz = notif_q_size * 256;
662  q_hdrs = sizeof (svm_queue_t) + sizeof (svm_msg_q_t);
663 
664  return (msg_q_sz + fifo_evt_ring_sz + session_ntf_ring_sz + q_hdrs);
665 }
666 
667 /**
668  * Allocates shm queue in the first segment
669  *
670  * Must be called with lock held
671  */
672 svm_msg_q_t *
675 {
676  u32 fifo_evt_size, session_evt_size = 256, notif_q_size;
677  svm_msg_q_cfg_t _cfg, *cfg = &_cfg;
678  svm_msg_q_t *q;
679  void *oldheap;
680 
681  fifo_evt_size = sizeof (session_event_t);
682  notif_q_size = clib_max (16, props->evt_q_size >> 4);
683  /* *INDENT-OFF* */
685  {props->evt_q_size, fifo_evt_size, 0},
686  {notif_q_size, session_evt_size, 0}
687  };
688  /* *INDENT-ON* */
689  cfg->consumer_pid = 0;
690  cfg->n_rings = 2;
691  cfg->q_nitems = props->evt_q_size;
692  cfg->ring_cfgs = rc;
693 
694  oldheap = ssvm_push_heap (segment->ssvm.sh);
695  q = svm_msg_q_alloc (cfg);
696  ssvm_pop_heap (oldheap);
697 
698  if (props->use_mq_eventfd)
699  {
701  clib_warning ("failed to alloc eventfd");
702  }
703  return q;
704 }
705 
706 /**
707  * Frees shm queue allocated in the first segment
708  */
709 void
711 {
714  void *oldheap;
715 
716  ASSERT (!pool_is_free_index (sm->segments, 0));
717 
718  segment = segment_manager_get_segment_w_lock (sm, 0);
719  sh = segment->ssvm.sh;
720 
721  oldheap = ssvm_push_heap (sh);
722  svm_queue_free (q);
723  ssvm_pop_heap (oldheap);
725 }
726 
727 /*
728  * Init segment vm address allocator
729  */
730 void
732 {
734  clib_valloc_chunk_t _ip, *ip = &_ip;
735 
736  ip->baseva = a->baseva;
737  ip->size = a->size;
738 
739  clib_valloc_init (&sm->va_allocator, ip, 1 /* lock */ );
740 }
741 
742 static clib_error_t *
744  vlib_cli_command_t * cmd)
745 {
748  segment_manager_t *sm;
749  u8 show_segments = 0, verbose = 0;
750  char *address;
751  size_t size;
752  u32 active_fifos;
753  u32 free_fifos;
754 
756  {
757  if (unformat (input, "segments"))
758  show_segments = 1;
759  else if (unformat (input, "verbose"))
760  verbose = 1;
761  else
762  return clib_error_return (0, "unknown input `%U'",
763  format_unformat_error, input);
764  }
765  vlib_cli_output (vm, "%d segment managers allocated",
766  pool_elts (smm->segment_managers));
767  if (verbose && pool_elts (smm->segment_managers))
768  {
769  vlib_cli_output (vm, "%-10s%=15s%=12s", "Index", "App Index",
770  "Segments");
771 
772  /* *INDENT-OFF* */
773  pool_foreach (sm, smm->segment_managers, ({
774  vlib_cli_output (vm, "%-10d%=15d%=12d", segment_manager_index (sm),
775  sm->app_wrk_index, pool_elts (sm->segments));
776  }));
777  /* *INDENT-ON* */
778 
779  }
780  if (show_segments)
781  {
782  vlib_cli_output (vm, "%-15s%15s%15s%15s%15s%15s", "Name", "Type",
783  "HeapSize (M)", "ActiveFifos", "FreeFifos", "Address");
784 
785  /* *INDENT-OFF* */
786  pool_foreach (sm, smm->segment_managers, ({
787  segment_manager_foreach_segment_w_lock (seg, sm, ({
788  svm_fifo_segment_info (seg, &address, &size);
789  active_fifos = svm_fifo_segment_num_fifos (seg);
790  free_fifos = svm_fifo_segment_num_free_fifos (seg, ~0 /* size */);
791  vlib_cli_output (vm, "%-15v%15U%15llu%15u%15u%15llx",
792  ssvm_name (&seg->ssvm), format_svm_fifo_segment_type,
793  seg, size >> 20ULL, active_fifos, free_fifos,
794  address);
795  if (verbose)
796  vlib_cli_output (vm, "%U", format_svm_fifo_segment, seg, verbose);
797  }));
798  }));
799  /* *INDENT-ON* */
800 
801  }
802  return 0;
803 }
804 
805 /* *INDENT-OFF* */
806 VLIB_CLI_COMMAND (segment_manager_show_command, static) =
807 {
808  .path = "show segment-manager",
809  .short_help = "show segment-manager [segments][verbose]",
810  .function = segment_manager_show_fn,
811 };
812 /* *INDENT-ON* */
813 
814 /*
815  * fd.io coding-style-patch-verification: ON
816  *
817  * Local Variables:
818  * eval: (c-set-style "gnu")
819  * End:
820  */
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
typedef address
Definition: ip_types.api:30
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:538
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
Definition: lock.h:177
struct _segment_manager_properties segment_manager_properties_t
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:239
segment_manager_properties_t * application_get_segment_manager_properties(u32 app_index)
Definition: application.c:1323
unsigned long u64
Definition: types.h:89
static u32 default_segment_size
svm_fifo_segment_private_t * segment_manager_get_segment_w_handle(u64 segment_handle)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
svm_msg_q_t * segment_manager_alloc_queue(svm_fifo_segment_private_t *segment, segment_manager_properties_t *props)
Allocates shm queue in the first segment.
static void clib_rwlock_free(clib_rwlock_t *p)
Definition: lock.h:129
static session_t * session_get_if_valid(u64 si, u32 thread_index)
Definition: session.h:214
static u32 default_app_evt_queue_size
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
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
int app_worker_add_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
Send an API message to the external app, to map new segment.
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
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:236
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.
u32 segment_manager_evt_q_expected_size(u32 q_len)
unsigned char u8
Definition: types.h:56
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:423
static session_handle_t session_handle(session_t *s)
struct _svm_fifo svm_fifo_t
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
svm_msg_q_t * svm_msg_q_alloc(svm_msg_q_cfg_t *cfg)
Allocate message queue.
Definition: message_queue.c:40
static u8 segment_manager_app_detached(segment_manager_t *sm)
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
#define always_inline
Definition: clib.h:98
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 int u32
Definition: types.h:88
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:411
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 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:514
uword 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)
static session_t * session_get_from_handle(session_handle_t handle)
Definition: session.h:227
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
uword clib_mem_get_page_size(void)
Definition: mem.c:51
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
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.
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
u32 n_rings
number of msg rings
Definition: message_queue.h:54
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
vlib_main_t * vm
Definition: buffer.c:312
#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:283
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:89
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
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)
void segment_manager_main_init(segment_manager_main_init_args_t *a)
svm_fifo_t * svm_fifo_segment_alloc_fifo(svm_fifo_segment_private_t *fs, u32 data_size_in_bytes, svm_fifo_segment_freelist_t list_index)
Allocate fifo in svm segment.
static u32 segment_manager_segment_index(segment_manager_t *sm, svm_fifo_segment_private_t *seg)
svm_msg_q_ring_cfg_t * ring_cfgs
array of ring cfgs
Definition: message_queue.h:55
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:288
u8 * name
Definition: ssvm.h:86
int app_worker_del_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
void segment_manager_segment_writer_unlock(segment_manager_t *sm)
void segment_manager_del(segment_manager_t *sm)
Removes segment manager.
app_worker_t * app_worker_get(u32 wrk_index)
u64 segment_manager_segment_handle(segment_manager_t *sm, svm_fifo_segment_private_t *segment)
u32 q_nitems
msg queue size (not rings)
Definition: message_queue.h:53
u64 session_handle_t
static uword max_log2(uword x)
Definition: clib.h:191
static u32 segment_name_counter
Counter used to build segment names.
void session_close(session_t *s)
Initialize session closing procedure.
Definition: session.c:1069
u64 uword
Definition: types.h:112
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.
u32 app_index
Index of owning app.
Definition: application.h:43
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:366
#define vec_foreach(var, vec)
Vector iterator.
static clib_error_t * segment_manager_show_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int consumer_pid
pid of msg consumer
Definition: message_queue.h:52
static u32 default_fifo_size
Default fifo and segment size.
int svm_msg_q_alloc_producer_eventfd(svm_msg_q_t *mq)
Allocate event fd for queue consumer.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
static segment_manager_t * segment_manager_get(u32 index)
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
void segment_manager_parse_segment_handle(u64 segment_handle, u32 *sm_index, u32 *segment_index)
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
ssvm_segment_type_t ssvm_type(const ssvm_private_t *ssvm)
Definition: ssvm.c:429
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128