DPDK  23.03.0
rte_ring_elem.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2019 Arm Limited
4  * Copyright (c) 2010-2017 Intel Corporation
5  * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
6  * All rights reserved.
7  * Derived from FreeBSD's bufring.h
8  * Used as BSD-3 Licensed with permission from Kip Macy.
9  */
10 
11 #ifndef _RTE_RING_ELEM_H_
12 #define _RTE_RING_ELEM_H_
13 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include <rte_ring_core.h>
24 #include <rte_ring_elem_pvt.h>
25 
44 ssize_t rte_ring_get_memsize_elem(unsigned int esize, unsigned int count);
45 
105 struct rte_ring *rte_ring_create_elem(const char *name, unsigned int esize,
106  unsigned int count, int socket_id, unsigned int flags);
107 
130 static __rte_always_inline unsigned int
131 rte_ring_mp_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table,
132  unsigned int esize, unsigned int n, unsigned int *free_space)
133 {
134  return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
136 }
137 
159 static __rte_always_inline unsigned int
160 rte_ring_sp_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table,
161  unsigned int esize, unsigned int n, unsigned int *free_space)
162 {
163  return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
165 }
166 
167 #include <rte_ring_hts.h>
168 #include <rte_ring_rts.h>
169 
193 static __rte_always_inline unsigned int
194 rte_ring_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table,
195  unsigned int esize, unsigned int n, unsigned int *free_space)
196 {
197  switch (r->prod.sync_type) {
198  case RTE_RING_SYNC_MT:
199  return rte_ring_mp_enqueue_bulk_elem(r, obj_table, esize, n,
200  free_space);
201  case RTE_RING_SYNC_ST:
202  return rte_ring_sp_enqueue_bulk_elem(r, obj_table, esize, n,
203  free_space);
205  return rte_ring_mp_rts_enqueue_bulk_elem(r, obj_table, esize, n,
206  free_space);
208  return rte_ring_mp_hts_enqueue_bulk_elem(r, obj_table, esize, n,
209  free_space);
210  }
211 
212  /* valid ring should never reach this point */
213  RTE_ASSERT(0);
214  if (free_space != NULL)
215  *free_space = 0;
216  return 0;
217 }
218 
237 static __rte_always_inline int
238 rte_ring_mp_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
239 {
240  return rte_ring_mp_enqueue_bulk_elem(r, obj, esize, 1, NULL) ? 0 :
241  -ENOBUFS;
242 }
243 
261 static __rte_always_inline int
262 rte_ring_sp_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
263 {
264  return rte_ring_sp_enqueue_bulk_elem(r, obj, esize, 1, NULL) ? 0 :
265  -ENOBUFS;
266 }
267 
287 static __rte_always_inline int
288 rte_ring_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
289 {
290  return rte_ring_enqueue_bulk_elem(r, obj, esize, 1, NULL) ? 0 :
291  -ENOBUFS;
292 }
293 
316 static __rte_always_inline unsigned int
317 rte_ring_mc_dequeue_bulk_elem(struct rte_ring *r, void *obj_table,
318  unsigned int esize, unsigned int n, unsigned int *available)
319 {
320  return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
322 }
323 
344 static __rte_always_inline unsigned int
345 rte_ring_sc_dequeue_bulk_elem(struct rte_ring *r, void *obj_table,
346  unsigned int esize, unsigned int n, unsigned int *available)
347 {
348  return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
350 }
351 
375 static __rte_always_inline unsigned int
376 rte_ring_dequeue_bulk_elem(struct rte_ring *r, void *obj_table,
377  unsigned int esize, unsigned int n, unsigned int *available)
378 {
379  switch (r->cons.sync_type) {
380  case RTE_RING_SYNC_MT:
381  return rte_ring_mc_dequeue_bulk_elem(r, obj_table, esize, n,
382  available);
383  case RTE_RING_SYNC_ST:
384  return rte_ring_sc_dequeue_bulk_elem(r, obj_table, esize, n,
385  available);
387  return rte_ring_mc_rts_dequeue_bulk_elem(r, obj_table, esize,
388  n, available);
390  return rte_ring_mc_hts_dequeue_bulk_elem(r, obj_table, esize,
391  n, available);
392  }
393 
394  /* valid ring should never reach this point */
395  RTE_ASSERT(0);
396  if (available != NULL)
397  *available = 0;
398  return 0;
399 }
400 
420 static __rte_always_inline int
421 rte_ring_mc_dequeue_elem(struct rte_ring *r, void *obj_p,
422  unsigned int esize)
423 {
424  return rte_ring_mc_dequeue_bulk_elem(r, obj_p, esize, 1, NULL) ? 0 :
425  -ENOENT;
426 }
427 
444 static __rte_always_inline int
445 rte_ring_sc_dequeue_elem(struct rte_ring *r, void *obj_p,
446  unsigned int esize)
447 {
448  return rte_ring_sc_dequeue_bulk_elem(r, obj_p, esize, 1, NULL) ? 0 :
449  -ENOENT;
450 }
451 
472 static __rte_always_inline int
473 rte_ring_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
474 {
475  return rte_ring_dequeue_bulk_elem(r, obj_p, esize, 1, NULL) ? 0 :
476  -ENOENT;
477 }
478 
501 static __rte_always_inline unsigned int
502 rte_ring_mp_enqueue_burst_elem(struct rte_ring *r, const void *obj_table,
503  unsigned int esize, unsigned int n, unsigned int *free_space)
504 {
505  return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
507 }
508 
530 static __rte_always_inline unsigned int
531 rte_ring_sp_enqueue_burst_elem(struct rte_ring *r, const void *obj_table,
532  unsigned int esize, unsigned int n, unsigned int *free_space)
533 {
534  return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
536 }
537 
561 static __rte_always_inline unsigned int
562 rte_ring_enqueue_burst_elem(struct rte_ring *r, const void *obj_table,
563  unsigned int esize, unsigned int n, unsigned int *free_space)
564 {
565  switch (r->prod.sync_type) {
566  case RTE_RING_SYNC_MT:
567  return rte_ring_mp_enqueue_burst_elem(r, obj_table, esize, n,
568  free_space);
569  case RTE_RING_SYNC_ST:
570  return rte_ring_sp_enqueue_burst_elem(r, obj_table, esize, n,
571  free_space);
573  return rte_ring_mp_rts_enqueue_burst_elem(r, obj_table, esize,
574  n, free_space);
576  return rte_ring_mp_hts_enqueue_burst_elem(r, obj_table, esize,
577  n, free_space);
578  }
579 
580  /* valid ring should never reach this point */
581  RTE_ASSERT(0);
582  if (free_space != NULL)
583  *free_space = 0;
584  return 0;
585 }
586 
611 static __rte_always_inline unsigned int
612 rte_ring_mc_dequeue_burst_elem(struct rte_ring *r, void *obj_table,
613  unsigned int esize, unsigned int n, unsigned int *available)
614 {
615  return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
617 }
618 
640 static __rte_always_inline unsigned int
641 rte_ring_sc_dequeue_burst_elem(struct rte_ring *r, void *obj_table,
642  unsigned int esize, unsigned int n, unsigned int *available)
643 {
644  return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
646 }
647 
671 static __rte_always_inline unsigned int
672 rte_ring_dequeue_burst_elem(struct rte_ring *r, void *obj_table,
673  unsigned int esize, unsigned int n, unsigned int *available)
674 {
675  switch (r->cons.sync_type) {
676  case RTE_RING_SYNC_MT:
677  return rte_ring_mc_dequeue_burst_elem(r, obj_table, esize, n,
678  available);
679  case RTE_RING_SYNC_ST:
680  return rte_ring_sc_dequeue_burst_elem(r, obj_table, esize, n,
681  available);
683  return rte_ring_mc_rts_dequeue_burst_elem(r, obj_table, esize,
684  n, available);
686  return rte_ring_mc_hts_dequeue_burst_elem(r, obj_table, esize,
687  n, available);
688  }
689 
690  /* valid ring should never reach this point */
691  RTE_ASSERT(0);
692  if (available != NULL)
693  *available = 0;
694  return 0;
695 }
696 
697 #include <rte_ring_peek.h>
698 #include <rte_ring_peek_zc.h>
699 
700 #include <rte_ring.h>
701 
702 #ifdef __cplusplus
703 }
704 #endif
705 
706 #endif /* _RTE_RING_ELEM_H_ */
static __rte_always_inline int rte_ring_sp_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
static __rte_always_inline int rte_ring_sc_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
#define __rte_always_inline
Definition: rte_common.h:255
static __rte_always_inline int rte_ring_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
static __rte_always_inline unsigned int rte_ring_sc_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_always_inline unsigned int rte_ring_mc_rts_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
Definition: rte_ring_rts.h:107
static __rte_always_inline unsigned int rte_ring_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
static __rte_always_inline unsigned int rte_ring_mp_enqueue_burst_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
static __rte_always_inline unsigned int rte_ring_mc_hts_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
Definition: rte_ring_hts.h:80
static __rte_always_inline unsigned int rte_ring_mp_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
static __rte_always_inline unsigned int rte_ring_mc_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_always_inline unsigned int rte_ring_mc_hts_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
Definition: rte_ring_hts.h:136
static __rte_always_inline int rte_ring_mc_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
static __rte_always_inline unsigned int rte_ring_enqueue_burst_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
static __rte_always_inline unsigned int rte_ring_mc_rts_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
Definition: rte_ring_rts.h:163
static __rte_always_inline unsigned int rte_ring_sc_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_always_inline unsigned int rte_ring_sp_enqueue_burst_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
static __rte_always_inline unsigned int rte_ring_mp_hts_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
Definition: rte_ring_hts.h:53
static __rte_always_inline unsigned int rte_ring_mc_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_always_inline unsigned int rte_ring_mp_hts_enqueue_burst_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
Definition: rte_ring_hts.h:107
static __rte_always_inline unsigned int rte_ring_dequeue_bulk_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
static __rte_always_inline int rte_ring_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
enum rte_ring_sync_type sync_type
Definition: rte_ring_core.h:74
static __rte_always_inline unsigned int rte_ring_sp_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
ssize_t rte_ring_get_memsize_elem(unsigned int esize, unsigned int count)
struct rte_ring * rte_ring_create_elem(const char *name, unsigned int esize, unsigned int count, int socket_id, unsigned int flags)
static __rte_always_inline unsigned int rte_ring_mp_rts_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
Definition: rte_ring_rts.h:80
static __rte_always_inline int rte_ring_mp_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
static __rte_always_inline unsigned int rte_ring_mp_rts_enqueue_burst_elem(struct rte_ring *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
Definition: rte_ring_rts.h:134
static __rte_always_inline unsigned int rte_ring_dequeue_burst_elem(struct rte_ring *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)