FD.io VPP  v21.10.1-2-g0a485f517
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 
20 typedef struct segment_manager_main_
21 {
22  segment_manager_t *segment_managers; /**< Pool of segment managers */
23  u32 seg_name_counter; /**< Counter for segment names */
24 
25  /*
26  * Configuration
27  */
28  u32 default_fifo_size; /**< default rx/tx fifo size */
29  u32 default_segment_size; /**< default fifo segment size */
30  u32 default_app_mq_size; /**< default app msg q size */
31  u32 default_max_fifo_size; /**< default max fifo size */
32  u8 default_high_watermark; /**< default high watermark % */
33  u8 default_low_watermark; /**< default low watermark % */
35 
37 
38 #define segment_manager_foreach_segment_w_lock(VAR, SM, BODY) \
39 do { \
40  clib_rwlock_reader_lock (&(SM)->segments_rwlock); \
41  pool_foreach((VAR), ((SM)->segments)) (BODY); \
42  clib_rwlock_reader_unlock (&(SM)->segments_rwlock); \
43 } while (0)
44 
47 {
48  app_worker_t *app_wrk = app_worker_get (sm->app_wrk_index);
50 }
51 
54 {
55  props->add_segment_size = sm_main.default_segment_size;
56  props->rx_fifo_size = sm_main.default_fifo_size;
57  props->tx_fifo_size = sm_main.default_fifo_size;
58  props->evt_q_size = sm_main.default_app_mq_size;
59  props->max_fifo_size = sm_main.default_max_fifo_size;
60  props->high_watermark = sm_main.default_high_watermark;
61  props->low_watermark = sm_main.default_low_watermark;
62  props->n_slices = vlib_num_workers () + 1;
63  return props;
64 }
65 
66 u8
68 {
69  return (sm->flags & SEG_MANAGER_F_DETACHED);
70 }
71 
72 void
74 {
75  sm->flags |= SEG_MANAGER_F_DETACHED;
76 }
77 
80 {
81  return (seg - sm->segments);
82 }
83 
84 /**
85  * Adds segment to segment manager's pool
86  *
87  * If needed a writer's lock is acquired before allocating a new segment
88  * to avoid affecting any of the segments pool readers.
89  */
90 static inline int
92  u8 notify_app, u8 flags)
93 {
96  fifo_segment_t *fs;
97  u32 fs_index = ~0;
98  u8 *seg_name;
99  int rv;
100 
101  props = segment_manager_properties_get (sm);
102 
103  /* Not configured for addition of new segments and not first */
104  if (!props->add_segment && !segment_size)
105  {
106  clib_warning ("cannot allocate new segment");
107  return VNET_API_ERROR_INVALID_VALUE;
108  }
109 
110  /*
111  * Allocate fifo segment and grab lock if needed
112  */
113  if (vlib_num_workers ())
114  clib_rwlock_writer_lock (&sm->segments_rwlock);
115 
116  pool_get_zero (sm->segments, fs);
117 
118  /*
119  * Allocate ssvm segment
120  */
121  segment_size = segment_size ? segment_size : props->add_segment_size;
122  segment_size = round_pow2 (segment_size, clib_mem_get_page_size ());
123 
124  if (props->segment_type != SSVM_SEGMENT_PRIVATE)
125  {
126  seg_name = format (0, "%d-%d%c", getpid (), smm->seg_name_counter++, 0);
127  }
128  else
129  {
130  app_worker_t *app_wrk = app_worker_get (sm->app_wrk_index);
131  application_t *app = application_get (app_wrk->app_index);
132  seg_name = format (0, "%v segment%c", app->name, 0);
133  }
134 
135  fs->ssvm.ssvm_size = segment_size;
136  fs->ssvm.name = seg_name;
137  fs->ssvm.requested_va = 0;
138 
139  if ((rv = ssvm_server_init (&fs->ssvm, props->segment_type)))
140  {
141  clib_warning ("svm_master_init ('%v', %u) failed", seg_name,
142  segment_size);
143  pool_put (sm->segments, fs);
144  goto done;
145  }
146 
147  /*
148  * Initialize fifo segment
149  */
150  fs->n_slices = props->n_slices;
151  fifo_segment_init (fs);
152 
153  /*
154  * Save segment index before dropping lock, if any held
155  */
156  fs_index = fs - sm->segments;
157 
158  /*
159  * Set watermarks in segment
160  */
161  fs->high_watermark = sm->high_watermark;
162  fs->low_watermark = sm->low_watermark;
163  fs->flags = flags;
165  fs->h->pct_first_alloc = props->pct_first_alloc;
166 
167  if (notify_app)
168  {
169  app_worker_t *app_wrk;
170  u64 fs_handle;
171  fs_handle = segment_manager_segment_handle (sm, fs);
172  app_wrk = app_worker_get (sm->app_wrk_index);
173  rv = app_worker_add_segment_notify (app_wrk, fs_handle);
174  if (rv)
175  return rv;
176  }
177 done:
178 
179  if (vlib_num_workers ())
180  clib_rwlock_writer_unlock (&sm->segments_rwlock);
181 
182  return fs_index;
183 }
184 
185 int
187  u8 notify_app)
188 {
189  return segment_manager_add_segment_inline (sm, segment_size, notify_app, 0);
190 }
191 
192 int
194  u8 flags)
195 {
196  return segment_manager_add_segment_inline (sm, segment_size, 0, flags);
197 }
198 
199 /**
200  * Remove segment without lock
201  */
202 void
204 {
205  if (ssvm_type (&fs->ssvm) != SSVM_SEGMENT_PRIVATE)
206  {
208  {
209  app_worker_t *app_wrk;
210  u64 segment_handle;
211  app_wrk = app_worker_get (sm->app_wrk_index);
212  segment_handle = segment_manager_segment_handle (sm, fs);
213  app_worker_del_segment_notify (app_wrk, segment_handle);
214  }
215  }
216 
218  ssvm_delete (&fs->ssvm);
219 
220  if (CLIB_DEBUG)
221  clib_memset (fs, 0xfb, sizeof (*fs));
222  pool_put (sm->segments, fs);
223 }
224 
225 static fifo_segment_t *
227  u32 segment_index)
228 {
229  if (pool_is_free_index (sm->segments, segment_index))
230  return 0;
231  return pool_elt_at_index (sm->segments, segment_index);
232 }
233 
234 /**
235  * Removes segment after acquiring writer lock
236  */
237 static inline void
239 {
240  fifo_segment_t *fs;
241  u8 is_prealloc;
242 
243  clib_rwlock_writer_lock (&sm->segments_rwlock);
244 
245  fs = segment_manager_get_segment_if_valid (sm, fs_index);
246  if (!fs)
247  goto done;
248 
250  if (is_prealloc && !segment_manager_app_detached (sm))
251  goto done;
252 
254 
255 done:
256  clib_rwlock_writer_unlock (&sm->segments_rwlock);
257 }
258 
259 void
261 {
262  sm_lock_and_del_segment_inline (sm, fs_index);
263 }
264 
265 /**
266  * Reads a segment from the segment manager's pool without lock
267  */
270 {
271  return pool_elt_at_index (sm->segments, segment_index);
272 }
273 
274 u64
276  fifo_segment_t * segment)
277 {
278  u32 segment_index = segment_manager_segment_index (sm, segment);
279  return (((u64) segment_manager_index (sm) << 32) | segment_index);
280 }
281 
282 u64
284  u32 segment_index)
285 {
286  return (((u64) segment_manager_index << 32) | segment_index);
287 }
288 
291 {
292  u32 sm_index, segment_index;
293  segment_manager_t *sm;
294 
295  segment_manager_parse_segment_handle (segment_handle, &sm_index,
296  &segment_index);
297  sm = segment_manager_get (sm_index);
298  if (!sm || pool_is_free_index (sm->segments, segment_index))
299  return 0;
300  return pool_elt_at_index (sm->segments, segment_index);
301 }
302 
303 /**
304  * Reads a segment from the segment manager's pool and acquires reader lock
305  *
306  * Caller must drop the reader's lock by calling
307  * @ref segment_manager_segment_reader_unlock once it finishes working with
308  * the segment.
309  */
312 {
313  clib_rwlock_reader_lock (&sm->segments_rwlock);
314  return pool_elt_at_index (sm->segments, segment_index);
315 }
316 
317 void
319 {
320  clib_rwlock_reader_lock (&sm->segments_rwlock);
321 }
322 
323 void
325 {
326  clib_rwlock_reader_unlock (&sm->segments_rwlock);
327 }
328 
329 void
331 {
332  clib_rwlock_writer_unlock (&sm->segments_rwlock);
333 }
334 
337 {
339  segment_manager_t *sm;
340 
341  pool_get_zero (smm->segment_managers, sm);
342  clib_rwlock_init (&sm->segments_rwlock);
343  return sm;
344 }
345 
346 int
348 {
350 
351  props = segment_manager_properties_get (sm);
352 
353  sm->max_fifo_size = props->max_fifo_size ?
354  props->max_fifo_size : sm_main.default_max_fifo_size;
355  sm->max_fifo_size = clib_max (sm->max_fifo_size, 4096);
356 
358  props->high_watermark,
359  props->low_watermark);
360  return 0;
361 }
362 
363 /**
364  * Initializes segment manager based on options provided.
365  * Returns error if ssvm segment(s) allocation fails.
366  */
367 int
369 {
371  uword first_seg_size;
372  fifo_segment_t *fs;
373  int fs_index, i;
374 
376  props = segment_manager_properties_get (sm);
377  first_seg_size = clib_max (props->segment_size,
379 
380  if (props->prealloc_fifos)
381  {
382  u64 approx_total_size, max_seg_size = ((u64) 1 << 32) - (128 << 10);
383  u32 rx_rounded_data_size, tx_rounded_data_size;
384  u32 prealloc_fifo_pairs = props->prealloc_fifos;
385  u32 rx_fifo_size, tx_fifo_size, pair_size;
386  u32 approx_segment_count;
387 
388  /* Figure out how many segments should be preallocated */
389  rx_rounded_data_size = (1 << (max_log2 (props->rx_fifo_size)));
390  tx_rounded_data_size = (1 << (max_log2 (props->tx_fifo_size)));
391 
392  rx_fifo_size = sizeof (svm_fifo_t) + rx_rounded_data_size;
393  tx_fifo_size = sizeof (svm_fifo_t) + tx_rounded_data_size;
394  pair_size = rx_fifo_size + tx_fifo_size;
395 
396  approx_total_size = (u64) prealloc_fifo_pairs *pair_size;
397  if (first_seg_size > approx_total_size)
398  max_seg_size = first_seg_size;
399  approx_segment_count = (approx_total_size + (max_seg_size - 1))
400  / max_seg_size;
401 
402  /* Allocate the segments */
403  for (i = 0; i < approx_segment_count + 1; i++)
404  {
405  fs_index = segment_manager_add_segment (sm, max_seg_size, 0);
406  if (fs_index < 0)
407  {
408  clib_warning ("Failed to preallocate segment %d", i);
409  return fs_index;
410  }
411 
412  fs = segment_manager_get_segment (sm, fs_index);
413  if (i == 0)
414  sm->event_queue = segment_manager_alloc_queue (fs, props);
415 
417  props->rx_fifo_size,
418  props->tx_fifo_size,
419  &prealloc_fifo_pairs);
421  if (prealloc_fifo_pairs == 0)
422  break;
423  }
424  return 0;
425  }
426 
427  fs_index = segment_manager_add_segment (sm, first_seg_size, 0);
428  if (fs_index < 0)
429  {
430  clib_warning ("Failed to allocate segment");
431  return fs_index;
432  }
433 
434  fs = segment_manager_get_segment (sm, fs_index);
435  sm->event_queue = segment_manager_alloc_queue (fs, props);
436 
437  if (props->prealloc_fifo_hdrs)
438  {
439  u32 hdrs_per_slice;
440 
441  /* Do not preallocate on slice associated to main thread */
442  i = (vlib_num_workers ()? 1 : 0);
443  hdrs_per_slice = props->prealloc_fifo_hdrs / (fs->n_slices - i);
444 
445  for (; i < fs->n_slices; i++)
446  {
447  if (fifo_segment_prealloc_fifo_hdrs (fs, i, hdrs_per_slice))
448  return VNET_API_ERROR_SVM_SEGMENT_CREATE_FAIL;
449  }
450  }
451 
452  return 0;
453 }
454 
455 void
457 {
458  app_worker_t *app_wrk;
459 
460  app_wrk = app_worker_get_if_valid (sm->app_wrk_index);
461  if (!app_wrk)
462  return;
463 
465 }
466 
467 /**
468  * Cleanup segment manager.
469  */
470 void
472 {
474  fifo_segment_t *fifo_segment;
475 
479 
480  if (sm->flags & SEG_MANAGER_F_DETACHED_LISTENER)
482 
483  /* If we have empty preallocated segments that haven't been removed, remove
484  * them now. Apart from that, the first segment in the first segment manager
485  * is not removed when all fifos are removed. It can only be removed when
486  * the manager is explicitly deleted/detached by the app. */
487  clib_rwlock_writer_lock (&sm->segments_rwlock);
488 
489  /* *INDENT-OFF* */
490  pool_foreach (fifo_segment, sm->segments) {
491  segment_manager_del_segment (sm, fifo_segment);
492  }
493  /* *INDENT-ON* */
494 
495  pool_free (sm->segments);
496  clib_rwlock_writer_unlock (&sm->segments_rwlock);
497 
498  clib_rwlock_free (&sm->segments_rwlock);
499  if (CLIB_DEBUG)
500  clib_memset (sm, 0xfe, sizeof (*sm));
501  pool_put (smm->segment_managers, sm);
502 }
503 
504 static void
506 {
507  u32 sm_index = *(u32 *) arg;
508  segment_manager_t *sm;
509 
510  ASSERT (vlib_get_thread_index () == 0);
511 
512  if ((sm = segment_manager_get_if_valid (sm_index)))
514 }
515 
516 void
518 {
520  {
521  u32 sm_index = segment_manager_index (sm);
523  sizeof (sm_index));
524  }
525  else
526  {
528  }
529 }
530 
531 void
533 {
534  ASSERT (vlib_get_thread_index () == 0);
535 
537  if (segment_manager_has_fifos (sm))
539  else
540  {
541  ASSERT (!sm->first_is_protected || segment_manager_app_detached (sm));
543  }
544 }
545 
548 {
550 }
551 
554 {
556  return 0;
558 }
559 
560 u32
562 {
563  return sm - sm_main.segment_managers;
564 }
565 
566 u8
568 {
569  fifo_segment_t *seg;
570  u8 first = 1;
571 
572  /* *INDENT-OFF* */
574  if (CLIB_DEBUG && !first && !fifo_segment_has_fifos (seg)
576  {
577  clib_warning ("segment %d has no fifos!",
579  first = 0;
580  }
581  if (fifo_segment_has_fifos (seg))
582  {
584  return 1;
585  }
586  }));
587  /* *INDENT-ON* */
588 
589  return 0;
590 }
591 
592 /**
593  * Initiate disconnects for all sessions 'owned' by a segment manager
594  */
595 void
597 {
598  session_handle_t *handles = 0, *handle;
599  fifo_segment_t *fs;
600  session_t *session;
601  int slice_index;
602  svm_fifo_t *f;
603 
604  ASSERT (pool_elts (sm->segments) != 0);
605 
606  /* Across all fifo segments used by the server */
607  /* *INDENT-OFF* */
609  for (slice_index = 0; slice_index < fs->n_slices; slice_index++)
610  {
611  f = fifo_segment_get_slice_fifo_list (fs, slice_index);
612 
613  /*
614  * Remove any residual sessions from the session lookup table
615  * Don't bother deleting the individual fifos, we're going to
616  * throw away the fifo segment in a minute.
617  */
618  while (f)
619  {
620  session = session_get_if_valid (f->shr->master_session_index,
621  f->master_thread_index);
622  if (session)
623  vec_add1 (handles, session_handle (session));
624  f = f->next;
625  }
626  }
627 
628  /* Instead of removing the segment, test when cleaning up disconnected
629  * sessions if the segment can be removed.
630  */
631  }));
632  /* *INDENT-ON* */
633 
634  vec_foreach (handle, handles)
635  {
636  session = session_get_from_handle (*handle);
637  session_close (session);
638  /* Avoid propagating notifications back to the app */
639  session->app_wrk_index = APP_INVALID_INDEX;
640  }
641  vec_free (handles);
642 }
643 
644 /**
645  * Initiate disconnects for sessions in specified state 'owned' by a segment
646  * manager
647  */
648 void
650  session_state_t *states)
651 {
652  session_handle_t *handles = 0, *handle;
653  fifo_segment_t *fs;
654  session_t *session;
655  int slice_index;
656  svm_fifo_t *f;
657 
658  ASSERT (pool_elts (sm->segments) != 0);
659 
660  /* Across all fifo segments used by the server */
662  fs, sm, ({
663  for (slice_index = 0; slice_index < fs->n_slices; slice_index++)
664  {
665  f = fifo_segment_get_slice_fifo_list (fs, slice_index);
666  while (f)
667  {
668  session = session_get_if_valid (f->shr->master_session_index,
669  f->master_thread_index);
670  if (session)
671  {
673  vec_foreach (state, states)
674  {
675  if (session->session_state == *state)
676  {
677  vec_add1 (handles, session_handle (session));
678  break;
679  }
680  }
681  }
682  f = f->next;
683  }
684  }
685  }));
686 
687  vec_foreach (handle, handles)
688  {
689  session = session_get_from_handle (*handle);
690  session_close (session);
691  /* Avoid propagating notifications back to the app */
692  session->app_wrk_index = APP_INVALID_INDEX;
693  }
694  vec_free (handles);
695 }
696 
697 int
700  u32 rx_fifo_size, u32 tx_fifo_size,
701  svm_fifo_t ** rx_fifo, svm_fifo_t ** tx_fifo)
702 {
703  rx_fifo_size = clib_max (rx_fifo_size, sm_main.default_fifo_size);
704  *rx_fifo = fifo_segment_alloc_fifo_w_slice (fifo_segment, thread_index,
705  rx_fifo_size,
707 
708  tx_fifo_size = clib_max (tx_fifo_size, sm_main.default_fifo_size);
709  *tx_fifo = fifo_segment_alloc_fifo_w_slice (fifo_segment, thread_index,
710  tx_fifo_size,
712 
713  if (*rx_fifo == 0)
714  {
715  /* This would be very odd, but handle it... */
716  if (*tx_fifo != 0)
717  {
718  fifo_segment_free_fifo (fifo_segment, *tx_fifo);
719  *tx_fifo = 0;
720  }
721  return -1;
722  }
723  if (*tx_fifo == 0)
724  {
725  if (*rx_fifo != 0)
726  {
727  fifo_segment_free_fifo (fifo_segment, *rx_fifo);
728  *rx_fifo = 0;
729  }
730  return -1;
731  }
732 
733  return 0;
734 }
735 
736 int
739  svm_fifo_t ** rx_fifo,
740  svm_fifo_t ** tx_fifo)
741 {
742  int alloc_fail = 1, rv = 0, new_fs_index;
743  uword free_bytes, max_free_bytes = 0;
745  fifo_segment_t *fs = 0, *cur;
746  u32 sm_index, fs_index;
747 
748  props = segment_manager_properties_get (sm);
749 
750  /*
751  * Find the first free segment to allocate the fifos in
752  */
753 
755 
756  pool_foreach (cur, sm->segments) {
758  continue;
759  free_bytes = fifo_segment_available_bytes (cur);
760  if (free_bytes > max_free_bytes)
761  {
762  max_free_bytes = free_bytes;
763  fs = cur;
764  }
765  }
766 
767  if (fs)
768  {
770  props->rx_fifo_size,
771  props->tx_fifo_size,
772  rx_fifo, tx_fifo);
773  /* On success, keep lock until fifos are initialized */
774  if (!alloc_fail)
775  goto alloc_success;
776  }
777 
779 
780  /*
781  * Allocation failed, see if we can add a new segment
782  */
783  if (props->add_segment)
784  {
785  if ((new_fs_index = segment_manager_add_segment (sm, 0, 1)) < 0)
786  {
787  clib_warning ("Failed to add new segment");
788  return SESSION_E_SEG_CREATE;
789  }
790  fs = segment_manager_get_segment_w_lock (sm, new_fs_index);
792  props->rx_fifo_size,
793  props->tx_fifo_size,
794  rx_fifo, tx_fifo);
795  if (alloc_fail)
796  {
797  clib_warning ("Added a segment, still can't allocate a fifo");
799  return SESSION_E_SEG_NO_SPACE2;
800  }
801  }
802  else
803  {
804  SESSION_DBG ("Can't add new seg and no space to allocate fifos!");
805  return SESSION_E_SEG_NO_SPACE;
806  }
807 
808 alloc_success:
809  ASSERT (rx_fifo && tx_fifo);
810 
811  sm_index = segment_manager_index (sm);
812  fs_index = segment_manager_segment_index (sm, fs);
813  (*tx_fifo)->segment_manager = sm_index;
814  (*rx_fifo)->segment_manager = sm_index;
815  (*tx_fifo)->segment_index = fs_index;
816  (*rx_fifo)->segment_index = fs_index;
817 
818  /* Drop the lock after app is notified */
820 
821  return rv;
822 }
823 
824 void
826 {
827  segment_manager_t *sm;
828  fifo_segment_t *fs;
829  u32 segment_index;
830 
831  if (!rx_fifo || !tx_fifo)
832  return;
833 
834  /* It's possible to have no segment manager if the session was removed
835  * as result of a detach. */
836  if (!(sm = segment_manager_get_if_valid (rx_fifo->segment_manager)))
837  return;
838 
839  segment_index = rx_fifo->segment_index;
840  fs = segment_manager_get_segment_w_lock (sm, segment_index);
841  fifo_segment_free_fifo (fs, rx_fifo);
842  fifo_segment_free_fifo (fs, tx_fifo);
843 
844  /*
845  * Try to remove svm segment if it has no fifos. This can be done only if
846  * the segment is not the first in the segment manager or if it is first
847  * and it is not protected. Moreover, if the segment is first and the app
848  * has detached from the segment manager, remove the segment manager.
849  */
850  if (!fifo_segment_has_fifos (fs))
851  {
853 
854  /* Remove segment if it holds no fifos or first but not protected */
855  if (segment_index != 0 || !sm->first_is_protected)
856  sm_lock_and_del_segment_inline (sm, segment_index);
857 
858  /* Remove segment manager if no sessions and detached from app */
860  && !segment_manager_has_fifos (sm))
862  }
863  else
865 }
866 
867 void
869 {
870  fifo_segment_t *fs;
871 
872  fs = segment_manager_get_segment_w_lock (sm, (*f)->segment_index);
875 }
876 
877 void
879  session_t *s)
880 {
881  fifo_segment_t *fs;
882 
883  fs = segment_manager_get_segment_w_lock (sm, (*f)->segment_index);
886 
887  (*f)->shr->master_session_index = s->session_index;
888  (*f)->master_thread_index = s->thread_index;
889 }
890 
891 u32
893 {
894  u32 fifo_evt_size, notif_q_size, q_hdrs;
895  u32 msg_q_sz, fifo_evt_ring_sz, session_ntf_ring_sz;
896 
897  fifo_evt_size = 1 << max_log2 (sizeof (session_event_t));
898  notif_q_size = clib_max (16, q_len >> 4);
899 
900  msg_q_sz = q_len * sizeof (svm_msg_q_msg_t);
901  fifo_evt_ring_sz = q_len * fifo_evt_size;
902  session_ntf_ring_sz = notif_q_size * 256;
903  q_hdrs = sizeof (svm_queue_t) + sizeof (svm_msg_q_t);
904 
905  return (msg_q_sz + fifo_evt_ring_sz + session_ntf_ring_sz + q_hdrs);
906 }
907 
908 /**
909  * Allocates shm queue in the first segment
910  *
911  * Must be called with lock held
912  */
913 svm_msg_q_t *
915  segment_manager_props_t * props)
916 {
917  u32 fifo_evt_size, session_evt_size = 256, notif_q_size;
918  svm_msg_q_cfg_t _cfg, *cfg = &_cfg;
919  svm_msg_q_t *q;
920 
921  fifo_evt_size = sizeof (session_event_t);
922  notif_q_size = clib_max (16, props->evt_q_size >> 4);
923  /* *INDENT-OFF* */
925  {props->evt_q_size, fifo_evt_size, 0},
926  {notif_q_size, session_evt_size, 0}
927  };
928  /* *INDENT-ON* */
929  cfg->consumer_pid = 0;
930  cfg->n_rings = 2;
931  cfg->q_nitems = props->evt_q_size;
932  cfg->ring_cfgs = rc;
933 
934  q = fifo_segment_msg_q_alloc (segment, 0, cfg);
935 
936  if (props->use_mq_eventfd)
937  {
938  if (svm_msg_q_alloc_eventfd (q))
939  clib_warning ("failed to alloc eventfd");
940  }
941  return q;
942 }
943 
944 svm_msg_q_t *
946 {
947  return sm->event_queue;
948 }
949 
950 /**
951  * Frees shm queue allocated in the first segment
952  */
953 void
955 {
956  fifo_segment_t *segment;
958  void *oldheap;
959 
960  ASSERT (!pool_is_free_index (sm->segments, 0));
961 
962  segment = segment_manager_get_segment_w_lock (sm, 0);
963  sh = segment->ssvm.sh;
964 
965  oldheap = ssvm_push_heap (sh);
966  svm_queue_free (q);
967  ssvm_pop_heap (oldheap);
969 }
970 
971 /*
972  * Init segment vm address allocator
973  */
974 void
976 {
978 
979  sm->default_fifo_size = 1 << 12;
980  sm->default_segment_size = 1 << 20;
981  sm->default_app_mq_size = 128;
982  sm->default_max_fifo_size = 4 << 20;
983  sm->default_high_watermark = 80;
984  sm->default_low_watermark = 50;
985 }
986 
987 static clib_error_t *
989  vlib_cli_command_t * cmd)
990 {
992  u8 show_segments = 0, verbose = 0;
993  uword max_fifo_size;
994  segment_manager_t *sm;
995  fifo_segment_t *seg;
996  app_worker_t *app_wrk;
997  application_t *app;
998  u8 custom_logic;
999 
1000  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1001  {
1002  if (unformat (input, "segments"))
1003  show_segments = 1;
1004  else if (unformat (input, "verbose"))
1005  verbose = 1;
1006  else
1007  return clib_error_return (0, "unknown input `%U'",
1008  format_unformat_error, input);
1009  }
1010  vlib_cli_output (vm, "%d segment managers allocated",
1011  pool_elts (smm->segment_managers));
1012  if (verbose && pool_elts (smm->segment_managers))
1013  {
1014  vlib_cli_output (vm, "%-6s%=10s%=10s%=13s%=11s%=11s%=12s",
1015  "Index", "AppIndex", "Segments", "MaxFifoSize",
1016  "HighWater", "LowWater", "FifoTuning");
1017 
1018  /* *INDENT-OFF* */
1019  pool_foreach (sm, smm->segment_managers) {
1020  app_wrk = app_worker_get_if_valid (sm->app_wrk_index);
1021  app = app_wrk ? application_get (app_wrk->app_index) : 0;
1022  custom_logic = (app && (app->cb_fns.fifo_tuning_callback)) ? 1 : 0;
1023  max_fifo_size = sm->max_fifo_size;
1024 
1025  vlib_cli_output (vm, "%-6d%=10d%=10d%=13U%=11d%=11d%=12s",
1026  segment_manager_index (sm),
1027  sm->app_wrk_index, pool_elts (sm->segments),
1028  format_memory_size, max_fifo_size,
1029  sm->high_watermark, sm->low_watermark,
1030  custom_logic ? "custom" : "none");
1031  }
1032  /* *INDENT-ON* */
1033 
1034  vlib_cli_output (vm, "\n");
1035  }
1036  if (show_segments)
1037  {
1038  vlib_cli_output (vm, "%U", format_fifo_segment, 0, verbose);
1039 
1040  /* *INDENT-OFF* */
1041  pool_foreach (sm, smm->segment_managers) {
1043  vlib_cli_output (vm, "%U", format_fifo_segment, seg, verbose);
1044  }));
1045  }
1046  /* *INDENT-ON* */
1047 
1048  }
1049  return 0;
1050 }
1051 
1052 /* *INDENT-OFF* */
1054 {
1055  .path = "show segment-manager",
1056  .short_help = "show segment-manager [segments][verbose]",
1057  .function = segment_manager_show_fn,
1058 };
1059 /* *INDENT-ON* */
1060 
1061 void
1063 {
1065  app_worker_t *app_wrk;
1066  fifo_segment_t *fs;
1067  const u8 *app_name;
1068  int slice_index;
1069  u8 *s = 0, *str;
1070  svm_fifo_t *f;
1071 
1072  if (!sm)
1073  {
1074  if (verbose)
1075  vlib_cli_output (vm, "%-" SESSION_CLI_ID_LEN "s%-20s%-15s%-10s",
1076  "Connection", "App", "API Client", "SegManager");
1077  else
1078  vlib_cli_output (vm, "%-" SESSION_CLI_ID_LEN "s%-20s", "Connection",
1079  "App");
1080  return;
1081  }
1082 
1083  app_wrk = app_worker_get (sm->app_wrk_index);
1085 
1086  clib_rwlock_reader_lock (&sm->segments_rwlock);
1087 
1088  /* *INDENT-OFF* */
1089  pool_foreach (fs, sm->segments) {
1090  for (slice_index = 0; slice_index < fs->n_slices; slice_index++)
1091  {
1092  f = fifo_segment_get_slice_fifo_list (fs, slice_index);
1093  while (f)
1094  {
1095  u32 session_index, thread_index;
1096  session_t *session;
1097 
1098  session_index = f->shr->master_session_index;
1099  thread_index = f->master_thread_index;
1100 
1101  session = session_get (session_index, thread_index);
1102  str = format (0, "%U", format_session, session, verbose);
1103 
1104  if (verbose)
1105  s = format (s, "%-" SESSION_CLI_ID_LEN "v%-20v%-15u%-10u", str,
1106  app_name, app_wrk->api_client_index,
1107  app_wrk->connects_seg_manager);
1108  else
1109  s = format (s, "%-" SESSION_CLI_ID_LEN "v%-20v", str, app_name);
1110 
1111  vlib_cli_output (vm, "%v", s);
1112  vec_reset_length (s);
1113  vec_free (str);
1114 
1115  f = f->next;
1116  }
1117  vec_free (s);
1118  }
1119  }
1120  /* *INDENT-ON* */
1121 
1122  clib_rwlock_reader_unlock (&sm->segments_rwlock);
1123 }
1124 
1125 void
1127  u8 high_watermark, u8 low_watermark)
1128 {
1129  ASSERT (high_watermark <= 100 && low_watermark <= 100 &&
1130  low_watermark <= high_watermark);
1131 
1132  sm->high_watermark = high_watermark;
1133  sm->low_watermark = low_watermark;
1134 }
1135 
1136 /*
1137  * fd.io coding-style-patch-verification: ON
1138  *
1139  * Local Variables:
1140  * eval: (c-set-style "gnu")
1141  * End:
1142  */
vec_reset_length
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
Definition: vec_bootstrap.h:194
ssvm_private_t::requested_va
uword requested_va
Definition: ssvm.h:85
segment_manager_main_t
struct segment_manager_main_ segment_manager_main_t
segment_manager_get_segment_w_lock
fifo_segment_t * segment_manager_get_segment_w_lock(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager's pool and acquires reader lock.
Definition: segment_manager.c:311
svm_msg_q_cfg_::n_rings
u32 n_rings
number of msg rings
Definition: message_queue.h:89
segment_manager_properties_get
static segment_manager_props_t * segment_manager_properties_get(segment_manager_t *sm)
Definition: segment_manager.c:46
vlib_num_workers
static u32 vlib_num_workers()
Definition: threads.h:333
segment_manager_segment_index
static u32 segment_manager_segment_index(segment_manager_t *sm, fifo_segment_t *seg)
Definition: segment_manager.c:79
SESSION_MQ_N_RINGS
@ SESSION_MQ_N_RINGS
Definition: session_types.h:403
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
segment_manager_segment_reader_lock
void segment_manager_segment_reader_lock(segment_manager_t *sm)
Definition: segment_manager.c:318
segment_manager_get
segment_manager_t * segment_manager_get(u32 index)
Definition: segment_manager.c:547
segment_manager_init_first
int segment_manager_init_first(segment_manager_t *sm)
Initializes segment manager based on options provided.
Definition: segment_manager.c:368
segment_manager_segment_writer_unlock
void segment_manager_segment_writer_unlock(segment_manager_t *sm)
Definition: segment_manager.c:330
segment_manager_show_fn
static clib_error_t * segment_manager_show_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: segment_manager.c:988
session_::session_index
u32 session_index
Index in thread pool where session was allocated.
Definition: session_types.h:188
fifo_segment_alloc_fifo_w_slice
svm_fifo_t * fifo_segment_alloc_fifo_w_slice(fifo_segment_t *fs, u32 slice_index, u32 data_bytes, fifo_segment_ftype_t ftype)
Allocate fifo in fifo segment.
Definition: fifo_segment.c:847
segment_manager_main_::segment_managers
segment_manager_t * segment_managers
Pool of segment managers.
Definition: segment_manager.c:22
SESSION_CLI_ID_LEN
#define SESSION_CLI_ID_LEN
Definition: session_types.h:507
session_close
void session_close(session_t *s)
Initialize session closing procedure.
Definition: session.c:1494
clib_max
#define clib_max(x, y)
Definition: clib.h:335
fifo_segment_attach_fifo
void fifo_segment_attach_fifo(fifo_segment_t *fs, svm_fifo_t **f, u32 slice_index)
Definition: fifo_segment.c:1012
sm_lock_and_del_segment_inline
static void sm_lock_and_del_segment_inline(segment_manager_t *sm, u32 fs_index)
Removes segment after acquiring writer lock.
Definition: segment_manager.c:238
f
vlib_frame_t * f
Definition: interface_output.c:1098
segment_manager_init
int segment_manager_init(segment_manager_t *sm)
Definition: segment_manager.c:347
ssvm_pop_heap
static void ssvm_pop_heap(void *oldheap)
Definition: ssvm.h:151
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
fifo_segment_t::high_watermark
u8 high_watermark
memory pressure watermark high
Definition: fifo_segment.h:77
ssvm_private_t::ssvm_size
uword ssvm_size
Definition: ssvm.h:84
segment_manager_main_::default_low_watermark
u8 default_low_watermark
default low watermark %
Definition: segment_manager.c:33
fifo_segment_t
Definition: fifo_segment.h:68
segment_manager_props_init
segment_manager_props_t * segment_manager_props_init(segment_manager_props_t *props)
Definition: segment_manager.c:53
fifo_segment_detach_fifo
void fifo_segment_detach_fifo(fifo_segment_t *fs, svm_fifo_t **f)
Definition: fifo_segment.c:985
segment_manager_main_
Definition: segment_manager.c:20
session_
Definition: session_types.h:175
segment_manager_t
struct _segment_manager segment_manager_t
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
svm_queue_t
struct _svm_queue svm_queue_t
session_handle_t
u64 session_handle_t
Definition: session_types.h:111
ssvm_push_heap
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
Definition: ssvm.h:143
svm_msg_q_cfg_::q_nitems
u32 q_nitems
msg queue size (not rings)
Definition: message_queue.h:88
first
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
APP_INVALID_INDEX
#define APP_INVALID_INDEX
Definition: application.h:226
svm_msg_q_msg_t
Definition: message_queue.h:93
session_::thread_index
u8 thread_index
Index of the thread that allocated the session.
Definition: session_types.h:194
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
fifo_segment_flags
#define fifo_segment_flags(_fs)
Definition: fifo_segment.h:97
state
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
svm_msg_q_alloc_eventfd
int svm_msg_q_alloc_eventfd(svm_msg_q_t *mq)
Allocate event fd for queue.
Definition: message_queue.c:491
application_
Definition: application.h:108
ssvm_private_t::sh
ssvm_shared_header_t * sh
Definition: ssvm.h:83
unformat_input_t
struct _unformat_input_t unformat_input_t
app_worker_del_segment_notify
int app_worker_del_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
Definition: application_worker.c:600
clib_rwlock_reader_lock
static void clib_rwlock_reader_lock(clib_rwlock_t *p)
Definition: lock.h:169
segment_manager_parse_segment_handle
static void segment_manager_parse_segment_handle(u64 segment_handle, u32 *sm_index, u32 *segment_index)
Definition: segment_manager.h:175
clib_rwlock_reader_unlock
static void clib_rwlock_reader_unlock(clib_rwlock_t *p)
Definition: lock.h:184
segment_manager_alloc
segment_manager_t * segment_manager_alloc(void)
Definition: segment_manager.c:336
clib_rwlock_writer_unlock
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
Definition: lock.h:206
segment_manager_app_detached
u8 segment_manager_app_detached(segment_manager_t *sm)
Definition: segment_manager.c:67
svm_msg_q_ring_cfg_
Definition: message_queue.h:78
svm_fifo_t
struct _svm_fifo svm_fifo_t
max_log2
static uword max_log2(uword x)
Definition: clib.h:223
segment_manager_get_segment_w_handle
fifo_segment_t * segment_manager_get_segment_w_handle(u64 segment_handle)
Definition: segment_manager.c:290
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
segment_manager_main_::default_app_mq_size
u32 default_app_mq_size
default app msg q size
Definition: segment_manager.c:30
round_pow2
static uword round_pow2(uword x, uword pow2)
Definition: clib.h:279
application_get
application_t * application_get(u32 app_index)
Definition: application.c:710
session_::app_wrk_index
u32 app_wrk_index
Index of the app worker that owns the session.
Definition: session_types.h:191
segment_manager_alloc_session_fifos
int segment_manager_alloc_session_fifos(segment_manager_t *sm, u32 thread_index, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
Definition: segment_manager.c:737
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
segment_manager_app_detach
void segment_manager_app_detach(segment_manager_t *sm)
Definition: segment_manager.c:73
fifo_segment_cleanup
void fifo_segment_cleanup(fifo_segment_t *fs)
Definition: fifo_segment.c:827
svm_queue_free
void svm_queue_free(svm_queue_t *q)
Definition: queue.c:91
segment_manager_event_queue
svm_msg_q_t * segment_manager_event_queue(segment_manager_t *sm)
Definition: segment_manager.c:945
SEG_MANAGER_F_DETACHED_LISTENER
@ SEG_MANAGER_F_DETACHED_LISTENER
Definition: segment_manager.h:48
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
segment_manager_dealloc_fifos
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
Definition: segment_manager.c:825
application_get_segment_manager_properties
segment_manager_props_t * application_get_segment_manager_properties(u32 app_index)
Definition: application.c:1662
segment_manager_del_sessions
void segment_manager_del_sessions(segment_manager_t *sm)
Initiate disconnects for all sessions 'owned' by a segment manager.
Definition: segment_manager.c:596
segment_manager_free
void segment_manager_free(segment_manager_t *sm)
Cleanup segment manager.
Definition: segment_manager.c:471
ssvm_delete
void ssvm_delete(ssvm_private_t *ssvm)
Definition: ssvm.c:445
fifo_segment_msg_q_alloc
svm_msg_q_t * fifo_segment_msg_q_alloc(fifo_segment_t *fs, u32 mq_index, svm_msg_q_cfg_t *cfg)
Allocate message queue on segment.
Definition: fifo_segment.c:1079
segment_manager_props_t
struct _segment_manager_props segment_manager_props_t
vlib_get_thread_index
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:187
app_worker_get_if_valid
app_worker_t * app_worker_get_if_valid(u32 wrk_index)
Definition: application_worker.c:47
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
segment_manager_get_segment_if_valid
static fifo_segment_t * segment_manager_get_segment_if_valid(segment_manager_t *sm, u32 segment_index)
Definition: segment_manager.c:226
segment_manager_format_sessions
void segment_manager_format_sessions(segment_manager_t *sm, int verbose)
Definition: segment_manager.c:1062
fifo_segment_preallocate_fifo_pairs
void fifo_segment_preallocate_fifo_pairs(fifo_segment_t *fs, u32 rx_fifo_size, u32 tx_fifo_size, u32 *n_fifo_pairs)
Pre-allocates fifo pairs in fifo segment.
Definition: fifo_segment.c:1209
FIFO_SEGMENT_F_MEM_LIMIT
@ FIFO_SEGMENT_F_MEM_LIMIT
Definition: fifo_segment.h:40
clib_rwlock_writer_lock
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
Definition: lock.h:192
uword
u64 uword
Definition: types.h:112
segment_manager_segment_reader_unlock
void segment_manager_segment_reader_unlock(segment_manager_t *sm)
Definition: segment_manager.c:324
vlib_thread_is_main_w_barrier
static u8 vlib_thread_is_main_w_barrier(void)
Definition: threads.h:485
fifo_segment_t::flags
u8 flags
private fifo segment flags
Definition: fifo_segment.h:76
segment_manager_get_segment
fifo_segment_t * segment_manager_get_segment(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager's pool without lock.
Definition: segment_manager.c:269
segment_manager_add_segment
int segment_manager_add_segment(segment_manager_t *sm, uword segment_size, u8 notify_app)
Definition: segment_manager.c:186
segment_manager_show_command
static vlib_cli_command_t segment_manager_show_command
(constructor) VLIB_CLI_COMMAND (segment_manager_show_command)
Definition: segment_manager.c:1053
session_handle
static session_handle_t session_handle(session_t *s)
Definition: session_types.h:283
svm_msg_q_cfg_::ring_cfgs
svm_msg_q_ring_cfg_t * ring_cfgs
array of ring cfgs
Definition: message_queue.h:90
segment_manager_segment_handle
u64 segment_manager_segment_handle(segment_manager_t *sm, fifo_segment_t *segment)
Definition: segment_manager.c:275
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
session_get_from_handle
static session_t * session_get_from_handle(session_handle_t handle)
Definition: session.h:357
segment_manager_lock_and_del_segment
void segment_manager_lock_and_del_segment(segment_manager_t *sm, u32 fs_index)
Definition: segment_manager.c:260
segment_manager.h
segment_manager_add_segment_inline
static int segment_manager_add_segment_inline(segment_manager_t *sm, uword segment_size, u8 notify_app, u8 flags)
Adds segment to segment manager's pool.
Definition: segment_manager.c:91
app_name
static char * app_name
Definition: vapi_cpp_test.cpp:33
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
FIFO_SEGMENT_TX_FIFO
@ FIFO_SEGMENT_TX_FIFO
Definition: fifo_segment.h:27
segment_manager_evt_q_expected_size
u32 segment_manager_evt_q_expected_size(u32 q_len)
Definition: segment_manager.c:892
segment_manager_index
u32 segment_manager_index(segment_manager_t *sm)
Definition: segment_manager.c:561
format_memory_size
u8 * format_memory_size(u8 *s, va_list *va)
Definition: std-formats.c:209
session_get
static session_t * session_get(u32 si, u32 thread_index)
Definition: session.h:337
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
svm_msg_q_
Definition: message_queue.h:72
segment_manager_main_::default_fifo_size
u32 default_fifo_size
default rx/tx fifo size
Definition: segment_manager.c:28
clib_rwlock_init
static void clib_rwlock_init(clib_rwlock_t *p)
Definition: lock.h:152
SSVM_SEGMENT_PRIVATE
@ SSVM_SEGMENT_PRIVATE
Definition: ssvm.h:51
format_session
u8 * format_session(u8 *s, va_list *args)
Format stream session as per the following format.
Definition: session_cli.c:101
fifo_segment_t::n_slices
u8 n_slices
number of fifo segment slices
Definition: fifo_segment.h:75
FIFO_SEGMENT_RX_FIFO
@ FIFO_SEGMENT_RX_FIFO
Definition: fifo_segment.h:26
segment_manager_main_::default_segment_size
u32 default_segment_size
default fifo segment size
Definition: segment_manager.c:29
sm_free_w_index_helper
static void sm_free_w_index_helper(void *arg)
Definition: segment_manager.c:505
fifo_segment_t::ssvm
ssvm_private_t ssvm
ssvm segment data
Definition: fifo_segment.h:70
segment_manager_alloc_queue
svm_msg_q_t * segment_manager_alloc_queue(fifo_segment_t *segment, segment_manager_props_t *props)
Allocates shm queue in the first segment.
Definition: segment_manager.c:914
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
index
u32 index
Definition: flow_types.api:221
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
fifo_segment_free_fifo
void fifo_segment_free_fifo(fifo_segment_t *fs, svm_fifo_t *f)
Free fifo allocated in fifo segment.
Definition: fifo_segment.c:919
segment_manager_init_free
void segment_manager_init_free(segment_manager_t *sm)
Initiate segment manager cleanup.
Definition: segment_manager.c:532
app_worker_::connects_seg_manager
u32 connects_seg_manager
Segment manager used for outgoing connects issued by the app.
Definition: application.h:54
segment_manager_get_if_valid
segment_manager_t * segment_manager_get_if_valid(u32 index)
Definition: segment_manager.c:553
u64
unsigned long u64
Definition: types.h:89
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
segment_manager_main_::default_high_watermark
u8 default_high_watermark
default high watermark %
Definition: segment_manager.c:32
ssvm_server_init
int ssvm_server_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
Definition: ssvm.c:433
session_state_t
session_state_t
Definition: session_types.h:143
SESSION_DBG
#define SESSION_DBG(_fmt, _args...)
Definition: session_debug.h:329
session_get_if_valid
static session_t * session_get_if_valid(u64 si, u32 thread_index)
Definition: session.h:344
app_worker_add_segment_notify
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.
Definition: application_worker.c:591
u32
unsigned int u32
Definition: types.h:88
ssvm_type
ssvm_segment_type_t ssvm_type(const ssvm_private_t *ssvm)
Definition: ssvm.c:451
fifo_segment_t::low_watermark
u8 low_watermark
memory pressure watermark low
Definition: fifo_segment.h:78
app_worker_get
app_worker_t * app_worker_get(u32 wrk_index)
Definition: application_worker.c:41
app_worker_
Definition: application.h:32
segment_manager_del_sessions_filter
void segment_manager_del_sessions_filter(segment_manager_t *sm, session_state_t *states)
Initiate disconnects for sessions in specified state 'owned' by a segment manager.
Definition: segment_manager.c:649
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
clib_mem_get_page_size
static_always_inline uword clib_mem_get_page_size(void)
Definition: mem.h:471
segment_manager_dealloc_queue
void segment_manager_dealloc_queue(segment_manager_t *sm, svm_queue_t *q)
Frees shm queue allocated in the first segment.
Definition: segment_manager.c:954
pool_elts
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127
vlib_rpc_call_main_thread
void vlib_rpc_call_main_thread(void *callback, u8 *args, u32 arg_size)
Definition: threads.c:1616
application_name_from_index
const u8 * application_name_from_index(u32 app_index)
Returns app name for app-index.
Definition: application.c:386
segment_manager_main_init
void segment_manager_main_init(void)
Definition: segment_manager.c:975
fifo_segment_available_bytes
uword fifo_segment_available_bytes(fifo_segment_t *fs)
Definition: fifo_segment.c:1415
segment_manager_has_fifos
u8 segment_manager_has_fifos(segment_manager_t *sm)
Definition: segment_manager.c:567
fifo_segment_init
int fifo_segment_init(fifo_segment_t *fs)
Initialize fifo segment shared header.
Definition: fifo_segment.c:296
svm_msg_q_cfg_
Definition: message_queue.h:85
svm_msg_q_cfg_::consumer_pid
int consumer_pid
pid of msg consumer
Definition: message_queue.h:87
segment_manager_cleanup_detached_listener
void segment_manager_cleanup_detached_listener(segment_manager_t *sm)
Definition: segment_manager.c:456
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
FIFO_SEGMENT_F_CUSTOM_USE
@ FIFO_SEGMENT_F_CUSTOM_USE
Definition: fifo_segment.h:41
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
pool_get_zero
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:258
u8
unsigned char u8
Definition: types.h:56
ssvm_private_t::name
u8 * name
Definition: ssvm.h:87
clib_error_t
Definition: clib_error.h:21
session.h
segment_manager_del_segment
void segment_manager_del_segment(segment_manager_t *sm, fifo_segment_t *fs)
Remove segment without lock.
Definition: segment_manager.c:203
i
int i
Definition: flowhash_template.h:376
pool_free
#define pool_free(p)
Free a pool.
Definition: pool.h:447
clib_warning
#define clib_warning(format, args...)
Definition: error.h:59
clib_rwlock_free
static void clib_rwlock_free(clib_rwlock_t *p)
Definition: lock.h:159
segment_manager_main_::default_max_fifo_size
u32 default_max_fifo_size
default max fifo size
Definition: segment_manager.c:31
session_cb_vft_::fifo_tuning_callback
int(* fifo_tuning_callback)(session_t *s, svm_fifo_t *f, session_ft_action_t act, u32 bytes)
Delegate fifo-tuning-logic to application.
Definition: application_interface.h:75
segment_manager_free_safe
void segment_manager_free_safe(segment_manager_t *sm)
Definition: segment_manager.c:517
rv
int __clib_unused rv
Definition: application.c:491
application_::cb_fns
session_cb_vft_t cb_fns
Callbacks: shoulder-taps for the server/client.
Definition: application.h:117
application_::name
u8 * name
Name registered by builtin apps.
Definition: application.h:126
segment_manager_add_segment2
int segment_manager_add_segment2(segment_manager_t *sm, uword segment_size, u8 flags)
Definition: segment_manager.c:193
sm_main
static segment_manager_main_t sm_main
Definition: segment_manager.c:36
segment_manager_main_::seg_name_counter
u32 seg_name_counter
Counter for segment names.
Definition: segment_manager.c:23
app_worker_::app_index
u32 app_index
Index of owning app.
Definition: application.h:43
segment_manager_set_watermarks
void segment_manager_set_watermarks(segment_manager_t *sm, u8 high_watermark, u8 low_watermark)
Definition: segment_manager.c:1126
fifo_segment_prealloc_fifo_hdrs
int fifo_segment_prealloc_fifo_hdrs(fifo_segment_t *fs, u32 slice_index, u32 batch_size)
Try to preallocate fifo headers.
Definition: fifo_segment.c:1175
fifo_segment_t::h
fifo_segment_header_t * h
fifo segment data
Definition: fifo_segment.h:71
vlib_cli_command_t
Definition: cli.h:92
app_worker_::api_client_index
u32 api_client_index
API index for the worker.
Definition: application.h:60
fifo_segment_has_fifos
u8 fifo_segment_has_fifos(fifo_segment_t *fs)
Definition: fifo_segment.c:1438
segment_manager_foreach_segment_w_lock
#define segment_manager_foreach_segment_w_lock(VAR, SM, BODY)
Definition: segment_manager.c:38
fifo_segment_get_slice_fifo_list
svm_fifo_t * fifo_segment_get_slice_fifo_list(fifo_segment_t *fs, u32 slice_index)
Definition: fifo_segment.c:1444
session_::session_state
volatile u8 session_state
State in session layer state machine.
Definition: session_types.h:185
segment_manager_detach_fifo
void segment_manager_detach_fifo(segment_manager_t *sm, svm_fifo_t **f)
Definition: segment_manager.c:868
FIFO_SEGMENT_F_IS_PREALLOCATED
@ FIFO_SEGMENT_F_IS_PREALLOCATED
Definition: fifo_segment.h:38
segment_manager_try_alloc_fifos
int segment_manager_try_alloc_fifos(fifo_segment_t *fifo_segment, u32 thread_index, u32 rx_fifo_size, u32 tx_fifo_size, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
Definition: segment_manager.c:698
fifo_segment_header_::pct_first_alloc
u8 pct_first_alloc
Pct of fifo size to alloc.
Definition: fifo_types.h:144
ssvm_shared_header_t
Definition: ssvm.h:55
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
segment_manager_attach_fifo
void segment_manager_attach_fifo(segment_manager_t *sm, svm_fifo_t **f, session_t *s)
Definition: segment_manager.c:878
format_fifo_segment
format_function_t format_fifo_segment
Definition: fifo_segment.h:345
SEG_MANAGER_F_DETACHED
@ SEG_MANAGER_F_DETACHED
Definition: segment_manager.h:47
application.h
segment_manager_make_segment_handle
u64 segment_manager_make_segment_handle(u32 segment_manager_index, u32 segment_index)
Definition: segment_manager.c:283
app_worker_del_detached_sm
void app_worker_del_detached_sm(app_worker_t *app_wrk, u32 sm_index)
Definition: application_worker.c:237
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105