DPDK  22.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 
106 struct rte_ring *rte_ring_create_elem(const char *name, unsigned int esize,
107  unsigned int count, int socket_id, unsigned int flags);
108 
131 static __rte_always_inline unsigned int
132 rte_ring_mp_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table,
133  unsigned int esize, unsigned int n, unsigned int *free_space)
134 {
135  return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
137 }
138 
160 static __rte_always_inline unsigned int
161 rte_ring_sp_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table,
162  unsigned int esize, unsigned int n, unsigned int *free_space)
163 {
164  return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
166 }
167 
168 #include <rte_ring_hts.h>
169 #include <rte_ring_rts.h>
170 
194 static __rte_always_inline unsigned int
195 rte_ring_enqueue_bulk_elem(struct rte_ring *r, const void *obj_table,
196  unsigned int esize, unsigned int n, unsigned int *free_space)
197 {
198  switch (r->prod.sync_type) {
199  case RTE_RING_SYNC_MT:
200  return rte_ring_mp_enqueue_bulk_elem(r, obj_table, esize, n,
201  free_space);
202  case RTE_RING_SYNC_ST:
203  return rte_ring_sp_enqueue_bulk_elem(r, obj_table, esize, n,
204  free_space);
206  return rte_ring_mp_rts_enqueue_bulk_elem(r, obj_table, esize, n,
207  free_space);
209  return rte_ring_mp_hts_enqueue_bulk_elem(r, obj_table, esize, n,
210  free_space);
211  }
212 
213  /* valid ring should never reach this point */
214  RTE_ASSERT(0);
215  if (free_space != NULL)
216  *free_space = 0;
217  return 0;
218 }
219 
238 static __rte_always_inline int
239 rte_ring_mp_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
240 {
241  return rte_ring_mp_enqueue_bulk_elem(r, obj, esize, 1, NULL) ? 0 :
242  -ENOBUFS;
243 }
244 
262 static __rte_always_inline int
263 rte_ring_sp_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
264 {
265  return rte_ring_sp_enqueue_bulk_elem(r, obj, esize, 1, NULL) ? 0 :
266  -ENOBUFS;
267 }
268 
288 static __rte_always_inline int
289 rte_ring_enqueue_elem(struct rte_ring *r, void *obj, unsigned int esize)
290 {
291  return rte_ring_enqueue_bulk_elem(r, obj, esize, 1, NULL) ? 0 :
292  -ENOBUFS;
293 }
294 
317 static __rte_always_inline unsigned int
318 rte_ring_mc_dequeue_bulk_elem(struct rte_ring *r, void *obj_table,
319  unsigned int esize, unsigned int n, unsigned int *available)
320 {
321  return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
323 }
324 
345 static __rte_always_inline unsigned int
346 rte_ring_sc_dequeue_bulk_elem(struct rte_ring *r, void *obj_table,
347  unsigned int esize, unsigned int n, unsigned int *available)
348 {
349  return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
351 }
352 
376 static __rte_always_inline unsigned int
377 rte_ring_dequeue_bulk_elem(struct rte_ring *r, void *obj_table,
378  unsigned int esize, unsigned int n, unsigned int *available)
379 {
380  switch (r->cons.sync_type) {
381  case RTE_RING_SYNC_MT:
382  return rte_ring_mc_dequeue_bulk_elem(r, obj_table, esize, n,
383  available);
384  case RTE_RING_SYNC_ST:
385  return rte_ring_sc_dequeue_bulk_elem(r, obj_table, esize, n,
386  available);
388  return rte_ring_mc_rts_dequeue_bulk_elem(r, obj_table, esize,
389  n, available);
391  return rte_ring_mc_hts_dequeue_bulk_elem(r, obj_table, esize,
392  n, available);
393  }
394 
395  /* valid ring should never reach this point */
396  RTE_ASSERT(0);
397  if (available != NULL)
398  *available = 0;
399  return 0;
400 }
401 
421 static __rte_always_inline int
422 rte_ring_mc_dequeue_elem(struct rte_ring *r, void *obj_p,
423  unsigned int esize)
424 {
425  return rte_ring_mc_dequeue_bulk_elem(r, obj_p, esize, 1, NULL) ? 0 :
426  -ENOENT;
427 }
428 
445 static __rte_always_inline int
446 rte_ring_sc_dequeue_elem(struct rte_ring *r, void *obj_p,
447  unsigned int esize)
448 {
449  return rte_ring_sc_dequeue_bulk_elem(r, obj_p, esize, 1, NULL) ? 0 :
450  -ENOENT;
451 }
452 
473 static __rte_always_inline int
474 rte_ring_dequeue_elem(struct rte_ring *r, void *obj_p, unsigned int esize)
475 {
476  return rte_ring_dequeue_bulk_elem(r, obj_p, esize, 1, NULL) ? 0 :
477  -ENOENT;
478 }
479 
502 static __rte_always_inline unsigned int
503 rte_ring_mp_enqueue_burst_elem(struct rte_ring *r, const void *obj_table,
504  unsigned int esize, unsigned int n, unsigned int *free_space)
505 {
506  return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
508 }
509 
531 static __rte_always_inline unsigned int
532 rte_ring_sp_enqueue_burst_elem(struct rte_ring *r, const void *obj_table,
533  unsigned int esize, unsigned int n, unsigned int *free_space)
534 {
535  return __rte_ring_do_enqueue_elem(r, obj_table, esize, n,
537 }
538 
562 static __rte_always_inline unsigned int
563 rte_ring_enqueue_burst_elem(struct rte_ring *r, const void *obj_table,
564  unsigned int esize, unsigned int n, unsigned int *free_space)
565 {
566  switch (r->prod.sync_type) {
567  case RTE_RING_SYNC_MT:
568  return rte_ring_mp_enqueue_burst_elem(r, obj_table, esize, n,
569  free_space);
570  case RTE_RING_SYNC_ST:
571  return rte_ring_sp_enqueue_burst_elem(r, obj_table, esize, n,
572  free_space);
574  return rte_ring_mp_rts_enqueue_burst_elem(r, obj_table, esize,
575  n, free_space);
577  return rte_ring_mp_hts_enqueue_burst_elem(r, obj_table, esize,
578  n, free_space);
579  }
580 
581  /* valid ring should never reach this point */
582  RTE_ASSERT(0);
583  if (free_space != NULL)
584  *free_space = 0;
585  return 0;
586 }
587 
612 static __rte_always_inline unsigned int
613 rte_ring_mc_dequeue_burst_elem(struct rte_ring *r, void *obj_table,
614  unsigned int esize, unsigned int n, unsigned int *available)
615 {
616  return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
618 }
619 
641 static __rte_always_inline unsigned int
642 rte_ring_sc_dequeue_burst_elem(struct rte_ring *r, void *obj_table,
643  unsigned int esize, unsigned int n, unsigned int *available)
644 {
645  return __rte_ring_do_dequeue_elem(r, obj_table, esize, n,
647 }
648 
672 static __rte_always_inline unsigned int
673 rte_ring_dequeue_burst_elem(struct rte_ring *r, void *obj_table,
674  unsigned int esize, unsigned int n, unsigned int *available)
675 {
676  switch (r->cons.sync_type) {
677  case RTE_RING_SYNC_MT:
678  return rte_ring_mc_dequeue_burst_elem(r, obj_table, esize, n,
679  available);
680  case RTE_RING_SYNC_ST:
681  return rte_ring_sc_dequeue_burst_elem(r, obj_table, esize, n,
682  available);
684  return rte_ring_mc_rts_dequeue_burst_elem(r, obj_table, esize,
685  n, available);
687  return rte_ring_mc_hts_dequeue_burst_elem(r, obj_table, esize,
688  n, available);
689  }
690 
691  /* valid ring should never reach this point */
692  RTE_ASSERT(0);
693  if (available != NULL)
694  *available = 0;
695  return 0;
696 }
697 
698 #include <rte_ring_peek.h>
699 #include <rte_ring_peek_zc.h>
700 
701 #include <rte_ring.h>
702 
703 #ifdef __cplusplus
704 }
705 #endif
706 
707 #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:228
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)