LCOV - code coverage report
Current view: top level - waltz/xdp - fd_xsk_private.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 7 7 100.0 %
Date: 2025-02-18 12:28:12 Functions: 2 6 33.3 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_waltz_xdp_fd_xsk_private_h
       2             : #define HEADER_fd_src_waltz_xdp_fd_xsk_private_h
       3             : 
       4             : #if defined(__linux__)
       5             : 
       6             : #include "fd_xsk.h"
       7             : #include "../../util/fd_util_base.h"
       8             : 
       9             : #include <linux/if_xdp.h>
      10             : 
      11             : /* fd_ring_desc_t describes an XSK descriptor ring in the thread group's
      12             :    local address space.  All pointers fall into kernel-managed XSK
      13             :    descriptor buffer at [mem;mem+mem_sz) that are valid during the
      14             :    lifetime of an fd_xsk_t join.  The ring producer and consumer are
      15             :    synchronized via incrementing sequence numbers that wrap at 2^64. */
      16             : 
      17             : struct __attribute__((aligned(64UL))) fd_ring_desc {
      18             :   /* This point is 64-byte aligned */
      19             : 
      20             :   /* mmap() params, only used during join/leave for munmap() */
      21             : 
      22             :   void *  mem;    /* Points to start of shared descriptor ring mmap region */
      23             :   ulong   map_sz; /* Size of shared descriptor ring mmap region */
      24             :   ulong   _pad_0x10;
      25             :   ulong   _pad_0x18;
      26             : 
      27             :   /* This point is 64-byte aligned */
      28             : 
      29             :   /* Pointers to fields opaque XSK ring structure.
      30             :      This indirection is required because the memory layout of the
      31             :      kernel-provided descriptor rings is unstable.  The field offsets
      32             :      can be queried using getsockopt(SOL_XDP, XDP_MMAP_OFFSETS). */
      33             : 
      34             :   union {
      35             :     void *            ptr;         /* Opaque pointer */
      36             :     struct xdp_desc * packet_ring; /* For RX, TX rings */
      37             :     ulong *           frame_ring;  /* For FILL, COMPLETION rings */
      38             :   };
      39             :   uint *  flags;       /* Points to flags in shared descriptor ring */
      40             :   uint *  prod;        /* Points to producer seq in shared descriptor ring */
      41             :   uint *  cons;        /* Points to consumer seq in shared descriptor ring */
      42             : 
      43             :   /* This point is 64-byte aligned */
      44             : 
      45             :   /* Managed by fd_xsk_t */
      46             : 
      47             :   uint    depth;       /* Capacity of ring in no of entries */
      48             :   uint    cached_prod; /* Cached value of *prod */
      49             :   uint    cached_cons; /* Cached value of *cons */
      50             : };
      51             : typedef struct fd_ring_desc fd_ring_desc_t;
      52             : 
      53             : /* Private definition of an fd_xsk_t */
      54             : 
      55           3 : #define FD_XSK_MAGIC (0xf17eda2c3778736bUL) /* firedancer hex(xsk) */
      56             : 
      57             : struct __attribute__((aligned(FD_XSK_ALIGN))) fd_xsk_private {
      58             :   ulong magic;   /* ==FD_XSK_MAGIC */
      59             :   ulong session; /* TODO, use as mutex lock */
      60             : 
      61             :   /* Network interface config *****************************************/
      62             : 
      63             :   /* Informational */
      64             :   uint if_idx;       /* index of net device */
      65             :   uint if_queue_id;  /* net device combined queue index */
      66             :   long log_suppress_until_ns; /* suppress log messages until this time */
      67             : 
      68             :   fd_xsk_params_t params;
      69             : 
      70             :   /* Per-join thread-group-local objects ******************************/
      71             : 
      72             :   /* Kernel descriptor of UMEM in local address space */
      73             :   struct xdp_umem_reg umem;
      74             : 
      75             :   /* Kernel descriptor of XSK rings in local address space
      76             :      returned by getsockopt(SOL_XDP, XDP_MMAP_OFFSETS) */
      77             :   struct xdp_mmap_offsets offsets;
      78             : 
      79             :   /* Open file descriptors */
      80             :   int xsk_fd;         /* AF_XDP socket file descriptor */
      81             :   int xdp_map_fd;     /* eBPF XSKMAP */
      82             :   int xdp_udp_map_fd; /* eBPF UDP map */
      83             : 
      84             :   /* ring_{rx,tx,fr,cr}: XSK ring descriptors */
      85             : 
      86             :   fd_ring_desc_t ring_rx;
      87             :   fd_ring_desc_t ring_tx;
      88             :   fd_ring_desc_t ring_fr;
      89             :   fd_ring_desc_t ring_cr;
      90             : 
      91             :   /* Variable-length data *********************************************/
      92             : 
      93             :   /* ... UMEM area follows ... */
      94             : };
      95             : 
      96             : FD_PROTOTYPES_BEGIN
      97             : 
      98             : /* fd_xsk_rx_need_wakeup: returns whether a wakeup is required to
      99             :    complete a rx operation */
     100             : 
     101             : static inline int
     102          15 : fd_xsk_rx_need_wakeup( fd_xsk_t * xsk ) {
     103          15 :   return !!( *xsk->ring_fr.flags & XDP_RING_NEED_WAKEUP );
     104          15 : }
     105             : 
     106             : /* fd_xsk_tx_need_wakeup: returns whether a wakeup is required to
     107             :    complete a tx operation */
     108             : 
     109             : static inline int
     110          15 : fd_xsk_tx_need_wakeup( fd_xsk_t * xsk ) {
     111          15 :   return !!( *xsk->ring_tx.flags & XDP_RING_NEED_WAKEUP );
     112          15 : }
     113             : 
     114             : FD_PROTOTYPES_END
     115             : 
     116             : #endif /* defined(__linux__) */
     117             : #endif /* HEADER_fd_src_waltz_xdp_fd_xsk_private_h */

Generated by: LCOV version 1.14