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