ip: use thread local vm instead of thread main for vlib_time_now calls
[vpp.git] / src / svm / fifo_segment.c
index 06b7f06..3fd7d9d 100644 (file)
@@ -420,8 +420,11 @@ fs_try_alloc_fifo_freelist_multi_chunk (fifo_segment_header_t * fsh,
   f = fss->free_fifos;
   if (!f)
     {
+      if (PREDICT_FALSE (fsh_n_free_bytes (fsh) < sizeof (svm_fifo_t)))
+       return 0;
+
       void *oldheap = ssvm_push_heap (fsh->ssvm_sh);
-      f = clib_mem_alloc_aligned (sizeof (*f), CLIB_CACHE_LINE_BYTES);
+      f = clib_mem_alloc_aligned_or_null (sizeof (*f), CLIB_CACHE_LINE_BYTES);
       ssvm_pop_heap (oldheap);
       if (!f)
        return 0;
@@ -569,21 +572,27 @@ fs_try_alloc_fifo_batch (fifo_segment_header_t * fsh,
   if (fmem == 0)
     return -1;
 
-  /* Carve fifo + chunk space */
+  /* Carve fifo hdr space */
   for (i = 0; i < batch_size; i++)
     {
       f = (svm_fifo_t *) fmem;
       memset (f, 0, sizeof (*f));
       f->next = fss->free_fifos;
       fss->free_fifos = f;
-      c = (svm_fifo_chunk_t *) (fmem + sizeof (*f));
+      fmem += sizeof (*f);
+    }
+
+  /* Carve chunk space */
+  for (i = 0; i < batch_size; i++)
+    {
+      c = (svm_fifo_chunk_t *) fmem;
       c->start_byte = 0;
       c->length = rounded_data_size;
       c->enq_rb_index = RBTREE_TNIL_INDEX;
       c->deq_rb_index = RBTREE_TNIL_INDEX;
       c->next = fss->free_chunks[fl_index];
       fss->free_chunks[fl_index] = c;
-      fmem += hdrs + rounded_data_size;
+      fmem += sizeof (svm_fifo_chunk_t) + rounded_data_size;
     }
 
   fss->num_chunks[fl_index] += batch_size;