fib: skip byte swap on n_paths in mroute details
[vpp.git] / src / svm / svm_fifo.c
index 971eda3..fda9481 100644 (file)
@@ -747,34 +747,6 @@ f_lookup_clear_deq_chunks (svm_fifo_t * f, svm_fifo_chunk_t * start,
   return c;
 }
 
-void
-svm_fifo_add_chunk (svm_fifo_t * f, svm_fifo_chunk_t * c)
-{
-  svm_fifo_chunk_t *cur, *prev;
-
-  cur = c;
-  prev = f->end_chunk;
-
-  while (cur)
-    {
-      cur->start_byte = prev->start_byte + prev->length;
-      cur->enq_rb_index = RBTREE_TNIL_INDEX;
-      cur->deq_rb_index = RBTREE_TNIL_INDEX;
-
-      prev = cur;
-      cur = cur->next;
-    }
-
-  prev->next = 0;
-  f->end_chunk->next = c;
-  f->end_chunk = prev;
-
-  if (!f->tail_chunk)
-    f->tail_chunk = c;
-
-  return;
-}
-
 void
 svm_fifo_free_chunk_lookup (svm_fifo_t * f)
 {
@@ -823,13 +795,12 @@ svm_fifo_overwrite_head (svm_fifo_t * f, u8 * src, u32 len)
 }
 
 static int
-f_try_grow (svm_fifo_t * f, u32 head, u32 tail, u32 len)
+f_try_chunk_alloc (svm_fifo_t * f, u32 head, u32 tail, u32 len)
 {
-  svm_fifo_chunk_t *c;
+  svm_fifo_chunk_t *c, *cur, *prev;
   u32 alloc_size, free_alloced;
 
   free_alloced = f_chunk_end (f->end_chunk) - tail;
-  ASSERT (free_alloced < len);
 
   alloc_size = clib_min (f->min_alloc, f->size - (tail - head));
   alloc_size = clib_max (alloc_size, len - free_alloced);
@@ -838,7 +809,26 @@ f_try_grow (svm_fifo_t * f, u32 head, u32 tail, u32 len)
   if (PREDICT_FALSE (!c))
     return -1;
 
-  svm_fifo_add_chunk (f, c);
+  cur = c;
+  prev = f->end_chunk;
+
+  while (cur)
+    {
+      cur->start_byte = prev->start_byte + prev->length;
+      cur->enq_rb_index = RBTREE_TNIL_INDEX;
+      cur->deq_rb_index = RBTREE_TNIL_INDEX;
+
+      prev = cur;
+      cur = cur->next;
+    }
+
+  prev->next = 0;
+  f->end_chunk->next = c;
+  f->end_chunk = prev;
+
+  if (!f->tail_chunk)
+    f->tail_chunk = c;
+
   return 0;
 }
 
@@ -863,7 +853,7 @@ svm_fifo_enqueue (svm_fifo_t * f, u32 len, const u8 * src)
 
   if (f_pos_gt (tail + len, f_chunk_end (f->end_chunk)))
     {
-      if (PREDICT_FALSE (f_try_grow (f, head, tail, len)))
+      if (PREDICT_FALSE (f_try_chunk_alloc (f, head, tail, len)))
        {
          len = f_chunk_end (f->end_chunk) - tail;
          if (!len)
@@ -919,7 +909,7 @@ svm_fifo_enqueue_with_offset (svm_fifo_t * f, u32 offset, u32 len, u8 * src)
 
   if (f_pos_gt (enq_pos + len, f_chunk_end (f->end_chunk)))
     {
-      if (PREDICT_FALSE (f_try_grow (f, head, tail, offset + len)))
+      if (PREDICT_FALSE (f_try_chunk_alloc (f, head, tail, offset + len)))
        return SVM_FIFO_EGROW;
     }
 
@@ -1034,6 +1024,10 @@ svm_fifo_dequeue (svm_fifo_t * f, u32 len, u8 * dst)
   svm_fifo_copy_from_chunk (f, f->head_chunk, head, dst, len, &f->head_chunk);
   head = head + len;
 
+  /* In order dequeues are not supported in combination with ooo peeking.
+   * Use svm_fifo_dequeue_drop instead. */
+  ASSERT (rb_tree_n_nodes (&f->ooo_deq_lookup) <= 1);
+
   if (f_pos_geq (head, f_chunk_end (f->start_chunk)))
     fsh_collect_chunks (f->fs_hdr, f->slice_index,
                        f_unlink_chunks (f, head, 0));
@@ -1104,7 +1098,6 @@ svm_fifo_dequeue_drop (svm_fifo_t * f, u32 len)
 /**
  * Drop all data from fifo
  *
- * Should be called only from vpp side because of lookup cleanup
  */
 void
 svm_fifo_dequeue_drop_all (svm_fifo_t * f)
@@ -1136,7 +1129,7 @@ svm_fifo_fill_chunk_list (svm_fifo_t * f)
   if (f_chunk_end (f->end_chunk) - head >= f->size)
     return 0;
 
-  if (f_try_grow (f, head, tail, f->size - (tail - head)))
+  if (f_try_chunk_alloc (f, head, tail, f->size - (tail - head)))
     return SVM_FIFO_EGROW;
 
   return 0;
@@ -1414,7 +1407,7 @@ svm_fifo_replay (u8 * s, svm_fifo_t * f, u8 no_read, u8 verbose)
   u8 *data = 0;
   svm_fifo_trace_elem_t *trace;
   u32 offset;
-  svm_fifo_t *dummy_fifo;
+  svm_fifo_t *placeholder_fifo;
 
   if (!f)
     return s;
@@ -1427,7 +1420,7 @@ svm_fifo_replay (u8 * s, svm_fifo_t * f, u8 no_read, u8 verbose)
   trace_len = 0;
 #endif
 
-  dummy_fifo = svm_fifo_alloc (f->size);
+  placeholder_fifo = svm_fifo_alloc (f->size);
   svm_fifo_init (f, f->size);
   clib_memset (f->head_chunk->data, 0xFF, f->size);
   vec_validate (data, f->size);
@@ -1442,26 +1435,26 @@ svm_fifo_replay (u8 * s, svm_fifo_t * f, u8 no_read, u8 verbose)
          if (verbose)
            s = format (s, "adding [%u, %u]:", trace[i].offset,
                        (trace[i].offset + trace[i].len));
-         svm_fifo_enqueue_with_offset (dummy_fifo, trace[i].offset,
+         svm_fifo_enqueue_with_offset (placeholder_fifo, trace[i].offset,
                                        trace[i].len, &data[offset]);
        }
       else if (trace[i].action == 2)
        {
          if (verbose)
            s = format (s, "adding [%u, %u]:", 0, trace[i].len);
-         svm_fifo_enqueue (dummy_fifo, trace[i].len, &data[offset]);
+         svm_fifo_enqueue (placeholder_fifo, trace[i].len, &data[offset]);
        }
       else if (!no_read)
        {
          if (verbose)
            s = format (s, "read: %u", trace[i].len);
-         svm_fifo_dequeue_drop (dummy_fifo, trace[i].len);
+         svm_fifo_dequeue_drop (placeholder_fifo, trace[i].len);
        }
       if (verbose)
-       s = format (s, "%U", format_svm_fifo, dummy_fifo, 1);
+       s = format (s, "%U", format_svm_fifo, placeholder_fifo, 1);
     }
 
-  s = format (s, "result: %U", format_svm_fifo, dummy_fifo, 1);
+  s = format (s, "result: %U", format_svm_fifo, placeholder_fifo, 1);
 
   return s;
 }