eb45e41449b33a2e5292ca12c317e161da7cb4ab
[deb_dpdk.git] / lib / librte_ring / rte_ring.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 /*
35  * Derived from FreeBSD's bufring.h
36  *
37  **************************************************************************
38  *
39  * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
40  * All rights reserved.
41  *
42  * Redistribution and use in source and binary forms, with or without
43  * modification, are permitted provided that the following conditions are met:
44  *
45  * 1. Redistributions of source code must retain the above copyright notice,
46  *    this list of conditions and the following disclaimer.
47  *
48  * 2. The name of Kip Macy nor the names of other
49  *    contributors may be used to endorse or promote products derived from
50  *    this software without specific prior written permission.
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
53  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
56  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
57  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
58  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
59  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
60  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
61  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
62  * POSSIBILITY OF SUCH DAMAGE.
63  *
64  ***************************************************************************/
65
66 #ifndef _RTE_RING_H_
67 #define _RTE_RING_H_
68
69 /**
70  * @file
71  * RTE Ring
72  *
73  * The Ring Manager is a fixed-size queue, implemented as a table of
74  * pointers. Head and tail pointers are modified atomically, allowing
75  * concurrent access to it. It has the following features:
76  *
77  * - FIFO (First In First Out)
78  * - Maximum size is fixed; the pointers are stored in a table.
79  * - Lockless implementation.
80  * - Multi- or single-consumer dequeue.
81  * - Multi- or single-producer enqueue.
82  * - Bulk dequeue.
83  * - Bulk enqueue.
84  *
85  * Note: the ring implementation is not preemptable. A lcore must not
86  * be interrupted by another task that uses the same ring.
87  *
88  */
89
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93
94 #include <stdio.h>
95 #include <stdint.h>
96 #include <sys/queue.h>
97 #include <errno.h>
98 #include <rte_common.h>
99 #include <rte_memory.h>
100 #include <rte_lcore.h>
101 #include <rte_atomic.h>
102 #include <rte_branch_prediction.h>
103
104 #define RTE_TAILQ_RING_NAME "RTE_RING"
105
106 enum rte_ring_queue_behavior {
107         RTE_RING_QUEUE_FIXED = 0, /* Enq/Deq a fixed number of items from a ring */
108         RTE_RING_QUEUE_VARIABLE   /* Enq/Deq as many items a possible from ring */
109 };
110
111 #ifdef RTE_LIBRTE_RING_DEBUG
112 /**
113  * A structure that stores the ring statistics (per-lcore).
114  */
115 struct rte_ring_debug_stats {
116         uint64_t enq_success_bulk; /**< Successful enqueues number. */
117         uint64_t enq_success_objs; /**< Objects successfully enqueued. */
118         uint64_t enq_quota_bulk;   /**< Successful enqueues above watermark. */
119         uint64_t enq_quota_objs;   /**< Objects enqueued above watermark. */
120         uint64_t enq_fail_bulk;    /**< Failed enqueues number. */
121         uint64_t enq_fail_objs;    /**< Objects that failed to be enqueued. */
122         uint64_t deq_success_bulk; /**< Successful dequeues number. */
123         uint64_t deq_success_objs; /**< Objects successfully dequeued. */
124         uint64_t deq_fail_bulk;    /**< Failed dequeues number. */
125         uint64_t deq_fail_objs;    /**< Objects that failed to be dequeued. */
126 } __rte_cache_aligned;
127 #endif
128
129 #define RTE_RING_NAMESIZE 32 /**< The maximum length of a ring name. */
130 #define RTE_RING_MZ_PREFIX "RG_"
131
132 #ifndef RTE_RING_PAUSE_REP_COUNT
133 #define RTE_RING_PAUSE_REP_COUNT 0 /**< Yield after pause num of times, no yield
134                                     *   if RTE_RING_PAUSE_REP not defined. */
135 #endif
136
137 struct rte_memzone; /* forward declaration, so as not to require memzone.h */
138
139 /**
140  * An RTE ring structure.
141  *
142  * The producer and the consumer have a head and a tail index. The particularity
143  * of these index is that they are not between 0 and size(ring). These indexes
144  * are between 0 and 2^32, and we mask their value when we access the ring[]
145  * field. Thanks to this assumption, we can do subtractions between 2 index
146  * values in a modulo-32bit base: that's why the overflow of the indexes is not
147  * a problem.
148  */
149 struct rte_ring {
150         char name[RTE_RING_NAMESIZE];    /**< Name of the ring. */
151         int flags;                       /**< Flags supplied at creation. */
152         const struct rte_memzone *memzone;
153                         /**< Memzone, if any, containing the rte_ring */
154
155         /** Ring producer status. */
156         struct prod {
157                 uint32_t watermark;      /**< Maximum items before EDQUOT. */
158                 uint32_t sp_enqueue;     /**< True, if single producer. */
159                 uint32_t size;           /**< Size of ring. */
160                 uint32_t mask;           /**< Mask (size-1) of ring. */
161                 volatile uint32_t head;  /**< Producer head. */
162                 volatile uint32_t tail;  /**< Producer tail. */
163         } prod __rte_cache_aligned;
164
165         /** Ring consumer status. */
166         struct cons {
167                 uint32_t sc_dequeue;     /**< True, if single consumer. */
168                 uint32_t size;           /**< Size of the ring. */
169                 uint32_t mask;           /**< Mask (size-1) of ring. */
170                 volatile uint32_t head;  /**< Consumer head. */
171                 volatile uint32_t tail;  /**< Consumer tail. */
172 #ifdef RTE_RING_SPLIT_PROD_CONS
173         } cons __rte_cache_aligned;
174 #else
175         } cons;
176 #endif
177
178 #ifdef RTE_LIBRTE_RING_DEBUG
179         struct rte_ring_debug_stats stats[RTE_MAX_LCORE];
180 #endif
181
182         void * ring[0] __rte_cache_aligned; /**< Memory space of ring starts here.
183                                              * not volatile so need to be careful
184                                              * about compiler re-ordering */
185 };
186
187 #define RING_F_SP_ENQ 0x0001 /**< The default enqueue is "single-producer". */
188 #define RING_F_SC_DEQ 0x0002 /**< The default dequeue is "single-consumer". */
189 #define RTE_RING_QUOT_EXCEED (1 << 31)  /**< Quota exceed for burst ops */
190 #define RTE_RING_SZ_MASK  (unsigned)(0x0fffffff) /**< Ring size mask */
191
192 /**
193  * @internal When debug is enabled, store ring statistics.
194  * @param r
195  *   A pointer to the ring.
196  * @param name
197  *   The name of the statistics field to increment in the ring.
198  * @param n
199  *   The number to add to the object-oriented statistics.
200  */
201 #ifdef RTE_LIBRTE_RING_DEBUG
202 #define __RING_STAT_ADD(r, name, n) do {                        \
203                 unsigned __lcore_id = rte_lcore_id();           \
204                 if (__lcore_id < RTE_MAX_LCORE) {               \
205                         r->stats[__lcore_id].name##_objs += n;  \
206                         r->stats[__lcore_id].name##_bulk += 1;  \
207                 }                                               \
208         } while(0)
209 #else
210 #define __RING_STAT_ADD(r, name, n) do {} while(0)
211 #endif
212
213 /**
214  * Calculate the memory size needed for a ring
215  *
216  * This function returns the number of bytes needed for a ring, given
217  * the number of elements in it. This value is the sum of the size of
218  * the structure rte_ring and the size of the memory needed by the
219  * objects pointers. The value is aligned to a cache line size.
220  *
221  * @param count
222  *   The number of elements in the ring (must be a power of 2).
223  * @return
224  *   - The memory size needed for the ring on success.
225  *   - -EINVAL if count is not a power of 2.
226  */
227 ssize_t rte_ring_get_memsize(unsigned count);
228
229 /**
230  * Initialize a ring structure.
231  *
232  * Initialize a ring structure in memory pointed by "r". The size of the
233  * memory area must be large enough to store the ring structure and the
234  * object table. It is advised to use rte_ring_get_memsize() to get the
235  * appropriate size.
236  *
237  * The ring size is set to *count*, which must be a power of two. Water
238  * marking is disabled by default. The real usable ring size is
239  * *count-1* instead of *count* to differentiate a free ring from an
240  * empty ring.
241  *
242  * The ring is not added in RTE_TAILQ_RING global list. Indeed, the
243  * memory given by the caller may not be shareable among dpdk
244  * processes.
245  *
246  * @param r
247  *   The pointer to the ring structure followed by the objects table.
248  * @param name
249  *   The name of the ring.
250  * @param count
251  *   The number of elements in the ring (must be a power of 2).
252  * @param flags
253  *   An OR of the following:
254  *    - RING_F_SP_ENQ: If this flag is set, the default behavior when
255  *      using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
256  *      is "single-producer". Otherwise, it is "multi-producers".
257  *    - RING_F_SC_DEQ: If this flag is set, the default behavior when
258  *      using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
259  *      is "single-consumer". Otherwise, it is "multi-consumers".
260  * @return
261  *   0 on success, or a negative value on error.
262  */
263 int rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
264         unsigned flags);
265
266 /**
267  * Create a new ring named *name* in memory.
268  *
269  * This function uses ``memzone_reserve()`` to allocate memory. Then it
270  * calls rte_ring_init() to initialize an empty ring.
271  *
272  * The new ring size is set to *count*, which must be a power of
273  * two. Water marking is disabled by default. The real usable ring size
274  * is *count-1* instead of *count* to differentiate a free ring from an
275  * empty ring.
276  *
277  * The ring is added in RTE_TAILQ_RING list.
278  *
279  * @param name
280  *   The name of the ring.
281  * @param count
282  *   The size of the ring (must be a power of 2).
283  * @param socket_id
284  *   The *socket_id* argument is the socket identifier in case of
285  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
286  *   constraint for the reserved zone.
287  * @param flags
288  *   An OR of the following:
289  *    - RING_F_SP_ENQ: If this flag is set, the default behavior when
290  *      using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()``
291  *      is "single-producer". Otherwise, it is "multi-producers".
292  *    - RING_F_SC_DEQ: If this flag is set, the default behavior when
293  *      using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()``
294  *      is "single-consumer". Otherwise, it is "multi-consumers".
295  * @return
296  *   On success, the pointer to the new allocated ring. NULL on error with
297  *    rte_errno set appropriately. Possible errno values include:
298  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
299  *    - E_RTE_SECONDARY - function was called from a secondary process instance
300  *    - EINVAL - count provided is not a power of 2
301  *    - ENOSPC - the maximum number of memzones has already been allocated
302  *    - EEXIST - a memzone with the same name already exists
303  *    - ENOMEM - no appropriate memory area found in which to create memzone
304  */
305 struct rte_ring *rte_ring_create(const char *name, unsigned count,
306                                  int socket_id, unsigned flags);
307 /**
308  * De-allocate all memory used by the ring.
309  *
310  * @param r
311  *   Ring to free
312  */
313 void rte_ring_free(struct rte_ring *r);
314
315 /**
316  * Change the high water mark.
317  *
318  * If *count* is 0, water marking is disabled. Otherwise, it is set to the
319  * *count* value. The *count* value must be greater than 0 and less
320  * than the ring size.
321  *
322  * This function can be called at any time (not necessarily at
323  * initialization).
324  *
325  * @param r
326  *   A pointer to the ring structure.
327  * @param count
328  *   The new water mark value.
329  * @return
330  *   - 0: Success; water mark changed.
331  *   - -EINVAL: Invalid water mark value.
332  */
333 int rte_ring_set_water_mark(struct rte_ring *r, unsigned count);
334
335 /**
336  * Dump the status of the ring to the console.
337  *
338  * @param f
339  *   A pointer to a file for output
340  * @param r
341  *   A pointer to the ring structure.
342  */
343 void rte_ring_dump(FILE *f, const struct rte_ring *r);
344
345 /* the actual enqueue of pointers on the ring.
346  * Placed here since identical code needed in both
347  * single and multi producer enqueue functions */
348 #define ENQUEUE_PTRS() do { \
349         const uint32_t size = r->prod.size; \
350         uint32_t idx = prod_head & mask; \
351         if (likely(idx + n < size)) { \
352                 for (i = 0; i < (n & ((~(unsigned)0x3))); i+=4, idx+=4) { \
353                         r->ring[idx] = obj_table[i]; \
354                         r->ring[idx+1] = obj_table[i+1]; \
355                         r->ring[idx+2] = obj_table[i+2]; \
356                         r->ring[idx+3] = obj_table[i+3]; \
357                 } \
358                 switch (n & 0x3) { \
359                         case 3: r->ring[idx++] = obj_table[i++]; \
360                         case 2: r->ring[idx++] = obj_table[i++]; \
361                         case 1: r->ring[idx++] = obj_table[i++]; \
362                 } \
363         } else { \
364                 for (i = 0; idx < size; i++, idx++)\
365                         r->ring[idx] = obj_table[i]; \
366                 for (idx = 0; i < n; i++, idx++) \
367                         r->ring[idx] = obj_table[i]; \
368         } \
369 } while(0)
370
371 /* the actual copy of pointers on the ring to obj_table.
372  * Placed here since identical code needed in both
373  * single and multi consumer dequeue functions */
374 #define DEQUEUE_PTRS() do { \
375         uint32_t idx = cons_head & mask; \
376         const uint32_t size = r->cons.size; \
377         if (likely(idx + n < size)) { \
378                 for (i = 0; i < (n & (~(unsigned)0x3)); i+=4, idx+=4) {\
379                         obj_table[i] = r->ring[idx]; \
380                         obj_table[i+1] = r->ring[idx+1]; \
381                         obj_table[i+2] = r->ring[idx+2]; \
382                         obj_table[i+3] = r->ring[idx+3]; \
383                 } \
384                 switch (n & 0x3) { \
385                         case 3: obj_table[i++] = r->ring[idx++]; \
386                         case 2: obj_table[i++] = r->ring[idx++]; \
387                         case 1: obj_table[i++] = r->ring[idx++]; \
388                 } \
389         } else { \
390                 for (i = 0; idx < size; i++, idx++) \
391                         obj_table[i] = r->ring[idx]; \
392                 for (idx = 0; i < n; i++, idx++) \
393                         obj_table[i] = r->ring[idx]; \
394         } \
395 } while (0)
396
397 /**
398  * @internal Enqueue several objects on the ring (multi-producers safe).
399  *
400  * This function uses a "compare and set" instruction to move the
401  * producer index atomically.
402  *
403  * @param r
404  *   A pointer to the ring structure.
405  * @param obj_table
406  *   A pointer to a table of void * pointers (objects).
407  * @param n
408  *   The number of objects to add in the ring from the obj_table.
409  * @param behavior
410  *   RTE_RING_QUEUE_FIXED:    Enqueue a fixed number of items from a ring
411  *   RTE_RING_QUEUE_VARIABLE: Enqueue as many items a possible from ring
412  * @return
413  *   Depend on the behavior value
414  *   if behavior = RTE_RING_QUEUE_FIXED
415  *   - 0: Success; objects enqueue.
416  *   - -EDQUOT: Quota exceeded. The objects have been enqueued, but the
417  *     high water mark is exceeded.
418  *   - -ENOBUFS: Not enough room in the ring to enqueue, no object is enqueued.
419  *   if behavior = RTE_RING_QUEUE_VARIABLE
420  *   - n: Actual number of objects enqueued.
421  */
422 static inline int __attribute__((always_inline))
423 __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table,
424                          unsigned n, enum rte_ring_queue_behavior behavior)
425 {
426         uint32_t prod_head, prod_next;
427         uint32_t cons_tail, free_entries;
428         const unsigned max = n;
429         int success;
430         unsigned i, rep = 0;
431         uint32_t mask = r->prod.mask;
432         int ret;
433
434         /* Avoid the unnecessary cmpset operation below, which is also
435          * potentially harmful when n equals 0. */
436         if (n == 0)
437                 return 0;
438
439         /* move prod.head atomically */
440         do {
441                 /* Reset n to the initial burst count */
442                 n = max;
443
444                 prod_head = r->prod.head;
445                 cons_tail = r->cons.tail;
446                 /* The subtraction is done between two unsigned 32bits value
447                  * (the result is always modulo 32 bits even if we have
448                  * prod_head > cons_tail). So 'free_entries' is always between 0
449                  * and size(ring)-1. */
450                 free_entries = (mask + cons_tail - prod_head);
451
452                 /* check that we have enough room in ring */
453                 if (unlikely(n > free_entries)) {
454                         if (behavior == RTE_RING_QUEUE_FIXED) {
455                                 __RING_STAT_ADD(r, enq_fail, n);
456                                 return -ENOBUFS;
457                         }
458                         else {
459                                 /* No free entry available */
460                                 if (unlikely(free_entries == 0)) {
461                                         __RING_STAT_ADD(r, enq_fail, n);
462                                         return 0;
463                                 }
464
465                                 n = free_entries;
466                         }
467                 }
468
469                 prod_next = prod_head + n;
470                 success = rte_atomic32_cmpset(&r->prod.head, prod_head,
471                                               prod_next);
472         } while (unlikely(success == 0));
473
474         /* write entries in ring */
475         ENQUEUE_PTRS();
476         rte_smp_wmb();
477
478         /* if we exceed the watermark */
479         if (unlikely(((mask + 1) - free_entries + n) > r->prod.watermark)) {
480                 ret = (behavior == RTE_RING_QUEUE_FIXED) ? -EDQUOT :
481                                 (int)(n | RTE_RING_QUOT_EXCEED);
482                 __RING_STAT_ADD(r, enq_quota, n);
483         }
484         else {
485                 ret = (behavior == RTE_RING_QUEUE_FIXED) ? 0 : n;
486                 __RING_STAT_ADD(r, enq_success, n);
487         }
488
489         /*
490          * If there are other enqueues in progress that preceded us,
491          * we need to wait for them to complete
492          */
493         while (unlikely(r->prod.tail != prod_head)) {
494                 rte_pause();
495
496                 /* Set RTE_RING_PAUSE_REP_COUNT to avoid spin too long waiting
497                  * for other thread finish. It gives pre-empted thread a chance
498                  * to proceed and finish with ring dequeue operation. */
499                 if (RTE_RING_PAUSE_REP_COUNT &&
500                     ++rep == RTE_RING_PAUSE_REP_COUNT) {
501                         rep = 0;
502                         sched_yield();
503                 }
504         }
505         r->prod.tail = prod_next;
506         return ret;
507 }
508
509 /**
510  * @internal Enqueue several objects on a ring (NOT multi-producers safe).
511  *
512  * @param r
513  *   A pointer to the ring structure.
514  * @param obj_table
515  *   A pointer to a table of void * pointers (objects).
516  * @param n
517  *   The number of objects to add in the ring from the obj_table.
518  * @param behavior
519  *   RTE_RING_QUEUE_FIXED:    Enqueue a fixed number of items from a ring
520  *   RTE_RING_QUEUE_VARIABLE: Enqueue as many items a possible from ring
521  * @return
522  *   Depend on the behavior value
523  *   if behavior = RTE_RING_QUEUE_FIXED
524  *   - 0: Success; objects enqueue.
525  *   - -EDQUOT: Quota exceeded. The objects have been enqueued, but the
526  *     high water mark is exceeded.
527  *   - -ENOBUFS: Not enough room in the ring to enqueue, no object is enqueued.
528  *   if behavior = RTE_RING_QUEUE_VARIABLE
529  *   - n: Actual number of objects enqueued.
530  */
531 static inline int __attribute__((always_inline))
532 __rte_ring_sp_do_enqueue(struct rte_ring *r, void * const *obj_table,
533                          unsigned n, enum rte_ring_queue_behavior behavior)
534 {
535         uint32_t prod_head, cons_tail;
536         uint32_t prod_next, free_entries;
537         unsigned i;
538         uint32_t mask = r->prod.mask;
539         int ret;
540
541         prod_head = r->prod.head;
542         cons_tail = r->cons.tail;
543         /* The subtraction is done between two unsigned 32bits value
544          * (the result is always modulo 32 bits even if we have
545          * prod_head > cons_tail). So 'free_entries' is always between 0
546          * and size(ring)-1. */
547         free_entries = mask + cons_tail - prod_head;
548
549         /* check that we have enough room in ring */
550         if (unlikely(n > free_entries)) {
551                 if (behavior == RTE_RING_QUEUE_FIXED) {
552                         __RING_STAT_ADD(r, enq_fail, n);
553                         return -ENOBUFS;
554                 }
555                 else {
556                         /* No free entry available */
557                         if (unlikely(free_entries == 0)) {
558                                 __RING_STAT_ADD(r, enq_fail, n);
559                                 return 0;
560                         }
561
562                         n = free_entries;
563                 }
564         }
565
566         prod_next = prod_head + n;
567         r->prod.head = prod_next;
568
569         /* write entries in ring */
570         ENQUEUE_PTRS();
571         rte_smp_wmb();
572
573         /* if we exceed the watermark */
574         if (unlikely(((mask + 1) - free_entries + n) > r->prod.watermark)) {
575                 ret = (behavior == RTE_RING_QUEUE_FIXED) ? -EDQUOT :
576                         (int)(n | RTE_RING_QUOT_EXCEED);
577                 __RING_STAT_ADD(r, enq_quota, n);
578         }
579         else {
580                 ret = (behavior == RTE_RING_QUEUE_FIXED) ? 0 : n;
581                 __RING_STAT_ADD(r, enq_success, n);
582         }
583
584         r->prod.tail = prod_next;
585         return ret;
586 }
587
588 /**
589  * @internal Dequeue several objects from a ring (multi-consumers safe). When
590  * the request objects are more than the available objects, only dequeue the
591  * actual number of objects
592  *
593  * This function uses a "compare and set" instruction to move the
594  * consumer index atomically.
595  *
596  * @param r
597  *   A pointer to the ring structure.
598  * @param obj_table
599  *   A pointer to a table of void * pointers (objects) that will be filled.
600  * @param n
601  *   The number of objects to dequeue from the ring to the obj_table.
602  * @param behavior
603  *   RTE_RING_QUEUE_FIXED:    Dequeue a fixed number of items from a ring
604  *   RTE_RING_QUEUE_VARIABLE: Dequeue as many items a possible from ring
605  * @return
606  *   Depend on the behavior value
607  *   if behavior = RTE_RING_QUEUE_FIXED
608  *   - 0: Success; objects dequeued.
609  *   - -ENOENT: Not enough entries in the ring to dequeue; no object is
610  *     dequeued.
611  *   if behavior = RTE_RING_QUEUE_VARIABLE
612  *   - n: Actual number of objects dequeued.
613  */
614
615 static inline int __attribute__((always_inline))
616 __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table,
617                  unsigned n, enum rte_ring_queue_behavior behavior)
618 {
619         uint32_t cons_head, prod_tail;
620         uint32_t cons_next, entries;
621         const unsigned max = n;
622         int success;
623         unsigned i, rep = 0;
624         uint32_t mask = r->prod.mask;
625
626         /* Avoid the unnecessary cmpset operation below, which is also
627          * potentially harmful when n equals 0. */
628         if (n == 0)
629                 return 0;
630
631         /* move cons.head atomically */
632         do {
633                 /* Restore n as it may change every loop */
634                 n = max;
635
636                 cons_head = r->cons.head;
637                 prod_tail = r->prod.tail;
638                 /* The subtraction is done between two unsigned 32bits value
639                  * (the result is always modulo 32 bits even if we have
640                  * cons_head > prod_tail). So 'entries' is always between 0
641                  * and size(ring)-1. */
642                 entries = (prod_tail - cons_head);
643
644                 /* Set the actual entries for dequeue */
645                 if (n > entries) {
646                         if (behavior == RTE_RING_QUEUE_FIXED) {
647                                 __RING_STAT_ADD(r, deq_fail, n);
648                                 return -ENOENT;
649                         }
650                         else {
651                                 if (unlikely(entries == 0)){
652                                         __RING_STAT_ADD(r, deq_fail, n);
653                                         return 0;
654                                 }
655
656                                 n = entries;
657                         }
658                 }
659
660                 cons_next = cons_head + n;
661                 success = rte_atomic32_cmpset(&r->cons.head, cons_head,
662                                               cons_next);
663         } while (unlikely(success == 0));
664
665         /* copy in table */
666         DEQUEUE_PTRS();
667         rte_smp_rmb();
668
669         /*
670          * If there are other dequeues in progress that preceded us,
671          * we need to wait for them to complete
672          */
673         while (unlikely(r->cons.tail != cons_head)) {
674                 rte_pause();
675
676                 /* Set RTE_RING_PAUSE_REP_COUNT to avoid spin too long waiting
677                  * for other thread finish. It gives pre-empted thread a chance
678                  * to proceed and finish with ring dequeue operation. */
679                 if (RTE_RING_PAUSE_REP_COUNT &&
680                     ++rep == RTE_RING_PAUSE_REP_COUNT) {
681                         rep = 0;
682                         sched_yield();
683                 }
684         }
685         __RING_STAT_ADD(r, deq_success, n);
686         r->cons.tail = cons_next;
687
688         return behavior == RTE_RING_QUEUE_FIXED ? 0 : n;
689 }
690
691 /**
692  * @internal Dequeue several objects from a ring (NOT multi-consumers safe).
693  * When the request objects are more than the available objects, only dequeue
694  * the actual number of objects
695  *
696  * @param r
697  *   A pointer to the ring structure.
698  * @param obj_table
699  *   A pointer to a table of void * pointers (objects) that will be filled.
700  * @param n
701  *   The number of objects to dequeue from the ring to the obj_table.
702  * @param behavior
703  *   RTE_RING_QUEUE_FIXED:    Dequeue a fixed number of items from a ring
704  *   RTE_RING_QUEUE_VARIABLE: Dequeue as many items a possible from ring
705  * @return
706  *   Depend on the behavior value
707  *   if behavior = RTE_RING_QUEUE_FIXED
708  *   - 0: Success; objects dequeued.
709  *   - -ENOENT: Not enough entries in the ring to dequeue; no object is
710  *     dequeued.
711  *   if behavior = RTE_RING_QUEUE_VARIABLE
712  *   - n: Actual number of objects dequeued.
713  */
714 static inline int __attribute__((always_inline))
715 __rte_ring_sc_do_dequeue(struct rte_ring *r, void **obj_table,
716                  unsigned n, enum rte_ring_queue_behavior behavior)
717 {
718         uint32_t cons_head, prod_tail;
719         uint32_t cons_next, entries;
720         unsigned i;
721         uint32_t mask = r->prod.mask;
722
723         cons_head = r->cons.head;
724         prod_tail = r->prod.tail;
725         /* The subtraction is done between two unsigned 32bits value
726          * (the result is always modulo 32 bits even if we have
727          * cons_head > prod_tail). So 'entries' is always between 0
728          * and size(ring)-1. */
729         entries = prod_tail - cons_head;
730
731         if (n > entries) {
732                 if (behavior == RTE_RING_QUEUE_FIXED) {
733                         __RING_STAT_ADD(r, deq_fail, n);
734                         return -ENOENT;
735                 }
736                 else {
737                         if (unlikely(entries == 0)){
738                                 __RING_STAT_ADD(r, deq_fail, n);
739                                 return 0;
740                         }
741
742                         n = entries;
743                 }
744         }
745
746         cons_next = cons_head + n;
747         r->cons.head = cons_next;
748
749         /* copy in table */
750         DEQUEUE_PTRS();
751         rte_smp_rmb();
752
753         __RING_STAT_ADD(r, deq_success, n);
754         r->cons.tail = cons_next;
755         return behavior == RTE_RING_QUEUE_FIXED ? 0 : n;
756 }
757
758 /**
759  * Enqueue several objects on the ring (multi-producers safe).
760  *
761  * This function uses a "compare and set" instruction to move the
762  * producer index atomically.
763  *
764  * @param r
765  *   A pointer to the ring structure.
766  * @param obj_table
767  *   A pointer to a table of void * pointers (objects).
768  * @param n
769  *   The number of objects to add in the ring from the obj_table.
770  * @return
771  *   - 0: Success; objects enqueue.
772  *   - -EDQUOT: Quota exceeded. The objects have been enqueued, but the
773  *     high water mark is exceeded.
774  *   - -ENOBUFS: Not enough room in the ring to enqueue, no object is enqueued.
775  */
776 static inline int __attribute__((always_inline))
777 rte_ring_mp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
778                          unsigned n)
779 {
780         return __rte_ring_mp_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED);
781 }
782
783 /**
784  * Enqueue several objects on a ring (NOT multi-producers safe).
785  *
786  * @param r
787  *   A pointer to the ring structure.
788  * @param obj_table
789  *   A pointer to a table of void * pointers (objects).
790  * @param n
791  *   The number of objects to add in the ring from the obj_table.
792  * @return
793  *   - 0: Success; objects enqueued.
794  *   - -EDQUOT: Quota exceeded. The objects have been enqueued, but the
795  *     high water mark is exceeded.
796  *   - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
797  */
798 static inline int __attribute__((always_inline))
799 rte_ring_sp_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
800                          unsigned n)
801 {
802         return __rte_ring_sp_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_FIXED);
803 }
804
805 /**
806  * Enqueue several objects on a ring.
807  *
808  * This function calls the multi-producer or the single-producer
809  * version depending on the default behavior that was specified at
810  * ring creation time (see flags).
811  *
812  * @param r
813  *   A pointer to the ring structure.
814  * @param obj_table
815  *   A pointer to a table of void * pointers (objects).
816  * @param n
817  *   The number of objects to add in the ring from the obj_table.
818  * @return
819  *   - 0: Success; objects enqueued.
820  *   - -EDQUOT: Quota exceeded. The objects have been enqueued, but the
821  *     high water mark is exceeded.
822  *   - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
823  */
824 static inline int __attribute__((always_inline))
825 rte_ring_enqueue_bulk(struct rte_ring *r, void * const *obj_table,
826                       unsigned n)
827 {
828         if (r->prod.sp_enqueue)
829                 return rte_ring_sp_enqueue_bulk(r, obj_table, n);
830         else
831                 return rte_ring_mp_enqueue_bulk(r, obj_table, n);
832 }
833
834 /**
835  * Enqueue one object on a ring (multi-producers safe).
836  *
837  * This function uses a "compare and set" instruction to move the
838  * producer index atomically.
839  *
840  * @param r
841  *   A pointer to the ring structure.
842  * @param obj
843  *   A pointer to the object to be added.
844  * @return
845  *   - 0: Success; objects enqueued.
846  *   - -EDQUOT: Quota exceeded. The objects have been enqueued, but the
847  *     high water mark is exceeded.
848  *   - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
849  */
850 static inline int __attribute__((always_inline))
851 rte_ring_mp_enqueue(struct rte_ring *r, void *obj)
852 {
853         return rte_ring_mp_enqueue_bulk(r, &obj, 1);
854 }
855
856 /**
857  * Enqueue one object on a ring (NOT multi-producers safe).
858  *
859  * @param r
860  *   A pointer to the ring structure.
861  * @param obj
862  *   A pointer to the object to be added.
863  * @return
864  *   - 0: Success; objects enqueued.
865  *   - -EDQUOT: Quota exceeded. The objects have been enqueued, but the
866  *     high water mark is exceeded.
867  *   - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
868  */
869 static inline int __attribute__((always_inline))
870 rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
871 {
872         return rte_ring_sp_enqueue_bulk(r, &obj, 1);
873 }
874
875 /**
876  * Enqueue one object on a ring.
877  *
878  * This function calls the multi-producer or the single-producer
879  * version, depending on the default behaviour that was specified at
880  * ring creation time (see flags).
881  *
882  * @param r
883  *   A pointer to the ring structure.
884  * @param obj
885  *   A pointer to the object to be added.
886  * @return
887  *   - 0: Success; objects enqueued.
888  *   - -EDQUOT: Quota exceeded. The objects have been enqueued, but the
889  *     high water mark is exceeded.
890  *   - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
891  */
892 static inline int __attribute__((always_inline))
893 rte_ring_enqueue(struct rte_ring *r, void *obj)
894 {
895         if (r->prod.sp_enqueue)
896                 return rte_ring_sp_enqueue(r, obj);
897         else
898                 return rte_ring_mp_enqueue(r, obj);
899 }
900
901 /**
902  * Dequeue several objects from a ring (multi-consumers safe).
903  *
904  * This function uses a "compare and set" instruction to move the
905  * consumer index atomically.
906  *
907  * @param r
908  *   A pointer to the ring structure.
909  * @param obj_table
910  *   A pointer to a table of void * pointers (objects) that will be filled.
911  * @param n
912  *   The number of objects to dequeue from the ring to the obj_table.
913  * @return
914  *   - 0: Success; objects dequeued.
915  *   - -ENOENT: Not enough entries in the ring to dequeue; no object is
916  *     dequeued.
917  */
918 static inline int __attribute__((always_inline))
919 rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned n)
920 {
921         return __rte_ring_mc_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED);
922 }
923
924 /**
925  * Dequeue several objects from a ring (NOT multi-consumers safe).
926  *
927  * @param r
928  *   A pointer to the ring structure.
929  * @param obj_table
930  *   A pointer to a table of void * pointers (objects) that will be filled.
931  * @param n
932  *   The number of objects to dequeue from the ring to the obj_table,
933  *   must be strictly positive.
934  * @return
935  *   - 0: Success; objects dequeued.
936  *   - -ENOENT: Not enough entries in the ring to dequeue; no object is
937  *     dequeued.
938  */
939 static inline int __attribute__((always_inline))
940 rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned n)
941 {
942         return __rte_ring_sc_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_FIXED);
943 }
944
945 /**
946  * Dequeue several objects from a ring.
947  *
948  * This function calls the multi-consumers or the single-consumer
949  * version, depending on the default behaviour that was specified at
950  * ring creation time (see flags).
951  *
952  * @param r
953  *   A pointer to the ring structure.
954  * @param obj_table
955  *   A pointer to a table of void * pointers (objects) that will be filled.
956  * @param n
957  *   The number of objects to dequeue from the ring to the obj_table.
958  * @return
959  *   - 0: Success; objects dequeued.
960  *   - -ENOENT: Not enough entries in the ring to dequeue, no object is
961  *     dequeued.
962  */
963 static inline int __attribute__((always_inline))
964 rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned n)
965 {
966         if (r->cons.sc_dequeue)
967                 return rte_ring_sc_dequeue_bulk(r, obj_table, n);
968         else
969                 return rte_ring_mc_dequeue_bulk(r, obj_table, n);
970 }
971
972 /**
973  * Dequeue one object from a ring (multi-consumers safe).
974  *
975  * This function uses a "compare and set" instruction to move the
976  * consumer index atomically.
977  *
978  * @param r
979  *   A pointer to the ring structure.
980  * @param obj_p
981  *   A pointer to a void * pointer (object) that will be filled.
982  * @return
983  *   - 0: Success; objects dequeued.
984  *   - -ENOENT: Not enough entries in the ring to dequeue; no object is
985  *     dequeued.
986  */
987 static inline int __attribute__((always_inline))
988 rte_ring_mc_dequeue(struct rte_ring *r, void **obj_p)
989 {
990         return rte_ring_mc_dequeue_bulk(r, obj_p, 1);
991 }
992
993 /**
994  * Dequeue one object from a ring (NOT multi-consumers safe).
995  *
996  * @param r
997  *   A pointer to the ring structure.
998  * @param obj_p
999  *   A pointer to a void * pointer (object) that will be filled.
1000  * @return
1001  *   - 0: Success; objects dequeued.
1002  *   - -ENOENT: Not enough entries in the ring to dequeue, no object is
1003  *     dequeued.
1004  */
1005 static inline int __attribute__((always_inline))
1006 rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
1007 {
1008         return rte_ring_sc_dequeue_bulk(r, obj_p, 1);
1009 }
1010
1011 /**
1012  * Dequeue one object from a ring.
1013  *
1014  * This function calls the multi-consumers or the single-consumer
1015  * version depending on the default behaviour that was specified at
1016  * ring creation time (see flags).
1017  *
1018  * @param r
1019  *   A pointer to the ring structure.
1020  * @param obj_p
1021  *   A pointer to a void * pointer (object) that will be filled.
1022  * @return
1023  *   - 0: Success, objects dequeued.
1024  *   - -ENOENT: Not enough entries in the ring to dequeue, no object is
1025  *     dequeued.
1026  */
1027 static inline int __attribute__((always_inline))
1028 rte_ring_dequeue(struct rte_ring *r, void **obj_p)
1029 {
1030         if (r->cons.sc_dequeue)
1031                 return rte_ring_sc_dequeue(r, obj_p);
1032         else
1033                 return rte_ring_mc_dequeue(r, obj_p);
1034 }
1035
1036 /**
1037  * Test if a ring is full.
1038  *
1039  * @param r
1040  *   A pointer to the ring structure.
1041  * @return
1042  *   - 1: The ring is full.
1043  *   - 0: The ring is not full.
1044  */
1045 static inline int
1046 rte_ring_full(const struct rte_ring *r)
1047 {
1048         uint32_t prod_tail = r->prod.tail;
1049         uint32_t cons_tail = r->cons.tail;
1050         return ((cons_tail - prod_tail - 1) & r->prod.mask) == 0;
1051 }
1052
1053 /**
1054  * Test if a ring is empty.
1055  *
1056  * @param r
1057  *   A pointer to the ring structure.
1058  * @return
1059  *   - 1: The ring is empty.
1060  *   - 0: The ring is not empty.
1061  */
1062 static inline int
1063 rte_ring_empty(const struct rte_ring *r)
1064 {
1065         uint32_t prod_tail = r->prod.tail;
1066         uint32_t cons_tail = r->cons.tail;
1067         return !!(cons_tail == prod_tail);
1068 }
1069
1070 /**
1071  * Return the number of entries in a ring.
1072  *
1073  * @param r
1074  *   A pointer to the ring structure.
1075  * @return
1076  *   The number of entries in the ring.
1077  */
1078 static inline unsigned
1079 rte_ring_count(const struct rte_ring *r)
1080 {
1081         uint32_t prod_tail = r->prod.tail;
1082         uint32_t cons_tail = r->cons.tail;
1083         return (prod_tail - cons_tail) & r->prod.mask;
1084 }
1085
1086 /**
1087  * Return the number of free entries in a ring.
1088  *
1089  * @param r
1090  *   A pointer to the ring structure.
1091  * @return
1092  *   The number of free entries in the ring.
1093  */
1094 static inline unsigned
1095 rte_ring_free_count(const struct rte_ring *r)
1096 {
1097         uint32_t prod_tail = r->prod.tail;
1098         uint32_t cons_tail = r->cons.tail;
1099         return (cons_tail - prod_tail - 1) & r->prod.mask;
1100 }
1101
1102 /**
1103  * Dump the status of all rings on the console
1104  *
1105  * @param f
1106  *   A pointer to a file for output
1107  */
1108 void rte_ring_list_dump(FILE *f);
1109
1110 /**
1111  * Search a ring from its name
1112  *
1113  * @param name
1114  *   The name of the ring.
1115  * @return
1116  *   The pointer to the ring matching the name, or NULL if not found,
1117  *   with rte_errno set appropriately. Possible rte_errno values include:
1118  *    - ENOENT - required entry not available to return.
1119  */
1120 struct rte_ring *rte_ring_lookup(const char *name);
1121
1122 /**
1123  * Enqueue several objects on the ring (multi-producers safe).
1124  *
1125  * This function uses a "compare and set" instruction to move the
1126  * producer index atomically.
1127  *
1128  * @param r
1129  *   A pointer to the ring structure.
1130  * @param obj_table
1131  *   A pointer to a table of void * pointers (objects).
1132  * @param n
1133  *   The number of objects to add in the ring from the obj_table.
1134  * @return
1135  *   - n: Actual number of objects enqueued.
1136  */
1137 static inline unsigned __attribute__((always_inline))
1138 rte_ring_mp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
1139                          unsigned n)
1140 {
1141         return __rte_ring_mp_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_VARIABLE);
1142 }
1143
1144 /**
1145  * Enqueue several objects on a ring (NOT multi-producers safe).
1146  *
1147  * @param r
1148  *   A pointer to the ring structure.
1149  * @param obj_table
1150  *   A pointer to a table of void * pointers (objects).
1151  * @param n
1152  *   The number of objects to add in the ring from the obj_table.
1153  * @return
1154  *   - n: Actual number of objects enqueued.
1155  */
1156 static inline unsigned __attribute__((always_inline))
1157 rte_ring_sp_enqueue_burst(struct rte_ring *r, void * const *obj_table,
1158                          unsigned n)
1159 {
1160         return __rte_ring_sp_do_enqueue(r, obj_table, n, RTE_RING_QUEUE_VARIABLE);
1161 }
1162
1163 /**
1164  * Enqueue several objects on a ring.
1165  *
1166  * This function calls the multi-producer or the single-producer
1167  * version depending on the default behavior that was specified at
1168  * ring creation time (see flags).
1169  *
1170  * @param r
1171  *   A pointer to the ring structure.
1172  * @param obj_table
1173  *   A pointer to a table of void * pointers (objects).
1174  * @param n
1175  *   The number of objects to add in the ring from the obj_table.
1176  * @return
1177  *   - n: Actual number of objects enqueued.
1178  */
1179 static inline unsigned __attribute__((always_inline))
1180 rte_ring_enqueue_burst(struct rte_ring *r, void * const *obj_table,
1181                       unsigned n)
1182 {
1183         if (r->prod.sp_enqueue)
1184                 return rte_ring_sp_enqueue_burst(r, obj_table, n);
1185         else
1186                 return rte_ring_mp_enqueue_burst(r, obj_table, n);
1187 }
1188
1189 /**
1190  * Dequeue several objects from a ring (multi-consumers safe). When the request
1191  * objects are more than the available objects, only dequeue the actual number
1192  * of objects
1193  *
1194  * This function uses a "compare and set" instruction to move the
1195  * consumer index atomically.
1196  *
1197  * @param r
1198  *   A pointer to the ring structure.
1199  * @param obj_table
1200  *   A pointer to a table of void * pointers (objects) that will be filled.
1201  * @param n
1202  *   The number of objects to dequeue from the ring to the obj_table.
1203  * @return
1204  *   - n: Actual number of objects dequeued, 0 if ring is empty
1205  */
1206 static inline unsigned __attribute__((always_inline))
1207 rte_ring_mc_dequeue_burst(struct rte_ring *r, void **obj_table, unsigned n)
1208 {
1209         return __rte_ring_mc_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_VARIABLE);
1210 }
1211
1212 /**
1213  * Dequeue several objects from a ring (NOT multi-consumers safe).When the
1214  * request objects are more than the available objects, only dequeue the
1215  * actual number of objects
1216  *
1217  * @param r
1218  *   A pointer to the ring structure.
1219  * @param obj_table
1220  *   A pointer to a table of void * pointers (objects) that will be filled.
1221  * @param n
1222  *   The number of objects to dequeue from the ring to the obj_table.
1223  * @return
1224  *   - n: Actual number of objects dequeued, 0 if ring is empty
1225  */
1226 static inline unsigned __attribute__((always_inline))
1227 rte_ring_sc_dequeue_burst(struct rte_ring *r, void **obj_table, unsigned n)
1228 {
1229         return __rte_ring_sc_do_dequeue(r, obj_table, n, RTE_RING_QUEUE_VARIABLE);
1230 }
1231
1232 /**
1233  * Dequeue multiple objects from a ring up to a maximum number.
1234  *
1235  * This function calls the multi-consumers or the single-consumer
1236  * version, depending on the default behaviour that was specified at
1237  * ring creation time (see flags).
1238  *
1239  * @param r
1240  *   A pointer to the ring structure.
1241  * @param obj_table
1242  *   A pointer to a table of void * pointers (objects) that will be filled.
1243  * @param n
1244  *   The number of objects to dequeue from the ring to the obj_table.
1245  * @return
1246  *   - Number of objects dequeued
1247  */
1248 static inline unsigned __attribute__((always_inline))
1249 rte_ring_dequeue_burst(struct rte_ring *r, void **obj_table, unsigned n)
1250 {
1251         if (r->cons.sc_dequeue)
1252                 return rte_ring_sc_dequeue_burst(r, obj_table, n);
1253         else
1254                 return rte_ring_mc_dequeue_burst(r, obj_table, n);
1255 }
1256
1257 #ifdef __cplusplus
1258 }
1259 #endif
1260
1261 #endif /* _RTE_RING_H_ */