FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
svm_fifo.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2019 Cisco and/or its affiliates.
3  * Copyright (c) 2019 Arm Limited
4  * Copyright (c) 2010-2017 Intel Corporation and/or its affiliates.
5  * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
6  * Inspired from DPDK rte_ring.h (SPSC only) (derived from freebsd bufring.h).
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at:
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 #ifndef __included_ssvm_fifo_h__
20 #define __included_ssvm_fifo_h__
21 
22 #include <vppinfra/clib.h>
23 #include <vppinfra/vec.h>
24 #include <vppinfra/pool.h>
25 #include <vppinfra/format.h>
26 #include <svm/fifo_types.h>
27 
28 #define OOO_SEGMENT_INVALID_INDEX ((u32)~0)
29 #define SVM_FIFO_INVALID_SESSION_INDEX ((u32)~0)
30 #define SVM_FIFO_INVALID_INDEX ((u32)~0)
31 
32 typedef enum svm_fifo_deq_ntf_
33 {
34  SVM_FIFO_NO_DEQ_NOTIF = 0, /**< No notification requested */
35  SVM_FIFO_WANT_DEQ_NOTIF = 1, /**< Notify on dequeue */
36  SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL = 2, /**< Notify on transition from full */
37  SVM_FIFO_WANT_DEQ_NOTIF_IF_EMPTY = 4, /**< Notify on transition to empty */
39 
40 typedef enum svm_fifo_flag_
41 {
44 
45 typedef enum
46 {
51 
52 typedef struct svm_fifo_seg_
53 {
54  u8 *data;
57 
58 #if SVM_FIFO_TRACE
59 #define svm_fifo_trace_add(_f, _s, _l, _t) \
60 { \
61  svm_fifo_trace_elem_t *trace_elt; \
62  vec_add2(_f->trace, trace_elt, 1); \
63  trace_elt->offset = _s; \
64  trace_elt->len = _l; \
65  trace_elt->action = _t; \
66 }
67 #else
68 #define svm_fifo_trace_add(_f, _s, _l, _t)
69 #endif
70 
72 u8 *svm_fifo_replay (u8 * s, svm_fifo_t * f, u8 no_read, u8 verbose);
73 
74 /**
75  * Load head and tail optimized for consumer
76  *
77  * Internal function.
78  */
79 static inline void
81 {
82  /* load-relaxed: consumer owned index */
83  *head = f->shr->head;
84  /* load-acq: consumer foreign index (paired with store-rel in producer) */
85  *tail = clib_atomic_load_acq_n (&f->shr->tail);
86 }
87 
88 /** Load head and tail optimized for producer
89  *
90  * Internal function
91  */
92 static inline void
94 {
95  /* load relaxed: producer owned index */
96  *tail = f->shr->tail;
97  /* load-acq: producer foreign index (paired with store-rel in consumer) */
98  *head = clib_atomic_load_acq_n (&f->shr->head);
99 }
100 
101 /**
102  * Load head and tail independent of producer/consumer role
103  *
104  * Internal function.
105  */
106 static inline void
108 {
109  /* load-acq : consumer foreign index (paired with store-rel) */
110  *tail = clib_atomic_load_acq_n (&f->shr->tail);
111  /* load-acq : producer foriegn index (paired with store-rel) */
112  *head = clib_atomic_load_acq_n (&f->shr->head);
113 }
114 
115 /**
116  * Fifo current size, i.e., number of bytes enqueued
117  *
118  * Internal function.
119  */
120 static inline u32
121 f_cursize (svm_fifo_t * f, u32 head, u32 tail)
122 {
123  return tail - head;
124 }
125 
126 /**
127  * Fifo free bytes, i.e., number of free bytes
128  *
129  * Internal function
130  */
131 static inline u32
132 f_free_count (svm_fifo_t * f, u32 head, u32 tail)
133 {
134  return (f->shr->size - f_cursize (f, head, tail));
135 }
136 
139 {
140  return c->start_byte + c->length;
141 }
142 
143 always_inline int
145 {
146  return ((i32) (a - b) < 0);
147 }
148 
149 always_inline int
151 {
152  return ((i32) (a - b) <= 0);
153 }
154 
155 always_inline int
157 {
158  return ((i32) (a - b) > 0);
159 }
160 
161 always_inline int
163 {
164  return ((i32) (a - b) >= 0);
165 }
166 
169 {
170  return (f_pos_geq (pos, c->start_byte)
171  && f_pos_lt (pos, c->start_byte + c->length));
172 }
173 
176 {
177  return fs_chunk_ptr (f->fs_hdr, f->shr->start_chunk);
178 }
179 
182 {
183  return fs_chunk_ptr (f->fs_hdr, f->shr->end_chunk);
184 }
185 
188 {
189  return fs_chunk_ptr (f->fs_hdr, f->shr->head_chunk);
190 }
191 
194 {
195  return fs_chunk_ptr (f->fs_hdr, f->shr->tail_chunk);
196 }
197 
200 {
201  return fs_chunk_ptr (f->fs_hdr, cp);
202 }
203 
206 {
207  return fs_chunk_sptr (f->fs_hdr, c);
208 }
209 
210 always_inline void
212 {
213  fs_chunk_ptr (f->fs_hdr, cp)->next = fs_chunk_sptr (f->fs_hdr, c);
214 }
215 
216 /**
217  * Create fifo of requested size
218  *
219  * Allocates fifo on current heap.
220  *
221  * @param size data size in bytes for fifo to be allocated. Will be
222  * rounded to the next highest power-of-two value.
223  * @return pointer to new fifo
224  */
226 /**
227  * Initialize fifo
228  *
229  * @param f fifo
230  * @param size size for fifo
231  */
232 void svm_fifo_init (svm_fifo_t * f, u32 size);
233 /**
234  * Allocate a fifo chunk on heap
235  *
236  * If the chunk is allocated on a fifo segment, this should be called
237  * with the segment's heap pushed.
238  *
239  * @param size chunk size in bytes. Will be rounded to the next highest
240  * power-of-two
241  * @return new chunk or 0 if alloc failed
242  */
244 /**
245  * Ensure the whole fifo size is writeable
246  *
247  * Allocates enough chunks to cover the whole fifo size.
248  *
249  * @param f fifo
250  */
252 /**
253  * Provision and return chunks for number of bytes requested
254  *
255  * Allocates enough chunks to cover the bytes requested and returns them
256  * in the fifo segment array. The number of bytes provisioned may be less
257  * than requested if not enough segments were provided.
258  *
259  * @param f fifo
260  * @param fs array of fifo segments
261  * @param n_segs length of fifo segments array
262  * @param len number of bytes to preallocate
263  * @return number of fifo segments provisioned or error
264  */
266  u32 len);
267 /**
268  * Initialize rbtrees used for ooo lookups
269  *
270  * @param f fifo
271  * @param ooo_type type of ooo operation (0 enqueue, 1 dequeue)
272  */
273 void svm_fifo_init_ooo_lookup (svm_fifo_t * f, u8 ooo_type);
274 /**
275  * Free fifo and associated state
276  *
277  * @param f fifo
278  */
279 void svm_fifo_free (svm_fifo_t * f);
280 /**
281  * Cleanup fifo chunk lookup rb tree
282  *
283  * The rb tree is allocated in segment heap so this should be called
284  * with it pushed.
285  *
286  * @param f fifo to cleanup
287  */
289 /**
290  * Cleanup fifo ooo data
291  *
292  * The ooo data is allocated in producer process memory. The fifo
293  * segment heap should not be pushed.
294  *
295  * @param f fifo to cleanup
296  */
298 /**
299  * Init fifo head and tail
300  *
301  * @param f fifo
302  * @param head head value that will be matched to a chunk
303  * @param tail tail value that will be matched to a chunk
304  */
305 void svm_fifo_init_pointers (svm_fifo_t * f, u32 head, u32 tail);
306 /**
307  * Clone fifo
308  *
309  * Clones single/default chunk fifo. It does not work for fifos with
310  * multiple chunks.
311  */
312 void svm_fifo_clone (svm_fifo_t * df, svm_fifo_t * sf);
313 /**
314  * Enqueue data to fifo
315  *
316  * Data is enqueued and tail pointer is updated atomically. If the new data
317  * enqueued partly overlaps or "touches" an out-of-order segment, said segment
318  * is "consumed" and the number of bytes returned is appropriately updated.
319  *
320  * @param f fifo
321  * @param len length of data to copy
322  * @param src buffer from where to copy the data
323  * @return number of contiguous bytes that can be consumed or error
324  */
325 int svm_fifo_enqueue (svm_fifo_t * f, u32 len, const u8 * src);
326 /**
327  * Enqueue data to fifo with offset
328  *
329  * Data is enqueued without updating tail pointer. Instead, an out-of-order
330  * list of segments is generated and maintained. Fifo takes care of coalescing
331  * contiguous or overlapping segments.
332  *
333  * @param f fifo
334  * @param offset offset at which to copy the data
335  * @param len len of data to copy
336  * @param src buffer from where to copy the data
337  * @return 0 if enqueue was successful, error otherwise
338  */
340  u8 * src);
341 
342 /**
343  * Advance tail pointer
344  *
345  * Useful for moving tail pointer after external enqueue.
346  *
347  * @param f fifo
348  * @param len number of bytes to add to tail
349  */
351 /**
352  * Enqueue array of @ref svm_fifo_seg_t in order
353  *
354  * @param f fifo
355  * @param segs array of segments to enqueue
356  * @param n_segs number of segments
357  * @param allow_partial if set partial enqueues are allowed
358  * @return len if enqueue was successful, error otherwise
359  */
361  u32 n_segs, u8 allow_partial);
362 /**
363  * Overwrite fifo head with new data
364  *
365  * This should be typically used by dgram transport protocols that need
366  * to update the dgram header after dequeuing a chunk of data. It assumes
367  * that the dgram header is at most spread over two chunks.
368  *
369  * @param f fifo
370  * @param src src of new data
371  * @param len length of new data
372  */
374 /**
375  * Dequeue data from fifo
376  *
377  * Data is dequeued to consumer provided buffer and head is atomically
378  * updated. This should not be used in combination with ooo lookups. If
379  * ooo peeking of data is needed in combination with dequeuing use @ref
380  * svm_fifo_dequeue_drop.
381  *
382  * @param f fifo
383  * @param len length of data to dequeue
384  * @param dst buffer to where to dequeue the data
385  * @return number of bytes dequeued or error
386  */
388 /**
389  * Peek data from fifo
390  *
391  * Data is copied from requested offset into provided dst buffer. Head is
392  * not updated.
393  *
394  * @param f fifo
395  * @param offset offset from which to copy the data
396  * @param len length of data to copy
397  * @param dst buffer to where to dequeue the data
398  * @return number of bytes peeked
399  */
401 /**
402  * Dequeue and drop bytes from fifo
403  *
404  * Advances fifo head by requested amount of bytes.
405  *
406  * @param f fifo
407  * @param len number of bytes to drop
408  * @return number of bytes dropped
409  */
411 /**
412  * Dequeue and drop all bytes from fifo
413  *
414  * Advances head to tail position.
415  *
416  * @param f fifo
417  */
419 /**
420  * Get pointers to fifo chunks data in @ref svm_fifo_seg_t array
421  *
422  * Populates fifo segment array with pointers to fifo chunk data and lengths.
423  * Because this returns pointers to data, it must be paired with
424  * @ref svm_fifo_dequeue_drop to actually release the fifo chunks after the
425  * data is consumed.
426  *
427  * @param f fifo
428  * @param offset offset from where to retrieve segments
429  * @param fs array of fifo segments allocated by caller
430  * @param n_segs number of fifo segments in array
431  * @param max_bytes max bytes to be mapped to fifo segments
432  * @return number of bytes in fifo segments or SVM_FIFO_EEMPTY
433  */
435  u32 n_segs, u32 max_bytes);
436 /**
437  * Add io events subscriber to list
438  *
439  * @param f fifo
440  * @param sub subscriber opaque index (typically app worker index)
441  */
442 void svm_fifo_add_subscriber (svm_fifo_t * f, u8 sub);
443 /**
444  * Remove io events subscriber form list
445  *
446  * @param f fifo
447  * @param sub subscriber index to be removed
448  */
449 void svm_fifo_del_subscriber (svm_fifo_t * f, u8 subscriber);
450 /**
451  * Number of out-of-order segments for fifo
452  *
453  * @param f fifo
454  * @return number of out of order segments
455  */
457 /**
458  * First out-of-order segment for fifo
459  *
460  * @param f fifo
461  * @return first out-of-order segment for fifo
462  */
464 /**
465  * Check if fifo is sane. Debug only.
466  *
467  * @param f fifo
468  * @return 1 if sane, 0 otherwise
469  */
471 /**
472  * Number of chunks linked into the fifo
473  *
474  * @param f fifo
475  * @return number of chunks in fifo linked list
476  */
479 
480 /**
481  * Fifo max bytes to dequeue optimized for consumer
482  *
483  * @param f fifo
484  * @return max number of bytes that can be dequeued
485  */
486 static inline u32
488 {
489  u32 tail, head;
490  f_load_head_tail_cons (f, &head, &tail);
491  return f_cursize (f, head, tail);
492 }
493 
494 /**
495  * Fifo max bytes to dequeue optimized for producer
496  *
497  * @param f fifo
498  * @return max number of bytes that can be dequeued
499  */
500 static inline u32
502 {
503  u32 tail, head;
504  f_load_head_tail_prod (f, &head, &tail);
505  return f_cursize (f, head, tail);
506 }
507 
508 /**
509  * Fifo max bytes to dequeue
510  *
511  * Note: use producer or consumer specific functions for performance:
512  * @ref svm_fifo_max_dequeue_cons (svm_fifo_t *f)
513  * @ref svm_fifo_max_dequeue_prod (svm_fifo_t *f)
514  */
515 static inline u32
517 {
518  u32 tail, head;
519  f_load_head_tail_all_acq (f, &head, &tail);
520  return f_cursize (f, head, tail);
521 }
522 
523 /**
524  * Check if fifo is full optimized for producer
525  *
526  * @param f fifo
527  * @return 1 if fifo is full 0 otherwise
528  */
529 static inline int
531 {
532  return (svm_fifo_max_dequeue_prod (f) == f->shr->size);
533 }
534 
535 /* Check if fifo is full.
536  *
537  * Note: use producer or consumer specific functions for performance.
538  * @ref svm_fifo_is_full_prod (svm_fifo_t * f)
539  * add cons version if needed
540  */
541 static inline int
543 {
544  return (svm_fifo_max_dequeue (f) == f->shr->size);
545 }
546 
547 /**
548  * Check if fifo is empty optimized for consumer
549  *
550  * @param f fifo
551  * @return 1 if fifo is empty 0 otherwise
552  */
553 static inline int
555 {
556  return (svm_fifo_max_dequeue_cons (f) == 0);
557 }
558 
559 /**
560  * Check if fifo is empty optimized for producer
561  *
562  * @param f fifo
563  * @return 1 if fifo is empty 0 otherwise
564  */
565 static inline int
567 {
568  return (svm_fifo_max_dequeue_prod (f) == 0);
569 }
570 
571 /**
572  * Check if fifo is empty
573  *
574  * Note: use producer or consumer specific functions for perfomance.
575  * @ref svm_fifo_is_empty_cons (svm_fifo_t * f)
576  * @ref svm_fifo_is_empty_prod (svm_fifo_t * f)
577  */
578 static inline int
580 {
581  return (svm_fifo_max_dequeue (f) == 0);
582 }
583 
584 /**
585  * Check if fifo is wrapped
586  *
587  * @param f fifo
588  * @return 1 if 'normalized' head is ahead of tail
589  */
590 static inline u8
592 {
593  u32 head, tail;
594  f_load_head_tail_all_acq (f, &head, &tail);
595  return head > tail;
596 }
597 
598 /**
599  * Maximum number of bytes that can be enqueued into fifo
600  *
601  * Optimized for producer
602  *
603  * @param f fifo
604  * @return max number of bytes that can be enqueued into fifo
605  */
606 static inline u32
608 {
609  u32 head, tail;
610  f_load_head_tail_prod (f, &head, &tail);
611  return f_free_count (f, head, tail);
612 }
613 
614 /* Maximum number of bytes that can be enqueued into fifo
615  *
616  * Note: use producer or consumer specific functions for performance.
617  * @ref svm_fifo_max_enqueue_prod (svm_fifo_t *f)
618  * add consumer specific version if needed.
619  */
620 static inline u32
622 {
623  u32 head, tail;
624  f_load_head_tail_all_acq (f, &head, &tail);
625  return f_free_count (f, head, tail);
626 }
627 
628 /**
629  * Max contiguous chunk of data that can be read.
630  *
631  * Should only be called by consumers.
632  */
634 
635 /**
636  * Max contiguous chunk of data that can be written
637  *
638  * Should only be called by producers
639  */
641 
642 /**
643  * Fifo number of subscribers getter
644  *
645  * @param f fifo
646  * @return number of subscribers
647  */
648 static inline u8
650 {
651  return f->shr->n_subscribers;
652 }
653 
654 /**
655  * Check if fifo has out-of-order data
656  *
657  * @param f fifo
658  * @return 1 if fifo has ooo data, 0 otherwise
659  */
660 static inline u8
662 {
663  return f->ooos_list_head != OOO_SEGMENT_INVALID_INDEX;
664 }
665 
666 static inline ooo_segment_t *
668 {
669  if (f->ooos_newest == OOO_SEGMENT_INVALID_INDEX)
670  return 0;
671  return pool_elt_at_index (f->ooo_segments, f->ooos_newest);
672 }
673 
674 static inline void
676 {
677  f->ooos_newest = OOO_SEGMENT_INVALID_INDEX;
678 }
679 
680 static inline u32
682 {
683  u32 tail;
684  /* load-relaxed: producer owned index */
685  tail = f->shr->tail;
686 
687  return (s->start - tail);
688 }
689 
690 static inline u32
692 {
693  return s->length;
694 }
695 
696 static inline u32
698 {
699  return f->shr->size;
700 }
701 
702 static inline void
704 {
705  if (size > (1 << f->fs_hdr->max_log2_fifo_size))
706  return;
707  fsh_virtual_mem_update (f->fs_hdr, f->shr->slice_index,
708  (int) f->shr->size - size);
709  f->shr->size = size;
710 }
711 
712 /**
713  * Check if fifo has io event
714  *
715  * @param f fifo
716  * @return 1 if fifo has event, 0 otherwise
717  */
718 static inline int
720 {
721  return f->shr->has_event;
722 }
723 
724 /**
725  * Set fifo event flag.
726  *
727  * Forces release semantics.
728  *
729  * @param f fifo
730  * @return 1 if flag was not set, 0 otherwise
731  */
734 {
735  return !clib_atomic_swap_rel_n (&f->shr->has_event, 1);
736 }
737 
738 /**
739  * Unset fifo event flag.
740  *
741  * Forces acquire semantics
742  *
743  * @param f fifo
744  */
745 always_inline void
747 {
748  clib_atomic_swap_acq_n (&f->shr->has_event, 0);
749 }
750 
751 /**
752  * Set specific want notification flag
753  *
754  * For list of flags see @ref svm_fifo_deq_ntf_t
755  *
756  * @param f fifo
757  * @param ntf_type type of notification requested
758  */
759 static inline void
761 {
762  f->shr->want_deq_ntf |= ntf_type;
763 }
764 
765 /**
766  * Clear specific want notification flag
767  *
768  * For list of flags see @ref svm_fifo_ntf_t
769  *
770  * @param f fifo
771  * @param ntf_type type of notification to be cleared
772  */
773 static inline void
775 {
776  f->shr->want_deq_ntf &= ~ntf_type;
777 }
778 
779 /**
780  * Clear the want notification flag and set has notification
781  *
782  * Should be used after enqueuing an event. This clears the
783  * SVM_FIFO_WANT_NOTIF flag but it does not clear
784  * SVM_FIFO_WANT_NOTIF_IF_FULL. If the latter was set, has_ntf is
785  * set to avoid enqueueing events for for all dequeue operations until
786  * it is manually cleared.
787  *
788  * @param f fifo
789  */
790 static inline void
792 {
793  /* Set the flag if want_notif_if_full was the only ntf requested */
794  f->shr->has_deq_ntf =
795  f->shr->want_deq_ntf == SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL;
797 }
798 
799 /**
800  * Clear has notification flag
801  *
802  * The fifo generates only one event per SVM_FIFO_WANT_NOTIF_IF_FULL
803  * request and sets has_ntf. To received new events the flag must be
804  * cleared using this function.
805  *
806  * @param f fifo
807  */
808 static inline void
810 {
811  f->shr->has_deq_ntf = 0;
812 }
813 
814 /**
815  * Check if fifo needs dequeue notification
816  *
817  * Determines based on notification request flags and state of the fifo if
818  * an event should be generated.
819  *
820  * @param f fifo
821  * @param n_last_deq number of bytes last dequeued
822  * @return 1 if event should be generated, 0 otherwise
823  */
824 static inline u8
826 {
827  u8 want_ntf = f->shr->want_deq_ntf;
828 
829  if (PREDICT_TRUE (want_ntf == SVM_FIFO_NO_DEQ_NOTIF))
830  return 0;
831  else if (want_ntf & SVM_FIFO_WANT_DEQ_NOTIF)
832  return 1;
833  if (want_ntf & SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL)
834  {
835  u32 max_deq = svm_fifo_max_dequeue_cons (f);
836  u32 size = f->shr->size;
837  if (!f->shr->has_deq_ntf && max_deq < size &&
838  max_deq + n_last_deq >= size)
839  return 1;
840  }
841  if (want_ntf & SVM_FIFO_WANT_DEQ_NOTIF_IF_EMPTY)
842  {
843  if (!f->shr->has_deq_ntf && svm_fifo_is_empty (f))
844  return 1;
845  }
846  return 0;
847 }
848 
849 #endif /* __included_ssvm_fifo_h__ */
850 
851 /*
852  * fd.io coding-style-patch-verification: ON
853  *
854  * Local Variables:
855  * eval: (c-set-style "gnu")
856  * End:
857  */
svm_fifo_is_full_prod
static int svm_fifo_is_full_prod(svm_fifo_t *f)
Check if fifo is full optimized for producer.
Definition: svm_fifo.h:530
svm_fifo_set_event
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
Definition: svm_fifo.h:733
f_load_head_tail_prod
static void f_load_head_tail_prod(svm_fifo_t *f, u32 *head, u32 *tail)
Load head and tail optimized for producer.
Definition: svm_fifo.h:93
svm_fifo_size
static u32 svm_fifo_size(svm_fifo_t *f)
Definition: svm_fifo.h:697
svm_fifo_unset_event
static void svm_fifo_unset_event(svm_fifo_t *f)
Unset fifo event flag.
Definition: svm_fifo.h:746
SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL
@ SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL
Notify on transition from full.
Definition: svm_fifo.h:36
svm_fifo_n_subscribers
static u8 svm_fifo_n_subscribers(svm_fifo_t *f)
Fifo number of subscribers getter.
Definition: svm_fifo.h:649
f
vlib_frame_t * f
Definition: interface_output.c:1098
svm_fifo_free
void svm_fifo_free(svm_fifo_t *f)
Free fifo and associated state.
Definition: svm_fifo.c:768
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
fs_chunk_sptr
static fs_sptr_t fs_chunk_sptr(fifo_segment_header_t *fsh, svm_fifo_chunk_t *c)
Definition: fifo_types.h:176
clib.h
svm_fifo_needs_deq_ntf
static u8 svm_fifo_needs_deq_ntf(svm_fifo_t *f, u32 n_last_deq)
Check if fifo needs dequeue notification.
Definition: svm_fifo.h:825
svm_fifo_enqueue_with_offset
int svm_fifo_enqueue_with_offset(svm_fifo_t *f, u32 offset, u32 len, u8 *src)
Enqueue data to fifo with offset.
Definition: svm_fifo.c:906
svm_fifo_chunk_
Definition: fifo_types.h:38
svm_fifo_seg_::len
u32 len
Definition: svm_fifo.h:55
f_tail_cptr
static svm_fifo_chunk_t * f_tail_cptr(svm_fifo_t *f)
Definition: svm_fifo.h:193
svm_fifo_overwrite_head
void svm_fifo_overwrite_head(svm_fifo_t *f, u8 *src, u32 len)
Overwrite fifo head with new data.
Definition: svm_fifo.c:781
f_pos_lt
static int f_pos_lt(u32 a, u32 b)
Definition: svm_fifo.h:144
svm_fifo_alloc
svm_fifo_t * svm_fifo_alloc(u32 size)
Create fifo of requested size.
Definition: svm_fifo.c:426
svm_fifo_flag_t
enum svm_fifo_flag_ svm_fifo_flag_t
f_load_head_tail_cons
static void f_load_head_tail_cons(svm_fifo_t *f, u32 *head, u32 *tail)
Load head and tail optimized for consumer.
Definition: svm_fifo.h:80
svm_fifo_is_empty_prod
static int svm_fifo_is_empty_prod(svm_fifo_t *f)
Check if fifo is empty optimized for producer.
Definition: svm_fifo.h:566
svm_fifo_segments
int svm_fifo_segments(svm_fifo_t *f, u32 offset, svm_fifo_seg_t *fs, u32 n_segs, u32 max_bytes)
Get pointers to fifo chunks data in svm_fifo_seg_t array.
Definition: svm_fifo.c:1283
svm_fifo_err_t
svm_fifo_err_t
Definition: svm_fifo.h:45
svm_fifo_fill_chunk_list
int svm_fifo_fill_chunk_list(svm_fifo_t *f)
Ensure the whole fifo size is writeable.
Definition: svm_fifo.c:1228
i32
signed int i32
Definition: types.h:77
svm_fifo_free_ooo_data
void svm_fifo_free_ooo_data(svm_fifo_t *f)
Cleanup fifo ooo data.
Definition: svm_fifo.c:115
ooo_segment_t::length
u32 length
Length of segment.
Definition: fifo_types.h:53
svm_fifo_provision_chunks
int svm_fifo_provision_chunks(svm_fifo_t *f, svm_fifo_seg_t *fs, u32 n_segs, u32 len)
Provision and return chunks for number of bytes requested.
Definition: svm_fifo.c:1244
svm_fifo_t
struct _svm_fifo svm_fifo_t
svm_fifo_n_chunks
u32 svm_fifo_n_chunks(svm_fifo_t *f)
Number of chunks linked into the fifo.
Definition: svm_fifo.c:1505
svm_fifo_has_ooo_data
static u8 svm_fifo_has_ooo_data(svm_fifo_t *f)
Check if fifo has out-of-order data.
Definition: svm_fifo.h:661
svm_fifo_enqueue_segments
int svm_fifo_enqueue_segments(svm_fifo_t *f, const svm_fifo_seg_t segs[], u32 n_segs, u8 allow_partial)
Enqueue array of svm_fifo_seg_t in order.
Definition: svm_fifo.c:972
svm_fifo_deq_ntf_t
enum svm_fifo_deq_ntf_ svm_fifo_deq_ntf_t
fsh_virtual_mem_update
void fsh_virtual_mem_update(fifo_segment_header_t *fsh, u32 slice_index, int n_bytes)
Definition: fifo_segment.c:124
svm_fifo_dequeue_drop_all
void svm_fifo_dequeue_drop_all(svm_fifo_t *f)
Dequeue and drop all bytes from fifo.
Definition: svm_fifo.c:1207
svm_fifo_seg_
Definition: svm_fifo.h:52
SVM_FIFO_WANT_DEQ_NOTIF
@ SVM_FIFO_WANT_DEQ_NOTIF
Notify on dequeue.
Definition: svm_fifo.h:35
len
u8 len
Definition: ip_types.api:103
svm_fifo_clear_deq_ntf
static void svm_fifo_clear_deq_ntf(svm_fifo_t *f)
Clear the want notification flag and set has notification.
Definition: svm_fifo.h:791
svm_fifo_is_empty_cons
static int svm_fifo_is_empty_cons(svm_fifo_t *f)
Check if fifo is empty optimized for consumer.
Definition: svm_fifo.h:554
svm_fifo_max_enqueue
static u32 svm_fifo_max_enqueue(svm_fifo_t *f)
Definition: svm_fifo.h:621
ooo_segment_t::start
u32 start
Start of segment, normalized.
Definition: fifo_types.h:52
svm_fifo_is_sane
u8 svm_fifo_is_sane(svm_fifo_t *f)
Check if fifo is sane.
Definition: svm_fifo.c:1410
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
fs_sptr_t
uword fs_sptr_t
Definition: fifo_types.h:36
svm_fifo_init_ooo_lookup
void svm_fifo_init_ooo_lookup(svm_fifo_t *f, u8 ooo_type)
Initialize rbtrees used for ooo lookups.
Definition: svm_fifo.c:408
svm_fifo_newest_ooo_segment
static ooo_segment_t * svm_fifo_newest_ooo_segment(svm_fifo_t *f)
Definition: svm_fifo.h:667
svm_fifo_dequeue
int svm_fifo_dequeue(svm_fifo_t *f, u32 len, u8 *dst)
Dequeue data from fifo.
Definition: svm_fifo.c:1105
svm_fifo_dequeue_drop
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 len)
Dequeue and drop bytes from fifo.
Definition: svm_fifo.c:1168
svm_fifo_max_write_chunk
u32 svm_fifo_max_write_chunk(svm_fifo_t *f)
Max contiguous chunk of data that can be written.
Definition: svm_fifo.c:534
ooo_segment_offset_prod
static u32 ooo_segment_offset_prod(svm_fifo_t *f, ooo_segment_t *s)
Definition: svm_fifo.h:681
svm_fifo_replay
u8 * svm_fifo_replay(u8 *s, svm_fifo_t *f, u8 no_read, u8 verbose)
Definition: svm_fifo.c:1555
f_pos_gt
static int f_pos_gt(u32 a, u32 b)
Definition: svm_fifo.h:156
pool.h
Fixed length block allocator. Pools are built from clib vectors and bitmaps. Use pools when repeatedl...
svm_fifo_is_full
static int svm_fifo_is_full(svm_fifo_t *f)
Definition: svm_fifo.h:542
f_end_cptr
static svm_fifo_chunk_t * f_end_cptr(svm_fifo_t *f)
Definition: svm_fifo.h:181
OOO_SEGMENT_INVALID_INDEX
#define OOO_SEGMENT_INVALID_INDEX
Definition: svm_fifo.h:28
SVM_FIFO_EFULL
@ SVM_FIFO_EFULL
Definition: svm_fifo.h:47
svm_fifo_max_dequeue_prod
static u32 svm_fifo_max_dequeue_prod(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for producer.
Definition: svm_fifo.h:501
format.h
src
vl_api_address_t src
Definition: gre.api:54
clib_atomic_swap_acq_n
#define clib_atomic_swap_acq_n(a, b)
Definition: atomics.h:57
svm_fifo_chunk_::next
fs_sptr_t next
pointer to next chunk in linked-lists
Definition: fifo_types.h:42
svm_fifo_dump_trace
u8 * svm_fifo_dump_trace(u8 *s, svm_fifo_t *f)
Definition: svm_fifo.c:1531
f_pos_geq
static int f_pos_geq(u32 a, u32 b)
Definition: svm_fifo.h:162
svm_fifo_n_ooo_segments
u32 svm_fifo_n_ooo_segments(svm_fifo_t *f)
Number of out-of-order segments for fifo.
Definition: svm_fifo.c:1354
ooo_segment_length
static u32 ooo_segment_length(svm_fifo_t *f, ooo_segment_t *s)
Definition: svm_fifo.h:691
f_cptr
static svm_fifo_chunk_t * f_cptr(svm_fifo_t *f, fs_sptr_t cp)
Definition: svm_fifo.h:199
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
size
u32 size
Definition: vhost_user.h:125
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
clib_bihash_value
template key/value backing page structure
Definition: bihash_doc.h:44
f_pos_leq
static int f_pos_leq(u32 a, u32 b)
Definition: svm_fifo.h:150
f_start_cptr
static svm_fifo_chunk_t * f_start_cptr(svm_fifo_t *f)
Definition: svm_fifo.h:175
svm_fifo_add_subscriber
void svm_fifo_add_subscriber(svm_fifo_t *f, u8 sub)
Add io events subscriber to list.
Definition: svm_fifo.c:1387
svm_fifo_max_enqueue_prod
static u32 svm_fifo_max_enqueue_prod(svm_fifo_t *f)
Maximum number of bytes that can be enqueued into fifo.
Definition: svm_fifo.h:607
svm_fifo_clone
void svm_fifo_clone(svm_fifo_t *df, svm_fifo_t *sf)
Clone fifo.
Definition: svm_fifo.c:1338
SVM_FIFO_NO_DEQ_NOTIF
@ SVM_FIFO_NO_DEQ_NOTIF
No notification requested.
Definition: svm_fifo.h:34
svm_fifo_set_size
static void svm_fifo_set_size(svm_fifo_t *f, u32 size)
Definition: svm_fifo.h:703
svm_fifo_chunk_alloc
svm_fifo_chunk_t * svm_fifo_chunk_alloc(u32 size)
Allocate a fifo chunk on heap.
Definition: svm_fifo.c:462
SVM_FIFO_WANT_DEQ_NOTIF_IF_EMPTY
@ SVM_FIFO_WANT_DEQ_NOTIF_IF_EMPTY
Notify on transition to empty.
Definition: svm_fifo.h:37
f_head_cptr
static svm_fifo_chunk_t * f_head_cptr(svm_fifo_t *f)
Definition: svm_fifo.h:187
u32
unsigned int u32
Definition: types.h:88
svm_fifo_init
void svm_fifo_init(svm_fifo_t *f, u32 size)
Initialize fifo.
Definition: svm_fifo.c:372
svm_fifo_deq_ntf_
svm_fifo_deq_ntf_
Definition: svm_fifo.h:32
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
clib_atomic_swap_rel_n
#define clib_atomic_swap_rel_n(a, b)
Definition: atomics.h:58
ooo_segment_t
Definition: fifo_types.h:48
svm_fifo_init_pointers
void svm_fifo_init_pointers(svm_fifo_t *f, u32 head, u32 tail)
Init fifo head and tail.
Definition: svm_fifo.c:1369
svm_fifo_first_ooo_segment
ooo_segment_t * svm_fifo_first_ooo_segment(svm_fifo_t *f)
First out-of-order segment for fifo.
Definition: svm_fifo.c:1360
svm_fifo_is_wrapped
static u8 svm_fifo_is_wrapped(svm_fifo_t *f)
Check if fifo is wrapped.
Definition: svm_fifo.h:591
vec.h
svm_fifo_max_read_chunk
u32 svm_fifo_max_read_chunk(svm_fifo_t *f)
Max contiguous chunk of data that can be read.
Definition: svm_fifo.c:514
SVM_FIFO_EGROW
@ SVM_FIFO_EGROW
Definition: svm_fifo.h:49
f_load_head_tail_all_acq
static void f_load_head_tail_all_acq(svm_fifo_t *f, u32 *head, u32 *tail)
Load head and tail independent of producer/consumer role.
Definition: svm_fifo.h:107
fs_chunk_ptr
static svm_fifo_chunk_t * fs_chunk_ptr(fifo_segment_header_t *fsh, fs_sptr_t cp)
Definition: fifo_types.h:170
f_cursize
static u32 f_cursize(svm_fifo_t *f, u32 head, u32 tail)
Fifo current size, i.e., number of bytes enqueued.
Definition: svm_fifo.h:121
svm_fifo_del_subscriber
void svm_fifo_del_subscriber(svm_fifo_t *f, u8 subscriber)
Remove io events subscriber form list.
Definition: svm_fifo.c:1395
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
a
a
Definition: bitmap.h:525
f_csptr_link
static void f_csptr_link(svm_fifo_t *f, fs_sptr_t cp, svm_fifo_chunk_t *c)
Definition: svm_fifo.h:211
f_chunk_end
static u32 f_chunk_end(svm_fifo_chunk_t *c)
Definition: svm_fifo.h:138
svm_fifo_enqueue_nocopy
void svm_fifo_enqueue_nocopy(svm_fifo_t *f, u32 len)
Advance tail pointer.
Definition: svm_fifo.c:946
svm_fifo_free_chunk_lookup
void svm_fifo_free_chunk_lookup(svm_fifo_t *f)
Cleanup fifo chunk lookup rb tree.
Definition: svm_fifo.c:761
SVM_FIFO_EEMPTY
@ SVM_FIFO_EEMPTY
Definition: svm_fifo.h:48
svm_fifo_seg_t
struct svm_fifo_seg_ svm_fifo_seg_t
svm_fifo_reset_has_deq_ntf
static void svm_fifo_reset_has_deq_ntf(svm_fifo_t *f)
Clear has notification flag.
Definition: svm_fifo.h:809
clib_atomic_load_acq_n
#define clib_atomic_load_acq_n(a)
Definition: atomics.h:51
f_chunk_includes_pos
static u8 f_chunk_includes_pos(svm_fifo_chunk_t *c, u32 pos)
Definition: svm_fifo.h:168
format_svm_fifo
format_function_t format_svm_fifo
Definition: svm_fifo.h:478
f_free_count
static u32 f_free_count(svm_fifo_t *f, u32 head, u32 tail)
Fifo free bytes, i.e., number of free bytes.
Definition: svm_fifo.h:132
svm_fifo_flag_
svm_fifo_flag_
Definition: svm_fifo.h:40
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
svm_fifo_max_dequeue_cons
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
Definition: svm_fifo.h:487
svm_fifo_enqueue
int svm_fifo_enqueue(svm_fifo_t *f, u32 len, const u8 *src)
Enqueue data to fifo.
Definition: svm_fifo.c:847
svm_fifo_peek
int svm_fifo_peek(svm_fifo_t *f, u32 offset, u32 len, u8 *dst)
Peek data from fifo.
Definition: svm_fifo.c:1141
svm_fifo_add_want_deq_ntf
static void svm_fifo_add_want_deq_ntf(svm_fifo_t *f, u8 ntf_type)
Set specific want notification flag.
Definition: svm_fifo.h:760
svm_fifo_is_empty
static int svm_fifo_is_empty(svm_fifo_t *f)
Check if fifo is empty.
Definition: svm_fifo.h:579
SVM_FIFO_F_LL_TRACKED
@ SVM_FIFO_F_LL_TRACKED
Definition: svm_fifo.h:42
svm_fifo_del_want_deq_ntf
static void svm_fifo_del_want_deq_ntf(svm_fifo_t *f, u8 ntf_type)
Clear specific want notification flag.
Definition: svm_fifo.h:774
svm_fifo_has_event
static int svm_fifo_has_event(svm_fifo_t *f)
Check if fifo has io event.
Definition: svm_fifo.h:719
fifo_types.h
svm_fifo_seg_::data
u8 * data
Definition: svm_fifo.h:54
svm_fifo_max_dequeue
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
Fifo max bytes to dequeue.
Definition: svm_fifo.h:516
f_csptr
static fs_sptr_t f_csptr(svm_fifo_t *f, svm_fifo_chunk_t *c)
Definition: svm_fifo.h:205
svm_fifo_newest_ooo_segment_reset
static void svm_fifo_newest_ooo_segment_reset(svm_fifo_t *f)
Definition: svm_fifo.h:675