DPDK  25.11.0
rte_graph_feature_arc_worker.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2025 Marvell International Ltd.
3  */
4 
5 #ifndef _RTE_GRAPH_FEATURE_ARC_WORKER_H_
6 #define _RTE_GRAPH_FEATURE_ARC_WORKER_H_
7 
8 #include <stddef.h>
10 #include <rte_bitops.h>
11 #include <rte_mbuf.h>
12 #include <rte_mbuf_dyn.h>
13 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
34 struct rte_graph_feature_node_list {
36  STAILQ_ENTRY(rte_graph_feature_node_list) next_feature;
37 
39  char feature_name[RTE_GRAPH_FEATURE_ARC_NAMELEN];
40 
42  rte_node_t feature_node_id;
43 
45  int32_t ref_count;
46 
51  rte_node_process_t feature_node_process_fn;
52 
55 
57  uint32_t finfo_index;
58 
60  void *feature_arc;
61 
63  rte_edge_t edge_to_this_feature;
64 
66  rte_edge_t edge_to_last_feature;
67 };
68 
87 
89  STAILQ_HEAD(, rte_graph_feature_node_list) all_features;
90 
92  char feature_arc_name[RTE_GRAPH_FEATURE_ARC_NAMELEN];
93 
96 
100  uint16_t max_features;
101 
104 
107 
110  struct rte_graph_feature_register end_feature;
111 
114 
116  size_t arc_size;
117 
120 
126  uint32_t feature_size;
127 
130 
132  alignas(RTE_CACHE_LINE_SIZE) RTE_MARKER fast_path_variables;
133 
139  RTE_ATOMIC(uint64_t) fp_feature_enable_bitmask;
140 
148  uint16_t max_indexes;
149 
154 
159 
165 
167  /*
168  * Arc specific fast path data
169  * It accommodates:
170  *
171  * 1. first enabled feature data for every index (rte_graph_feature_data_t or fdata)
172  * +--------------------------------------------------------------+ <- cache_aligned
173  * | 0th Index | 1st Index | ... | max_index - 1 |
174  * +--------------------------------------------------------------+
175  * | Startfdata0 | Startfdata1 | ... | Startfdata(max_index-1) |
176  * +--------------------------------------------------------------+
177  *
178  * 2. struct rte_graph_feature_data per index per feature
179  * +----------------------------------------+ ^ <- Start (Reserved, cache aligned)
180  * | struct rte_graph_feature_data[Index0] | |
181  * +----------------------------------------+ | feature_size
182  * | struct rte_graph_feature_data[Index1] | |
183  * +----------------------------------------+ ^ <- Feature-0 (cache_aligned)
184  * | struct rte_graph_feature_data[Index0] | |
185  * +----------------------------------------+ | feature_size
186  * | struct rte_graph_feature_data[Index1] | |
187  * +----------------------------------------+ v <- Feature-1 (cache aligned)
188  * | struct rte_graph_feature_data[Index0] | ^
189  * +----------------------------------------+ | feature_size
190  * | struct rte_graph_feature_data[Index1] | |
191  * +----------------------------------------+ v
192  * | ... .... |
193  * | ... .... |
194  * | ... .... |
195  * +----------------------------------------+ v <- Feature Index-1 (cache aligned)
196  * | struct rte_graph_feature_data[Index0] | ^
197  * +----------------------------------------+ | feature_size
198  * | struct rte_graph_feature_data[Index1] | |
199  * +----------------------------------------+ v <- Extra (Reserved, cache aligned)
200  * | struct rte_graph_feature_data[Index0] | ^
201  * +----------------------------------------+ | feature_size
202  * | struct rte_graph_feature_data[Index1] | |
203  * +----------------------------------------+ v
204  */
206 };
207 
213 typedef struct rte_feature_arc_main {
216 
219 
226 
228  uintptr_t feature_arcs[];
230 
243  RTE_ATOMIC(rte_edge_t) next_edge;
244 
249  RTE_ATOMIC(uint16_t) app_cookie;
250 
253 };
254 
259 };
260 
262 #define RTE_GRAPH_FEATURE_ARC_DYNFIELD_NAME "__rte_graph_feature_arc_mbuf_dynfield"
263 
265 #define RTE_GRAPH_FEATURE_DATA_SIZE_LOG2 3
266 
268 #define RTE_GRAPH_FEATURE_DATA_NUM_PER_FEATURE(arc) \
269  (arc->feature_size >> RTE_GRAPH_FEATURE_DATA_SIZE_LOG2)
270 
272 #define RTE_GRAPH_FEATURE_TO_FEATURE_DATA(arc, feature, index) \
273  ((rte_graph_feature_data_t) \
274  ((RTE_GRAPH_FEATURE_DATA_NUM_PER_FEATURE(arc) * (feature)) + (index)))
275 
279 #define GRAPH_FEATURE_ARC_PTR_INITIALIZER ((uintptr_t)UINTPTR_MAX)
280 
283 
305 __rte_experimental
308  const int dyn_offset)
309 {
310  return RTE_MBUF_DYNFIELD(mbuf, dyn_offset,
312 }
313 
324 __rte_experimental
325 static __rte_always_inline int
327 {
328  return (feature != RTE_GRAPH_FEATURE_INVALID);
329 }
330 
341 __rte_experimental
342 static __rte_always_inline int
344 {
345  return (feature_data != RTE_GRAPH_FEATURE_DATA_INVALID);
346 }
347 
358 __rte_experimental
361 {
362  uintptr_t fa = GRAPH_FEATURE_ARC_PTR_INITIALIZER;
363  rte_graph_feature_arc_main_t *fm = NULL;
364 
366 
367  if (likely((fm != NULL) && (arc < fm->max_feature_arcs)))
368  fa = fm->feature_arcs[arc];
369 
370  return (fa == GRAPH_FEATURE_ARC_PTR_INITIALIZER) ?
371  NULL : (struct rte_graph_feature_arc *)fa;
372 }
373 
385 __rte_experimental
389 {
390  return ((struct rte_graph_feature_data *) ((uint8_t *)arc + arc->fp_feature_data_offset +
392 }
393 
403 __rte_experimental
406 {
407  return rte_atomic_load_explicit(&fdata->next_edge, rte_memory_order_relaxed);
408 }
409 
419 __rte_experimental
420 static __rte_always_inline uint16_t
422 {
423  return rte_atomic_load_explicit(&fdata->app_cookie, rte_memory_order_relaxed);
424 }
425 
435 __rte_experimental
438 {
439  return rte_atomic_load_explicit(&fdata->next_feature_data, rte_memory_order_relaxed);
440 }
441 
442 
454 __rte_experimental
455 static __rte_always_inline uint16_t
458 {
459  struct rte_graph_feature_data *fdata_obj = ((struct rte_graph_feature_data *)
460  ((uint8_t *)arc + arc->fp_feature_data_offset +
462 
463 
464  return rte_atomic_load_explicit(&fdata_obj->app_cookie, rte_memory_order_relaxed);
465 }
466 
481 __rte_experimental
482 static __rte_always_inline int
486 {
487  struct rte_graph_feature_data *fdptr = ((struct rte_graph_feature_data *)
488  ((uint8_t *)arc + arc->fp_feature_data_offset +
489  ((*fdata) << RTE_GRAPH_FEATURE_DATA_SIZE_LOG2)));
490  *fdata = rte_atomic_load_explicit(&fdptr->next_feature_data, rte_memory_order_relaxed);
491  *next_edge = rte_atomic_load_explicit(&fdptr->next_edge, rte_memory_order_relaxed);
492 
493 
494  return ((*fdata) != RTE_GRAPH_FEATURE_DATA_INVALID);
495 }
496 
509 __rte_experimental
513 {
514  if (fdata != RTE_GRAPH_FEATURE_DATA_INVALID)
515  return ((struct rte_graph_feature_data *)
516  ((uint8_t *)arc + arc->fp_feature_data_offset +
518  else
519  return NULL;
520 }
521 
537 __rte_experimental
538 static __rte_always_inline int
540  uint32_t index,
542  rte_edge_t *edge)
543 {
544  struct rte_graph_feature_data *fdata_obj = NULL;
546 
547  fd = (rte_graph_feature_data_t *)((uint8_t *)arc + arc->fp_first_feature_offset +
548  (sizeof(rte_graph_feature_data_t) * index));
549 
550  if ((*fd) != RTE_GRAPH_FEATURE_DATA_INVALID) {
551  fdata_obj = ((struct rte_graph_feature_data *)
552  ((uint8_t *)arc + arc->fp_feature_data_offset +
554 
555  *edge = rte_atomic_load_explicit(&fdata_obj->next_edge,
556  rte_memory_order_relaxed);
557 
558  *fdata = rte_atomic_load_explicit(&fdata_obj->next_feature_data,
559  rte_memory_order_relaxed);
560  return 1;
561  }
562 
563  return 0;
564 }
565 
578 __rte_experimental
579 static __rte_always_inline uint64_t
581 {
582  if (unlikely(arc == NULL))
583  return 0;
584 
585  return (rte_atomic_load_explicit(&arc->fp_feature_enable_bitmask,
586  rte_memory_order_relaxed));
587 }
588 
595 __rte_experimental
596 static __rte_always_inline void
598 {
599  rte_prefetch0((void *)arc->fast_path_variables);
600 }
601 
610 __rte_experimental
611 static __rte_always_inline void
614 {
615  struct rte_graph_feature_data *fdata_obj = ((struct rte_graph_feature_data *)
616  ((uint8_t *)arc + arc->fp_feature_data_offset +
618  rte_prefetch0((void *)fdata_obj);
619 }
620 
621 #ifdef __cplusplus
622 }
623 #endif
624 
625 #endif
#define likely(x)
#define unlikely(x)
__extension__ typedef uint8_t RTE_MARKER8[0]
Definition: rte_common.h:780
#define __rte_cache_aligned
Definition: rte_common.h:739
#define __rte_always_inline
Definition: rte_common.h:490
__extension__ typedef void * RTE_MARKER[0]
Definition: rte_common.h:778
uint16_t(* rte_node_process_t)(struct rte_graph *graph, struct rte_node *node, void **objs, uint16_t nb_objs)
Definition: rte_graph.h:95
uint32_t rte_node_t
Definition: rte_graph.h:42
uint16_t rte_edge_t
Definition: rte_graph.h:43
#define RTE_GRAPH_FEATURE_ARC_NAMELEN
uint32_t rte_graph_feature_data_t
uint16_t rte_graph_feature_arc_t
uint8_t rte_graph_feature_t
void(* rte_graph_feature_change_notifier_cb_t)(const char *arc_name, const char *feature_name, rte_node_t feature_node_id, uint32_t index, bool enable_disable, uint16_t app_cookie)
static __rte_experimental __rte_always_inline uint16_t __rte_graph_feature_data_app_cookie_get(struct rte_graph_feature_data *fdata)
static __rte_experimental __rte_always_inline struct rte_graph_feature_arc_mbuf_dynfields * rte_graph_feature_arc_mbuf_dynfields_get(struct rte_mbuf *mbuf, const int dyn_offset)
#define RTE_GRAPH_FEATURE_DATA_SIZE_LOG2
static __rte_experimental __rte_always_inline int rte_graph_feature_is_valid(rte_graph_feature_t feature)
static __rte_experimental __rte_always_inline void rte_graph_feature_arc_feature_data_prefetch(struct rte_graph_feature_arc *arc, rte_graph_feature_data_t fdata)
static __rte_experimental __rte_always_inline uint16_t rte_graph_feature_data_app_cookie_get(struct rte_graph_feature_arc *arc, rte_graph_feature_data_t fdata)
static __rte_experimental __rte_always_inline struct rte_graph_feature_arc * rte_graph_feature_arc_get(rte_graph_feature_arc_t arc)
static __rte_experimental __rte_always_inline int rte_graph_feature_data_is_valid(rte_graph_feature_data_t feature_data)
struct rte_feature_arc_main rte_graph_feature_arc_main_t
static __rte_experimental __rte_always_inline void rte_graph_feature_arc_prefetch(struct rte_graph_feature_arc *arc)
static __rte_experimental __rte_always_inline rte_edge_t __rte_graph_feature_data_edge_get(struct rte_graph_feature_data *fdata)
static __rte_experimental __rte_always_inline uint64_t rte_graph_feature_arc_is_any_feature_enabled(struct rte_graph_feature_arc *arc)
static __rte_experimental __rte_always_inline int rte_graph_feature_data_next_feature_get(struct rte_graph_feature_arc *arc, rte_graph_feature_data_t *fdata, rte_edge_t *next_edge)
static __rte_experimental __rte_always_inline struct rte_graph_feature_data * __rte_graph_feature_data_get(struct rte_graph_feature_arc *arc, rte_graph_feature_data_t fdata)
rte_graph_feature_arc_main_t * __rte_graph_feature_arc_main
static __rte_experimental __rte_always_inline struct rte_graph_feature_data * rte_graph_feature_data_get(struct rte_graph_feature_arc *arc, rte_graph_feature_data_t fdata)
static __rte_experimental __rte_always_inline rte_graph_feature_data_t __rte_graph_feature_data_next_feature_get(struct rte_graph_feature_data *fdata)
static __rte_experimental __rte_always_inline int rte_graph_feature_data_first_feature_get(struct rte_graph_feature_arc *arc, uint32_t index, rte_graph_feature_data_t *fdata, rte_edge_t *edge)
#define RTE_MBUF_DYNFIELD(m, offset, type)
Definition: rte_mbuf_dyn.h:228
static void rte_prefetch0(const volatile void *p)
STAILQ_HEAD(, rte_graph_feature_node_list) all_features
struct rte_node_register * start_node
rte_graph_feature_arc_t feature_arc_index
rte_graph_feature_data_t * feature_data_by_index
rte_graph_feature_data_t next_feature_data