FD.io VPP  v19.01.2-3-gf61a1a8
Vector Packet Processing
svm_fifo_segment.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <svm/svm_fifo_segment.h>
17 
18 static void
20  u32 data_size_in_bytes, int chunk_size)
21 {
22  int freelist_index;
23  u32 size;
24  u8 *fifo_space;
25  u32 rounded_data_size;
26  svm_fifo_t *f;
27  int i;
28 
29  rounded_data_size = (1 << (max_log2 (data_size_in_bytes)));
30  freelist_index = max_log2 (rounded_data_size)
32 
33  /* Calculate space requirement $$$ round-up data_size_in_bytes */
34  size = (sizeof (*f) + rounded_data_size) * chunk_size;
35 
36  /* Allocate fifo space. May fail. */
38  (size, CLIB_CACHE_LINE_BYTES, 0 /* align_offset */ ,
39  0 /* os_out_of_memory */ );
40 
41  /* Out of space.. */
42  if (fifo_space == 0)
43  return;
44 
45  /* Carve fifo space */
46  f = (svm_fifo_t *) fifo_space;
47  for (i = 0; i < chunk_size; i++)
48  {
49  f->freelist_index = freelist_index;
50  f->next = fsh->free_fifos[freelist_index];
51  fsh->free_fifos[freelist_index] = f;
52  fifo_space += sizeof (*f) + rounded_data_size;
53  f = (svm_fifo_t *) fifo_space;
54  }
55 }
56 
57 /**
58  * Pre-allocates fifo pairs in fifo segment
59  *
60  * The number of fifos pre-allocated is the minimum of the requested number
61  * of pairs and the maximum number that fit within the segment. If the maximum
62  * is hit, the number of fifo pairs requested is updated by subtracting the
63  * number of fifos that have been successfully allocated.
64  */
65 void
67  u32 rx_fifo_size, u32 tx_fifo_size,
68  u32 * n_fifo_pairs)
69 {
70  u32 rx_rounded_data_size, tx_rounded_data_size, pair_size;
71  u32 rx_fifos_size, tx_fifos_size, pairs_to_allocate;
72  int rx_freelist_index, tx_freelist_index;
73  ssvm_shared_header_t *sh = s->ssvm.sh;
74  svm_fifo_segment_header_t *fsh = s->h;
75  u8 *rx_fifo_space, *tx_fifo_space;
76  uword space_available;
77  void *oldheap;
78  svm_fifo_t *f;
79  int i;
80 
81  /* Parameter check */
82  if (rx_fifo_size == 0 || tx_fifo_size == 0 || *n_fifo_pairs == 0)
83  return;
84 
85  if (rx_fifo_size < FIFO_SEGMENT_MIN_FIFO_SIZE ||
86  rx_fifo_size > FIFO_SEGMENT_MAX_FIFO_SIZE)
87  {
88  clib_warning ("rx fifo_size out of range %d", rx_fifo_size);
89  return;
90  }
91 
92  if (tx_fifo_size < FIFO_SEGMENT_MIN_FIFO_SIZE ||
93  tx_fifo_size > FIFO_SEGMENT_MAX_FIFO_SIZE)
94  {
95  clib_warning ("tx fifo_size out of range %d", rx_fifo_size);
96  return;
97  }
98 
99  rx_rounded_data_size = (1 << (max_log2 (rx_fifo_size)));
100  rx_freelist_index = max_log2 (rx_fifo_size)
102  tx_rounded_data_size = (1 << (max_log2 (tx_fifo_size)));
103  tx_freelist_index = max_log2 (tx_fifo_size)
105 
106  /* Calculate space requirements */
107  pair_size = 2 * sizeof (*f) + rx_rounded_data_size + tx_rounded_data_size;
108 #if USE_DLMALLOC == 0
109  space_available = s->ssvm.ssvm_size - mheap_bytes (sh->heap);
110 #else
111  space_available = s->ssvm.ssvm_size - mspace_usable_size (sh->heap);
112 #endif
113 
114  pairs_to_allocate = clib_min (space_available / pair_size, *n_fifo_pairs);
115  rx_fifos_size = (sizeof (*f) + rx_rounded_data_size) * pairs_to_allocate;
116  tx_fifos_size = (sizeof (*f) + tx_rounded_data_size) * pairs_to_allocate;
117 
119  clib_max (rx_freelist_index, tx_freelist_index),
120  0);
121 
122  oldheap = ssvm_push_heap (sh);
123  /* Allocate rx fifo space. May fail. */
124  rx_fifo_space = clib_mem_alloc_aligned_at_offset
125  (rx_fifos_size, CLIB_CACHE_LINE_BYTES, 0 /* align_offset */ ,
126  0 /* os_out_of_memory */ );
127 
128  /* Same for TX */
129  tx_fifo_space = clib_mem_alloc_aligned_at_offset
130  (tx_fifos_size, CLIB_CACHE_LINE_BYTES, 0 /* align_offset */ ,
131  0 /* os_out_of_memory */ );
132 
133  /* Make sure it worked. Clean up if it didn't... */
134  if (rx_fifo_space == 0 || tx_fifo_space == 0)
135  {
136  if (rx_fifo_space)
137  clib_mem_free (rx_fifo_space);
138  else
139  clib_warning ("rx fifo preallocation failure: size %d npairs %d",
140  rx_fifo_size, *n_fifo_pairs);
141 
142  if (tx_fifo_space)
143  clib_mem_free (tx_fifo_space);
144  else
145  clib_warning ("tx fifo preallocation failure: size %d nfifos %d",
146  tx_fifo_size, *n_fifo_pairs);
147  ssvm_pop_heap (oldheap);
148  return;
149  }
150 
151  /* Carve rx fifo space */
152  f = (svm_fifo_t *) rx_fifo_space;
153  for (i = 0; i < pairs_to_allocate; i++)
154  {
155  f->freelist_index = rx_freelist_index;
156  f->next = fsh->free_fifos[rx_freelist_index];
157  fsh->free_fifos[rx_freelist_index] = f;
158  rx_fifo_space += sizeof (*f) + rx_rounded_data_size;
159  f = (svm_fifo_t *) rx_fifo_space;
160  }
161  /* Carve tx fifo space */
162  f = (svm_fifo_t *) tx_fifo_space;
163  for (i = 0; i < pairs_to_allocate; i++)
164  {
165  f->freelist_index = tx_freelist_index;
166  f->next = fsh->free_fifos[tx_freelist_index];
167  fsh->free_fifos[tx_freelist_index] = f;
168  tx_fifo_space += sizeof (*f) + tx_rounded_data_size;
169  f = (svm_fifo_t *) tx_fifo_space;
170  }
171 
172  /* Account for the pairs allocated */
173  *n_fifo_pairs -= pairs_to_allocate;
174  ssvm_pop_heap (oldheap);
175 }
176 
177 /**
178  * Initialize svm fifo segment shared header
179  */
180 int
182 {
185  void *oldheap;
186 
187  sh = s->ssvm.sh;
188  oldheap = ssvm_push_heap (sh);
189 
190  fsh = clib_mem_alloc (sizeof (*fsh));
191  clib_memset (fsh, 0, sizeof (*fsh));
192  s->h = sh->opaque[0] = fsh;
193 
194  ssvm_pop_heap (oldheap);
195 
196  sh->ready = 1;
197  return (0);
198 }
199 
200 /**
201  * Create an svm fifo segment and initialize as master
202  */
203 int
206 {
208  int rv;
209 
210  /* Allocate a fresh segment */
211  pool_get (sm->segments, s);
212  clib_memset (s, 0, sizeof (*s));
213 
214  s->ssvm.ssvm_size = a->segment_size;
215  s->ssvm.i_am_master = 1;
216  s->ssvm.my_pid = getpid ();
217  s->ssvm.name = format (0, "%s%c", a->segment_name, 0);
218  s->ssvm.requested_va = sm->next_baseva;
219 
220  if ((rv = ssvm_master_init (&s->ssvm, a->segment_type)))
221  {
222  pool_put (sm->segments, s);
223  return (rv);
224  }
225 
226  /* Note: requested_va updated due to seg base addr randomization */
227  sm->next_baseva = s->ssvm.sh->ssvm_va + a->segment_size;
228 
230  vec_add1 (a->new_segment_indices, s - sm->segments);
231  return (0);
232 }
233 
234 /**
235  * Create an svm fifo segment in process-private memory
236  */
237 int
240 {
243  u32 rnd_size = 0;
244  u8 *heap;
245  u32 pagesize = clib_mem_get_page_size ();
246 
247  pool_get (sm->segments, s);
248  clib_memset (s, 0, sizeof (*s));
249 
250  rnd_size = (a->segment_size + (pagesize - 1)) & ~pagesize;
251 
252 #if USE_DLMALLOC == 0
253  heap = mheap_alloc (0, rnd_size);
254  if (heap == 0)
255  {
256  clib_unix_warning ("mheap alloc");
257  pool_put (sm->segments, s);
258  return -1;
259  }
260  {
262  heap_header = mheap_header (heap);
263  heap_header->flags |= MHEAP_FLAG_THREAD_SAFE;
264  }
265 #else
266  heap = create_mspace (rnd_size, 1 /* locked */ );
267 #endif
268 
269  s->ssvm.ssvm_size = rnd_size;
270  s->ssvm.i_am_master = 1;
271  s->ssvm.my_pid = getpid ();
272  s->ssvm.name = format (0, "%s%c", a->segment_name, 0);
273  s->ssvm.requested_va = ~0;
274 
275  /* Allocate a [sic] shared memory header, in process memory... */
276  sh = clib_mem_alloc_aligned (sizeof (*sh), CLIB_CACHE_LINE_BYTES);
277  s->ssvm.sh = sh;
278 
279  clib_memset (sh, 0, sizeof (*sh));
280  sh->heap = heap;
281 
283  vec_add1 (a->new_segment_indices, s - sm->segments);
284 
285  return (0);
286 }
287 
288 /**
289  * Attach as slave to an svm fifo segment
290  */
291 int
294 {
296  int rv;
297 
298  /* Allocate a fresh segment */
299  pool_get (sm->segments, s);
300  clib_memset (s, 0, sizeof (*s));
301 
302  s->ssvm.ssvm_size = a->segment_size;
303  s->ssvm.my_pid = getpid ();
304  s->ssvm.name = format (0, "%s%c", a->segment_name, 0);
305  s->ssvm.requested_va = sm->next_baseva;
307  s->ssvm.fd = a->memfd_fd;
308  else
310 
311  if ((rv = ssvm_slave_init (&s->ssvm, a->segment_type)))
312  {
313  _vec_len (s) = vec_len (s) - 1;
314  return (rv);
315  }
316 
317  /* Fish the segment header */
318  s->h = s->ssvm.sh->opaque[0];
319 
320  vec_add1 (a->new_segment_indices, s - sm->segments);
321  return (0);
322 }
323 
324 void
327 {
328  ssvm_delete (&s->ssvm);
329  clib_memset (s, 0xfe, sizeof (*s));
330  pool_put (sm->segments, s);
331 }
332 
333 /**
334  * Allocate fifo in svm segment
335  */
336 svm_fifo_t *
338  u32 data_size_in_bytes,
339  svm_fifo_segment_freelist_t list_index)
340 {
343  svm_fifo_t *f = 0;
344  void *oldheap;
345  int freelist_index;
346 
347  /*
348  * 4K minimum. It's not likely that anything good will happen
349  * with a smaller FIFO.
350  */
351  if (data_size_in_bytes < FIFO_SEGMENT_MIN_FIFO_SIZE ||
352  data_size_in_bytes > FIFO_SEGMENT_MAX_FIFO_SIZE)
353  {
354  clib_warning ("fifo size out of range %d", data_size_in_bytes);
355  return 0;
356  }
357 
358  freelist_index = max_log2 (data_size_in_bytes)
360 
361  sh = fs->ssvm.sh;
362  ssvm_lock_non_recursive (sh, 1);
363  fsh = (svm_fifo_segment_header_t *) sh->opaque[0];
364 
365  switch (list_index)
366  {
369  vec_validate_init_empty (fsh->free_fifos, freelist_index, 0);
370  f = fsh->free_fifos[freelist_index];
371  if (PREDICT_FALSE (!f))
372  {
373  /* Preallocated and no fifo left. Don't even try */
375  goto done;
376 
377  oldheap = ssvm_push_heap (sh);
378  allocate_new_fifo_chunk (fsh, data_size_in_bytes,
380  ssvm_pop_heap (oldheap);
381  f = fsh->free_fifos[freelist_index];
382  }
383  if (PREDICT_TRUE (f != 0))
384  {
385  fsh->free_fifos[freelist_index] = f->next;
386  /* (re)initialize the fifo, as in svm_fifo_create */
387  clib_memset (f, 0, sizeof (*f));
388  f->nitems = data_size_in_bytes;
389  f->ooos_list_head = OOO_SEGMENT_INVALID_INDEX;
390  f->ct_session_index = SVM_FIFO_INVALID_SESSION_INDEX;
391  f->refcnt = 1;
392  f->freelist_index = freelist_index;
393  goto found;
394  }
395  break;
397  break;
398 
399  default:
400  clib_warning ("ignore bogus freelist %d", list_index);
401  break;
402  }
403 
404  /* Catch all that allocates just one fifo. Note: this can fail,
405  * in which case: create another segment */
406  oldheap = ssvm_push_heap (sh);
407  f = svm_fifo_create (data_size_in_bytes);
408  ssvm_pop_heap (oldheap);
409  if (PREDICT_FALSE (f == 0))
410  goto done;
411  f->freelist_index = freelist_index;
412 
413 found:
414  /* If rx_freelist add to active fifos list. When cleaning up segment,
415  * we need a list of active sessions that should be disconnected. Since
416  * both rx and tx fifos keep pointers to the session, it's enough to track
417  * only one. */
418  if (list_index == FIFO_SEGMENT_RX_FREELIST)
419  {
420  if (fsh->fifos)
421  {
422  fsh->fifos->prev = f;
423  f->next = fsh->fifos;
424  }
425  fsh->fifos = f;
426  }
427  fsh->n_active_fifos++;
428 
429 done:
431  return (f);
432 }
433 
434 void
436  svm_fifo_segment_freelist_t list_index)
437 {
440  void *oldheap;
441  int freelist_index;
442 
443  ASSERT (f->refcnt > 0);
444 
445  if (--f->refcnt > 0)
446  return;
447 
448  sh = s->ssvm.sh;
449  fsh = (svm_fifo_segment_header_t *) sh->opaque[0];
450 
451  freelist_index = f->freelist_index;
452 
453  ASSERT (freelist_index < vec_len (fsh->free_fifos));
454 
455  ssvm_lock_non_recursive (sh, 2);
456  oldheap = ssvm_push_heap (sh);
457 
458  switch (list_index)
459  {
461  /* Remove from active list */
462  if (f->prev)
463  f->prev->next = f->next;
464  else
465  fsh->fifos = f->next;
466  if (f->next)
467  f->next->prev = f->prev;
468  /* Fall through: we add only rx fifos to active pool */
470  /* Add to free list */
471  f->next = fsh->free_fifos[freelist_index];
472  f->prev = 0;
473  fsh->free_fifos[freelist_index] = f;
474  break;
476  break;
477 
478  default:
479  clib_warning ("ignore bogus freelist %d", list_index);
480  break;
481  }
482 
483  if (CLIB_DEBUG)
484  {
485  f->master_session_index = ~0;
486  f->master_thread_index = ~0;
487  }
488 
489  fsh->n_active_fifos--;
490  ssvm_pop_heap (oldheap);
492 }
493 
494 void
496  u32 timeout_in_seconds)
497 {
498  sm->next_baseva = baseva;
499  sm->timeout_in_seconds = timeout_in_seconds;
500 }
501 
502 u32
505 {
506  return s - sm->segments;
507 }
508 
509 /**
510  * Retrieve svm segments pool. Used only for debug purposes.
511  */
514 {
515  return sm->segments;
516 }
517 
518 /**
519  * Get number of active fifos
520  */
521 u32
523 {
524  return fifo_segment->h->n_active_fifos;
525 }
526 
527 u32
529  u32 fifo_size_in_bytes)
530 {
533  svm_fifo_t *f;
534  int i;
535  u32 count = 0, rounded_data_size, freelist_index;
536 
537  sh = fifo_segment->ssvm.sh;
538  fsh = (svm_fifo_segment_header_t *) sh->opaque[0];
539 
540  /* Count all free fifos? */
541  if (fifo_size_in_bytes == ~0)
542  {
543  for (i = 0; i < vec_len (fsh->free_fifos); i++)
544  {
545  f = fsh->free_fifos[i];
546  if (f == 0)
547  continue;
548 
549  while (f)
550  {
551  f = f->next;
552  count++;
553  }
554  }
555  return count;
556  }
557 
558  rounded_data_size = (1 << (max_log2 (fifo_size_in_bytes)));
559  freelist_index = max_log2 (rounded_data_size)
561 
562  if (freelist_index >= vec_len (fsh->free_fifos))
563  return 0;
564 
565  f = fsh->free_fifos[freelist_index];
566  if (f == 0)
567  return 0;
568 
569  while (f)
570  {
571  f = f->next;
572  count++;
573  }
574  return count;
575 }
576 
577 void
579  size_t * size)
580 {
581  if (ssvm_type (&seg->ssvm) == SSVM_SEGMENT_PRIVATE)
582  {
583 #if USE_DLMALLOC == 0
585 
586  *address = pointer_to_uword (seg->ssvm.sh->heap);
587  heap_header = mheap_header (seg->ssvm.sh->heap);
588  *size = heap_header->max_size;
589 #else
590  mspace_get_address_and_size (seg->ssvm.sh->heap, address, size);
591 #endif
592  }
593  else
594  {
595  *address = (char *) seg->ssvm.sh->ssvm_va;
596  *size = seg->ssvm.ssvm_size;
597  }
598 }
599 
600 void *
602 {
603  return seg->ssvm.sh->heap;
604 }
605 
606 u8 *
607 format_svm_fifo_segment_type (u8 * s, va_list * args)
608 {
610  sp = va_arg (*args, svm_fifo_segment_private_t *);
611  ssvm_segment_type_t st = ssvm_type (&sp->ssvm);
612 
613  if (st == SSVM_SEGMENT_PRIVATE)
614  s = format (s, "%s", "private-heap");
615  else if (st == SSVM_SEGMENT_MEMFD)
616  s = format (s, "%s", "memfd");
617  else if (st == SSVM_SEGMENT_SHM)
618  s = format (s, "%s", "shm");
619  else
620  s = format (s, "%s", "unknown");
621  return s;
622 }
623 
624 /**
625  * Segment format function
626  */
627 u8 *
628 format_svm_fifo_segment (u8 * s, va_list * args)
629 {
631  = va_arg (*args, svm_fifo_segment_private_t *);
632  int verbose __attribute__ ((unused)) = va_arg (*args, int);
633  svm_fifo_segment_header_t *fsh = sp->h;
634  u32 count, indent;
635  svm_fifo_t *f;
636  int i;
637 
638  indent = format_get_indent (s) + 2;
639 #if USE_DLMALLOC == 0
640  s = format (s, "%U segment heap: %U\n", format_white_space, indent,
641  format_mheap, svm_fifo_segment_heap (sp), verbose);
642  s = format (s, "%U segment has %u active fifos\n",
644 #endif
645 
646  for (i = 0; i < vec_len (fsh->free_fifos); i++)
647  {
648  f = fsh->free_fifos[i];
649  if (f == 0)
650  continue;
651  count = 0;
652  while (f)
653  {
654  f = f->next;
655  count++;
656  }
657 
658  s = format (s, "%U%-5u Kb: %u free",
659  format_white_space, indent + 2,
660  1 << (i + max_log2 (FIFO_SEGMENT_MIN_FIFO_SIZE) - 10),
661  count);
662  }
663  return s;
664 }
665 
666 /*
667  * fd.io coding-style-patch-verification: ON
668  *
669  * Local Variables:
670  * eval: (c-set-style "gnu")
671  * End:
672  */
u64 ssvm_size
Definition: ssvm.h:84
void svm_fifo_segment_info(svm_fifo_segment_private_t *seg, char **address, size_t *size)
typedef address
Definition: ip_types.api:30
#define clib_min(x, y)
Definition: clib.h:295
uword requested_va
Definition: ssvm.h:87
static void * clib_mem_alloc_aligned_at_offset(uword size, uword align, uword align_offset, int os_out_of_memory_on_failure)
Definition: mem.h:81
a
Definition: bitmap.h:538
#define PREDICT_TRUE(x)
Definition: clib.h:112
volatile u32 ready
Definition: ssvm.h:76
unsigned long u64
Definition: types.h:89
void * mheap_alloc(void *memory, uword size)
Definition: mheap.c:963
svm_fifo_segment_freelist_t
void * opaque[SSVM_N_OPAQUE]
Definition: ssvm.h:73
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:525
#define FIFO_SEGMENT_F_IS_PREALLOCATED
int i
static mheap_t * mheap_header(u8 *v)
static u32 format_get_indent(u8 *s)
Definition: format.h:72
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
ssvm_shared_header_t * sh
Definition: ssvm.h:83
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
#define MHEAP_FLAG_THREAD_SAFE
#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.
unsigned char u8
Definition: types.h:56
void ssvm_delete(ssvm_private_t *ssvm)
Definition: ssvm.c:423
struct _svm_fifo svm_fifo_t
enum ssvm_segment_type_ ssvm_segment_type_t
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
Definition: ssvm.h:144
unsigned int u32
Definition: types.h:88
int attach_timeout
shm segments attach timeout (sec)
Definition: ssvm.h:93
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
#define FIFO_SEGMENT_MIN_FIFO_SIZE
ssvm_segment_type_t segment_type
u8 * format_svm_fifo_segment_type(u8 *s, va_list *args)
u8 * format_mheap(u8 *s, va_list *va)
Definition: mem_dlmalloc.c:354
u32 svm_fifo_segment_num_fifos(svm_fifo_segment_private_t *fifo_segment)
Get number of active fifos.
uword size
uword clib_mem_get_page_size(void)
Definition: mem.c:51
svm_fifo_t * fifos
Linked list of active RX fifos.
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
svm_fifo_t ** free_fifos
Freelists, by fifo size.
#define PREDICT_FALSE(x)
Definition: clib.h:111
svm_fifo_segment_header_t * h
#define FIFO_SEGMENT_ALLOC_CHUNK_SIZE
int svm_fifo_segment_attach(svm_fifo_segment_main_t *sm, svm_fifo_segment_create_args_t *a)
Attach as slave to an svm fifo segment.
void svm_fifo_segment_delete(svm_fifo_segment_main_t *sm, svm_fifo_segment_private_t *s)
DLMALLOC_EXPORT mspace create_mspace(size_t capacity, int locked)
DLMALLOC_EXPORT void mspace_get_address_and_size(mspace msp, char **addrp, size_t *sizep)
u32 n_active_fifos
Number of active fifos.
int svm_fifo_segment_create_process_private(svm_fifo_segment_main_t *sm, svm_fifo_segment_create_args_t *a)
Create an svm fifo segment in process-private memory.
#define clib_warning(format, args...)
Definition: error.h:59
static void allocate_new_fifo_chunk(svm_fifo_segment_header_t *fsh, u32 data_size_in_bytes, int chunk_size)
int ssvm_slave_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
Definition: ssvm.c:417
u32 my_pid
Definition: ssvm.h:85
#define OOO_SEGMENT_INVALID_INDEX
Definition: svm_fifo.h:40
int fd
memfd segments
Definition: ssvm.h:92
#define FIFO_SEGMENT_MAX_FIFO_SIZE
int svm_fifo_segment_create(svm_fifo_segment_main_t *sm, svm_fifo_segment_create_args_t *a)
Create an svm fifo segment and initialize as master.
#define ASSERT(truth)
void * svm_fifo_segment_heap(svm_fifo_segment_private_t *seg)
u32 svm_fifo_segment_index(svm_fifo_segment_main_t *sm, svm_fifo_segment_private_t *s)
static void clib_mem_free(void *p)
Definition: mem.h:205
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.
size_t count
Definition: vapi.c:47
static heap_header_t * heap_header(void *v)
Definition: heap.h:161
static void * clib_mem_alloc(uword size)
Definition: mem.h:132
static uword pointer_to_uword(const void *p)
Definition: types.h:131
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
uword mheap_bytes(void *v)
Definition: mheap.c:1069
DLMALLOC_EXPORT size_t mspace_usable_size(const void *mem)
svm_fifo_segment_private_t * segments
pool of segments
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static uword max_log2(uword x)
Definition: clib.h:191
u64 uword
Definition: types.h:112
#define clib_unix_warning(format, args...)
Definition: error.h:68
int svm_fifo_segment_init(svm_fifo_segment_private_t *s)
Initialize svm fifo segment shared header.
static void * clib_mem_alloc_aligned(uword size, uword align)
Definition: mem.h:140
u32 svm_fifo_segment_num_free_fifos(svm_fifo_segment_private_t *fifo_segment, u32 fifo_size_in_bytes)
#define SVM_FIFO_INVALID_SESSION_INDEX
Definition: svm_fifo.h:41
static void ssvm_unlock_non_recursive(ssvm_shared_header_t *h)
Definition: ssvm.h:136
void svm_fifo_segment_main_init(svm_fifo_segment_main_t *sm, u64 baseva, u32 timeout_in_seconds)
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:488
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
u8 * format_svm_fifo_segment(u8 *s, va_list *args)
Segment format function.
svm_fifo_segment_private_t * svm_fifo_segment_segments_pool(svm_fifo_segment_main_t *sm)
Retrieve svm segments pool.
int i_am_master
Definition: ssvm.h:88
static void ssvm_lock_non_recursive(ssvm_shared_header_t *h, u32 tag)
Definition: ssvm.h:115
ssvm_segment_type_t ssvm_type(const ssvm_private_t *ssvm)
Definition: ssvm.c:429
svm_fifo_t * svm_fifo_create(u32 data_size_in_bytes)
create an svm fifo, in the current heap.
Definition: svm_fifo.c:205