FD.io VPP  v20.09-64-g4f7b92f0a
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
80 f_load_head_tail_cons (svm_fifo_t * f, u32 * head, u32 * tail)
81 {
82  /* load-relaxed: consumer owned index */
83  *head = f->head;
84  /* load-acq: consumer foreign index (paired with store-rel in producer) */
85  *tail = clib_atomic_load_acq_n (&f->tail);
86 }
87 
88 /** Load head and tail optimized for producer
89  *
90  * Internal function
91  */
92 static inline void
93 f_load_head_tail_prod (svm_fifo_t * f, u32 * head, u32 * tail)
94 {
95  /* load relaxed: producer owned index */
96  *tail = f->tail;
97  /* load-acq: producer foreign index (paired with store-rel in consumer) */
98  *head = clib_atomic_load_acq_n (&f->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->tail);
111  /* load-acq : producer foriegn index (paired with store-rel) */
112  *head = clib_atomic_load_acq_n (&f->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->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 
174 /**
175  * Create fifo of requested size
176  *
177  * Allocates fifo on current heap.
178  *
179  * @param size data size in bytes for fifo to be allocated. Will be
180  * rounded to the next highest power-of-two value.
181  * @return pointer to new fifo
182  */
184 /**
185  * Initialize fifo
186  *
187  * @param f fifo
188  * @param size size for fifo
189  */
190 void svm_fifo_init (svm_fifo_t * f, u32 size);
191 /**
192  * Allocate a fifo chunk on heap
193  *
194  * If the chunk is allocated on a fifo segment, this should be called
195  * with the segment's heap pushed.
196  *
197  * @param size chunk size in bytes. Will be rounded to the next highest
198  * power-of-two
199  * @return new chunk or 0 if alloc failed
200  */
202 /**
203  * Ensure the whole fifo size is writeable
204  *
205  * Allocates enough chunks to cover the whole fifo size.
206  *
207  * @param f fifo
208  */
210 /**
211  * Initialize rbtrees used for ooo lookups
212  *
213  * @param f fifo
214  * @param ooo_type type of ooo operation (0 enqueue, 1 dequeue)
215  */
216 void svm_fifo_init_ooo_lookup (svm_fifo_t * f, u8 ooo_type);
217 /**
218  * Free fifo and associated state
219  *
220  * @param f fifo
221  */
222 void svm_fifo_free (svm_fifo_t * f);
223 /**
224  * Cleanup fifo chunk lookup rb tree
225  *
226  * The rb tree is allocated in segment heap so this should be called
227  * with it pushed.
228  *
229  * @param f fifo to cleanup
230  */
232 /**
233  * Cleanup fifo ooo data
234  *
235  * The ooo data is allocated in producer process memory. The fifo
236  * segment heap should not be pushed.
237  *
238  * @param f fifo to cleanup
239  */
241 /**
242  * Init fifo head and tail
243  *
244  * @param f fifo
245  * @param head head value that will be matched to a chunk
246  * @param tail tail value that will be matched to a chunk
247  */
248 void svm_fifo_init_pointers (svm_fifo_t * f, u32 head, u32 tail);
249 /**
250  * Clone fifo
251  *
252  * Clones single/default chunk fifo. It does not work for fifos with
253  * multiple chunks.
254  */
255 void svm_fifo_clone (svm_fifo_t * df, svm_fifo_t * sf);
256 /**
257  * Enqueue data to fifo
258  *
259  * Data is enqueued and tail pointer is updated atomically. If the new data
260  * enqueued partly overlaps or "touches" an out-of-order segment, said segment
261  * is "consumed" and the number of bytes returned is appropriately updated.
262  *
263  * @param f fifo
264  * @param len length of data to copy
265  * @param src buffer from where to copy the data
266  * @return number of contiguous bytes that can be consumed or error
267  */
268 int svm_fifo_enqueue (svm_fifo_t * f, u32 len, const u8 * src);
269 /**
270  * Enqueue data to fifo with offset
271  *
272  * Data is enqueued without updating tail pointer. Instead, an out-of-order
273  * list of segments is generated and maintained. Fifo takes care of coalescing
274  * contiguous or overlapping segments.
275  *
276  * @param f fifo
277  * @param offset offset at which to copy the data
278  * @param len len of data to copy
279  * @param src buffer from where to copy the data
280  * @return 0 if enqueue was successful, error otherwise
281  */
283  u8 * src);
284 
285 /**
286  * Advance tail pointer
287  *
288  * Useful for moving tail pointer after external enqueue.
289  *
290  * @param f fifo
291  * @param len number of bytes to add to tail
292  */
294 /**
295  * Overwrite fifo head with new data
296  *
297  * This should be typically used by dgram transport protocols that need
298  * to update the dgram header after dequeuing a chunk of data. It assumes
299  * that the dgram header is at most spread over two chunks.
300  *
301  * @param f fifo
302  * @param src src of new data
303  * @param len length of new data
304  */
306 /**
307  * Dequeue data from fifo
308  *
309  * Data is dequeued to consumer provided buffer and head is atomically
310  * updated. This should not be used in combination with ooo lookups. If
311  * ooo peeking of data is needed in combination with dequeuing use @ref
312  * svm_fifo_dequeue_drop.
313  *
314  * @param f fifo
315  * @param len length of data to dequeue
316  * @param dst buffer to where to dequeue the data
317  * @return number of bytes dequeued or error
318  */
319 int svm_fifo_dequeue (svm_fifo_t * f, u32 len, u8 * dst);
320 /**
321  * Peek data from fifo
322  *
323  * Data is copied from requested offset into provided dst buffer. Head is
324  * not updated.
325  *
326  * @param f fifo
327  * @param offset offset from which to copy the data
328  * @param len length of data to copy
329  * @param dst buffer to where to dequeue the data
330  * @return number of bytes peeked
331  */
332 int svm_fifo_peek (svm_fifo_t * f, u32 offset, u32 len, u8 * dst);
333 /**
334  * Dequeue and drop bytes from fifo
335  *
336  * Advances fifo head by requested amount of bytes.
337  *
338  * @param f fifo
339  * @param len number of bytes to drop
340  * @return number of bytes dropped
341  */
343 /**
344  * Dequeue and drop all bytes from fifo
345  *
346  * Advances head to tail position.
347  *
348  * @param f fifo
349  */
353 /**
354  * Add io events subscriber to list
355  *
356  * @param f fifo
357  * @param sub subscriber opaque index (typically app worker index)
358  */
359 void svm_fifo_add_subscriber (svm_fifo_t * f, u8 sub);
360 /**
361  * Remove io events subscriber form list
362  *
363  * @param f fifo
364  * @param sub subscriber index to be removed
365  */
366 void svm_fifo_del_subscriber (svm_fifo_t * f, u8 subscriber);
367 /**
368  * Number of out-of-order segments for fifo
369  *
370  * @param f fifo
371  * @return number of out of order segments
372  */
374 /**
375  * First out-of-order segment for fifo
376  *
377  * @param f fifo
378  * @return first out-of-order segment for fifo
379  */
381 /**
382  * Check if fifo is sane. Debug only.
383  *
384  * @param f fifo
385  * @return 1 if sane, 0 otherwise
386  */
388 /**
389  * Number of chunks linked into the fifo
390  *
391  * @param f fifo
392  * @return number of chunks in fifo linked list
393  */
396 
397 /**
398  * Fifo max bytes to dequeue optimized for consumer
399  *
400  * @param f fifo
401  * @return max number of bytes that can be dequeued
402  */
403 static inline u32
405 {
406  u32 tail, head;
407  f_load_head_tail_cons (f, &head, &tail);
408  return f_cursize (f, head, tail);
409 }
410 
411 /**
412  * Fifo max bytes to dequeue optimized for producer
413  *
414  * @param f fifo
415  * @return max number of bytes that can be dequeued
416  */
417 static inline u32
419 {
420  u32 tail, head;
421  f_load_head_tail_prod (f, &head, &tail);
422  return f_cursize (f, head, tail);
423 }
424 
425 /**
426  * Fifo max bytes to dequeue
427  *
428  * Note: use producer or consumer specific functions for performance:
429  * @ref svm_fifo_max_dequeue_cons (svm_fifo_t *f)
430  * @ref svm_fifo_max_dequeue_prod (svm_fifo_t *f)
431  */
432 static inline u32
434 {
435  u32 tail, head;
436  f_load_head_tail_all_acq (f, &head, &tail);
437  return f_cursize (f, head, tail);
438 }
439 
440 /**
441  * Check if fifo is full optimized for producer
442  *
443  * @param f fifo
444  * @return 1 if fifo is full 0 otherwise
445  */
446 static inline int
448 {
449  return (svm_fifo_max_dequeue_prod (f) == f->size);
450 }
451 
452 /* Check if fifo is full.
453  *
454  * Note: use producer or consumer specific functions for performance.
455  * @ref svm_fifo_is_full_prod (svm_fifo_t * f)
456  * add cons version if needed
457  */
458 static inline int
460 {
461  return (svm_fifo_max_dequeue (f) == f->size);
462 }
463 
464 /**
465  * Check if fifo is empty optimized for consumer
466  *
467  * @param f fifo
468  * @return 1 if fifo is empty 0 otherwise
469  */
470 static inline int
472 {
473  return (svm_fifo_max_dequeue_cons (f) == 0);
474 }
475 
476 /**
477  * Check if fifo is empty optimized for producer
478  *
479  * @param f fifo
480  * @return 1 if fifo is empty 0 otherwise
481  */
482 static inline int
484 {
485  return (svm_fifo_max_dequeue_prod (f) == 0);
486 }
487 
488 /**
489  * Check if fifo is empty
490  *
491  * Note: use producer or consumer specific functions for perfomance.
492  * @ref svm_fifo_is_empty_cons (svm_fifo_t * f)
493  * @ref svm_fifo_is_empty_prod (svm_fifo_t * f)
494  */
495 static inline int
497 {
498  return (svm_fifo_max_dequeue (f) == 0);
499 }
500 
501 /**
502  * Check if fifo is wrapped
503  *
504  * @param f fifo
505  * @return 1 if 'normalized' head is ahead of tail
506  */
507 static inline u8
509 {
510  u32 head, tail;
511  f_load_head_tail_all_acq (f, &head, &tail);
512  return head > tail;
513 }
514 
515 /**
516  * Maximum number of bytes that can be enqueued into fifo
517  *
518  * Optimized for producer
519  *
520  * @param f fifo
521  * @return max number of bytes that can be enqueued into fifo
522  */
523 static inline u32
525 {
526  u32 head, tail;
527  f_load_head_tail_prod (f, &head, &tail);
528  return f_free_count (f, head, tail);
529 }
530 
531 /* Maximum number of bytes that can be enqueued into fifo
532  *
533  * Note: use producer or consumer specific functions for performance.
534  * @ref svm_fifo_max_enqueue_prod (svm_fifo_t *f)
535  * add consumer specific version if needed.
536  */
537 static inline u32
539 {
540  u32 head, tail;
541  f_load_head_tail_all_acq (f, &head, &tail);
542  return f_free_count (f, head, tail);
543 }
544 
545 /**
546  * Max contiguous chunk of data that can be read.
547  *
548  * Should only be called by consumers.
549  */
551 
552 /**
553  * Max contiguous chunk of data that can be written
554  *
555  * Should only be called by producers
556  */
558 
559 /**
560  * Fifo head chunk getter
561  *
562  * @param f fifo
563  * @return head chunk pointer
564  */
565 static inline svm_fifo_chunk_t *
567 {
568  return f->head_chunk;
569 }
570 
571 /**
572  * Fifo head pointer getter
573  *
574  * @param f fifo
575  * @return head pointer
576  */
577 static inline u8 *
579 {
580  if (!f->head_chunk)
581  return 0;
582  /* load-relaxed: consumer owned index */
583  return (f->head_chunk->data + (f->head - f->head_chunk->start_byte));
584 }
585 
586 /**
587  * Fifo tail chunk getter
588  *
589  * @param f fifo
590  * @return tail chunk pointer
591  */
592 static inline svm_fifo_chunk_t *
594 {
595  return f->tail_chunk;
596 }
597 
598 /**
599  * Fifo tail pointer getter
600  *
601  * @param f fifo
602  * @return tail pointer
603  */
604 static inline u8 *
606 {
607  /* load-relaxed: producer owned index */
608  return (f->tail_chunk->data + (f->tail - f->tail_chunk->start_byte));
609 }
610 
611 /**
612  * Fifo number of subscribers getter
613  *
614  * @param f fifo
615  * @return number of subscribers
616  */
617 static inline u8
619 {
620  return f->n_subscribers;
621 }
622 
623 /**
624  * Check if fifo has out-of-order data
625  *
626  * @param f fifo
627  * @return 1 if fifo has ooo data, 0 otherwise
628  */
629 static inline u8
631 {
632  return f->ooos_list_head != OOO_SEGMENT_INVALID_INDEX;
633 }
634 
635 static inline ooo_segment_t *
637 {
638  if (f->ooos_newest == OOO_SEGMENT_INVALID_INDEX)
639  return 0;
640  return pool_elt_at_index (f->ooo_segments, f->ooos_newest);
641 }
642 
643 static inline void
645 {
646  f->ooos_newest = OOO_SEGMENT_INVALID_INDEX;
647 }
648 
649 static inline u32
651 {
652  u32 tail;
653  /* load-relaxed: producer owned index */
654  tail = f->tail;
655 
656  return (s->start - tail);
657 }
658 
659 static inline u32
661 {
662  return s->length;
663 }
664 
665 static inline u32
667 {
668  return f->size;
669 }
670 
671 static inline void
673 {
674  if (size > (1 << f->fs_hdr->max_log2_chunk_size))
675  return;
676  fsh_virtual_mem_update (f->fs_hdr, f->slice_index, (int) f->size - size);
677  f->size = size;
678 }
679 
680 /**
681  * Check if fifo has io event
682  *
683  * @param f fifo
684  * @return 1 if fifo has event, 0 otherwise
685  */
686 static inline int
688 {
689  return f->has_event;
690 }
691 
692 /**
693  * Set fifo event flag.
694  *
695  * Forces release semantics.
696  *
697  * @param f fifo
698  * @return 1 if flag was not set, 0 otherwise
699  */
702 {
703  return !clib_atomic_swap_rel_n (&f->has_event, 1);
704 }
705 
706 /**
707  * Unset fifo event flag.
708  *
709  * Forces acquire semantics
710  *
711  * @param f fifo
712  */
713 always_inline void
715 {
716  clib_atomic_swap_acq_n (&f->has_event, 0);
717 }
718 
719 /**
720  * Set specific want notification flag
721  *
722  * For list of flags see @ref svm_fifo_deq_ntf_t
723  *
724  * @param f fifo
725  * @param ntf_type type of notification requested
726  */
727 static inline void
729 {
730  f->want_deq_ntf |= ntf_type;
731 }
732 
733 /**
734  * Clear specific want notification flag
735  *
736  * For list of flags see @ref svm_fifo_ntf_t
737  *
738  * @param f fifo
739  * @param ntf_type type of notification to be cleared
740  */
741 static inline void
743 {
744  f->want_deq_ntf &= ~ntf_type;
745 }
746 
747 /**
748  * Clear the want notification flag and set has notification
749  *
750  * Should be used after enqueuing an event. This clears the
751  * SVM_FIFO_WANT_NOTIF flag but it does not clear
752  * SVM_FIFO_WANT_NOTIF_IF_FULL. If the latter was set, has_ntf is
753  * set to avoid enqueueing events for for all dequeue operations until
754  * it is manually cleared.
755  *
756  * @param f fifo
757  */
758 static inline void
760 {
761  /* Set the flag if want_notif_if_full was the only ntf requested */
762  f->has_deq_ntf = f->want_deq_ntf == SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL;
764 }
765 
766 /**
767  * Clear has notification flag
768  *
769  * The fifo generates only one event per SVM_FIFO_WANT_NOTIF_IF_FULL
770  * request and sets has_ntf. To received new events the flag must be
771  * cleared using this function.
772  *
773  * @param f fifo
774  */
775 static inline void
777 {
778  f->has_deq_ntf = 0;
779 }
780 
781 /**
782  * Check if fifo needs dequeue notification
783  *
784  * Determines based on notification request flags and state of the fifo if
785  * an event should be generated.
786  *
787  * @param f fifo
788  * @param n_last_deq number of bytes last dequeued
789  * @return 1 if event should be generated, 0 otherwise
790  */
791 static inline u8
793 {
794  u8 want_ntf = f->want_deq_ntf;
795 
796  if (PREDICT_TRUE (want_ntf == SVM_FIFO_NO_DEQ_NOTIF))
797  return 0;
798  else if (want_ntf & SVM_FIFO_WANT_DEQ_NOTIF)
799  return 1;
800  if (want_ntf & SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL)
801  {
802  u32 max_deq = svm_fifo_max_dequeue_cons (f);
803  u32 size = f->size;
804  if (!f->has_deq_ntf && max_deq < size && max_deq + n_last_deq >= size)
805  return 1;
806  }
807  if (want_ntf & SVM_FIFO_WANT_DEQ_NOTIF_IF_EMPTY)
808  {
809  if (!f->has_deq_ntf && svm_fifo_is_empty (f))
810  return 1;
811  }
812  return 0;
813 }
814 
815 #endif /* __included_ssvm_fifo_h__ */
816 
817 /*
818  * fd.io coding-style-patch-verification: ON
819  *
820  * Local Variables:
821  * eval: (c-set-style "gnu")
822  * End:
823  */
void svm_fifo_add_subscriber(svm_fifo_t *f, u8 sub)
Add io events subscriber to list.
Definition: svm_fifo.c:1241
u32 length
length of chunk in bytes
Definition: fifo_types.h:32
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
int svm_fifo_enqueue(svm_fifo_t *f, u32 len, const u8 *src)
Enqueue data to fifo.
Definition: svm_fifo.c:838
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:524
a
Definition: bitmap.h:538
void svm_fifo_clone(svm_fifo_t *df, svm_fifo_t *sf)
Clone fifo.
Definition: svm_fifo.c:1195
static void svm_fifo_set_size(svm_fifo_t *f, u32 size)
Definition: svm_fifo.h:672
static int svm_fifo_is_full(svm_fifo_t *f)
Definition: svm_fifo.h:459
Notify on dequeue.
Definition: svm_fifo.h:35
u8 * svm_fifo_replay(u8 *s, svm_fifo_t *f, u8 no_read, u8 verbose)
Definition: svm_fifo.c:1407
static u32 svm_fifo_size(svm_fifo_t *f)
Definition: svm_fifo.h:666
static u8 svm_fifo_has_ooo_data(svm_fifo_t *f)
Check if fifo has out-of-order data.
Definition: svm_fifo.h:630
format_function_t format_svm_fifo
Definition: svm_fifo.h:395
void svm_fifo_free_ooo_data(svm_fifo_t *f)
Cleanup fifo ooo data.
Definition: svm_fifo.c:113
#define PREDICT_TRUE(x)
Definition: clib.h:121
svm_fifo_flag_
Definition: svm_fifo.h:40
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
Fixed length block allocator.
static int svm_fifo_is_empty_prod(svm_fifo_t *f)
Check if fifo is empty optimized for producer.
Definition: svm_fifo.h:483
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
vl_api_address_t src
Definition: gre.api:54
static int svm_fifo_is_empty_cons(svm_fifo_t *f)
Check if fifo is empty optimized for consumer.
Definition: svm_fifo.h:471
static void svm_fifo_reset_has_deq_ntf(svm_fifo_t *f)
Clear has notification flag.
Definition: svm_fifo.h:776
u32 svm_fifo_max_read_chunk(svm_fifo_t *f)
Max contiguous chunk of data that can be read.
Definition: svm_fifo.c:509
void fsh_virtual_mem_update(fifo_segment_header_t *fsh, u32 slice_index, int n_bytes)
Definition: fifo_segment.c:115
static u32 svm_fifo_max_enqueue(svm_fifo_t *f)
Definition: svm_fifo.h:538
static u8 * svm_fifo_tail(svm_fifo_t *f)
Fifo tail pointer getter.
Definition: svm_fifo.h:605
unsigned char u8
Definition: types.h:56
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
static int svm_fifo_is_empty(svm_fifo_t *f)
Check if fifo is empty.
Definition: svm_fifo.h:496
int svm_fifo_segments(svm_fifo_t *f, svm_fifo_seg_t *fs)
Definition: svm_fifo.c:1142
static svm_fifo_chunk_t * svm_fifo_head_chunk(svm_fifo_t *f)
Fifo head chunk getter.
Definition: svm_fifo.h:566
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
Fifo max bytes to dequeue.
Definition: svm_fifo.h:433
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
Definition: svm_fifo.h:404
static u32 ooo_segment_length(svm_fifo_t *f, ooo_segment_t *s)
Definition: svm_fifo.h:660
u8 * svm_fifo_dump_trace(u8 *s, svm_fifo_t *f)
Definition: svm_fifo.c:1383
unsigned int u32
Definition: types.h:88
int svm_fifo_fill_chunk_list(svm_fifo_t *f)
Ensure the whole fifo size is writeable.
Definition: svm_fifo.c:1126
struct svm_fifo_seg_ svm_fifo_seg_t
svm_fifo_deq_ntf_
Definition: svm_fifo.h:32
static u8 * svm_fifo_head(svm_fifo_t *f)
Fifo head pointer getter.
Definition: svm_fifo.h:578
void svm_fifo_init_ooo_lookup(svm_fifo_t *f, u8 ooo_type)
Initialize rbtrees used for ooo lookups.
Definition: svm_fifo.c:403
static int svm_fifo_is_full_prod(svm_fifo_t *f)
Check if fifo is full optimized for producer.
Definition: svm_fifo.h:447
static void svm_fifo_newest_ooo_segment_reset(svm_fifo_t *f)
Definition: svm_fifo.h:644
int svm_fifo_peek(svm_fifo_t *f, u32 offset, u32 len, u8 *dst)
Peek data from fifo.
Definition: svm_fifo.c:1044
u8 svm_fifo_is_sane(svm_fifo_t *f)
Check if fifo is sane.
Definition: svm_fifo.c:1264
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
static int f_pos_gt(u32 a, u32 b)
Definition: svm_fifo.h:156
void svm_fifo_dequeue_drop_all(svm_fifo_t *f)
Dequeue and drop all bytes from fifo.
Definition: svm_fifo.c:1106
u32 svm_fifo_n_ooo_segments(svm_fifo_t *f)
Number of out-of-order segments for fifo.
Definition: svm_fifo.c:1210
u32 size
Definition: vhost_user.h:106
#define always_inline
Definition: ipsec.h:28
static u32 f_chunk_end(svm_fifo_chunk_t *c)
Definition: svm_fifo.h:138
static void svm_fifo_unset_event(svm_fifo_t *f)
Unset fifo event flag.
Definition: svm_fifo.h:714
static u32 svm_fifo_max_dequeue_prod(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for producer.
Definition: svm_fifo.h:418
vl_api_address_t dst
Definition: gre.api:55
static ooo_segment_t * svm_fifo_newest_ooo_segment(svm_fifo_t *f)
Definition: svm_fifo.h:636
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
Definition: svm_fifo.h:701
svm_fifo_chunk_t * svm_fifo_chunk_alloc(u32 size)
Allocate a fifo chunk on heap.
Definition: svm_fifo.c:457
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:792
svmdb_client_t * c
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
int svm_fifo_dequeue(svm_fifo_t *f, u32 len, u8 *dst)
Dequeue data from fifo.
Definition: svm_fifo.c:1009
void svm_fifo_overwrite_head(svm_fifo_t *f, u8 *src, u32 len)
Overwrite fifo head with new data.
Definition: svm_fifo.c:773
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
u32 start_byte
chunk start byte
Definition: fifo_types.h:31
#define OOO_SEGMENT_INVALID_INDEX
Definition: svm_fifo.h:28
svm_fifo_t * svm_fifo_alloc(u32 size)
Create fifo of requested size.
Definition: svm_fifo.c:421
signed int i32
Definition: types.h:77
static u8 f_chunk_includes_pos(svm_fifo_chunk_t *c, u32 pos)
Definition: svm_fifo.h:168
u32 svm_fifo_max_write_chunk(svm_fifo_t *f)
Max contiguous chunk of data that can be written.
Definition: svm_fifo.c:529
void svm_fifo_free_chunk_lookup(svm_fifo_t *f)
Cleanup fifo chunk lookup rb tree.
Definition: svm_fifo.c:753
#define clib_atomic_swap_acq_n(a, b)
Definition: atomics.h:51
static int f_pos_geq(u32 a, u32 b)
Definition: svm_fifo.h:162
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 len)
Dequeue and drop bytes from fifo.
Definition: svm_fifo.c:1068
Notify on transition to empty.
Definition: svm_fifo.h:37
void svm_fifo_free(svm_fifo_t *f)
Free fifo and associated state.
Definition: svm_fifo.c:760
static void svm_fifo_clear_deq_ntf(svm_fifo_t *f)
Clear the want notification flag and set has notification.
Definition: svm_fifo.h:759
static void svm_fifo_add_want_deq_ntf(svm_fifo_t *f, u8 ntf_type)
Set specific want notification flag.
Definition: svm_fifo.h:728
u32 svm_fifo_n_chunks(svm_fifo_t *f)
Number of chunks linked into the fifo.
Definition: svm_fifo.c:1357
static u8 svm_fifo_is_wrapped(svm_fifo_t *f)
Check if fifo is wrapped.
Definition: svm_fifo.h:508
Notify on transition from full.
Definition: svm_fifo.h:36
u32 length
Length of segment.
Definition: fifo_types.h:44
void svm_fifo_enqueue_nocopy(svm_fifo_t *f, u32 len)
Advance tail pointer.
Definition: svm_fifo.c:933
void svm_fifo_init(svm_fifo_t *f, u32 size)
Initialize fifo.
Definition: svm_fifo.c:370
static int f_pos_leq(u32 a, u32 b)
Definition: svm_fifo.h:150
template key/value backing page structure
Definition: bihash_doc.h:44
#define clib_atomic_swap_rel_n(a, b)
Definition: atomics.h:52
enum svm_fifo_deq_ntf_ svm_fifo_deq_ntf_t
No notification requested.
Definition: svm_fifo.h:34
enum svm_fifo_flag_ svm_fifo_flag_t
static void svm_fifo_del_want_deq_ntf(svm_fifo_t *f, u8 ntf_type)
Clear specific want notification flag.
Definition: svm_fifo.h:742
static u32 ooo_segment_offset_prod(svm_fifo_t *f, ooo_segment_t *s)
Definition: svm_fifo.h:650
static u8 svm_fifo_n_subscribers(svm_fifo_t *f)
Fifo number of subscribers getter.
Definition: svm_fifo.h:618
void svm_fifo_init_pointers(svm_fifo_t *f, u32 head, u32 tail)
Init fifo head and tail.
Definition: svm_fifo.c:1225
void svm_fifo_segments_free(svm_fifo_t *f, svm_fifo_seg_t *fs)
Definition: svm_fifo.c:1174
svm_fifo_err_t
Definition: svm_fifo.h:45
static int svm_fifo_has_event(svm_fifo_t *f)
Check if fifo has io event.
Definition: svm_fifo.h:687
#define clib_atomic_load_acq_n(a)
Definition: atomics.h:48
void svm_fifo_del_subscriber(svm_fifo_t *f, u8 subscriber)
Remove io events subscriber form list.
Definition: svm_fifo.c:1249
struct _svm_fifo svm_fifo_t
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:896
u32 start
Start of segment, normalized.
Definition: fifo_types.h:43
ooo_segment_t * svm_fifo_first_ooo_segment(svm_fifo_t *f)
First out-of-order segment for fifo.
Definition: svm_fifo.c:1216
static svm_fifo_chunk_t * svm_fifo_tail_chunk(svm_fifo_t *f)
Fifo tail chunk getter.
Definition: svm_fifo.h:593
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
static int f_pos_lt(u32 a, u32 b)
Definition: svm_fifo.h:144