LCOV - code coverage report
Current view: top level - util/shmem - fd_shmem_private.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 8 10 80.0 %
Date: 2024-11-13 11:58:15 Functions: 2 8 25.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_util_shmem_fd_shmem_private_h
       2             : #define HEADER_fd_src_util_shmem_fd_shmem_private_h
       3             : 
       4             : #include "fd_shmem.h"
       5             : 
       6             : #if FD_HAS_THREADS
       7             : #include <pthread.h>
       8             : #endif
       9             : 
      10             : /* Want strlen(base)+strlen("/.")+strlen(page)+strlen("/")+strlen(name)+1 <= BUF_MAX
      11             :      -> BASE_MAX-1  +2           +PAGE_MAX-1  +1          +NAME_MAX-1  +1 == BUF_MAX
      12             :      -> BASE_MAX == BUF_MAX - NAME_MAX - PAGE_MAX - 1 */
      13             : 
      14        3687 : #define FD_SHMEM_PRIVATE_PATH_BUF_MAX (256UL)
      15             : #define FD_SHMEM_PRIVATE_BASE_MAX     (FD_SHMEM_PRIVATE_PATH_BUF_MAX-FD_SHMEM_NAME_MAX-FD_SHMEM_PAGE_SZ_CSTR_MAX-1UL)
      16             : 
      17           0 : #define FD_SHMEM_PRIVATE_MMAP_NORMAL_MASK 0x7ffffffff000
      18           0 : #define FD_SHMEM_PRIVATE_MMAP_HUGE_MASK 0x7fffffc00000
      19        1062 : #define FD_SHMEM_PRIVATE_MMAP_GIGANTIC_MASK 0x7fffc0000000
      20             : 
      21             : #if FD_HAS_THREADS
      22     1324026 : #define FD_SHMEM_LOCK   pthread_mutex_lock(   fd_shmem_private_lock )
      23     1324026 : #define FD_SHMEM_UNLOCK pthread_mutex_unlock( fd_shmem_private_lock )
      24             : #else
      25             : #define FD_SHMEM_LOCK   ((void)0)
      26             : #define FD_SHMEM_UNLOCK ((void)0)
      27             : #endif
      28             : 
      29             : FD_PROTOTYPES_BEGIN
      30             : 
      31             : /* NUMA backend ******************************************************/
      32             : 
      33             : /* fd_numa_node_cnt / fd_numa_cpu_cnt determines the current number of
      34             :    configured numa nodes / cpus (roughly equivalent to libnuma's
      35             :    numa_num_configured_nodes / numa_num_configured_cpus).  Returns 0 if
      36             :    this could not be determined (logs details on failure).  These
      37             :    function are only used during shmem initialization as part of
      38             :    topology discovery so should not do any fancy caching under the hood. */
      39             : 
      40             : ulong
      41             : fd_numa_node_cnt( void );
      42             : 
      43             : ulong
      44             : fd_numa_cpu_cnt( void );
      45             : 
      46             : /* fd_numa_node_idx determines the numa node closest to the given
      47             :    cpu_idx (roughly equivalent to libnuma's numa_node_of_cpu).  Returns
      48             :    ULONG_MAX if this could not be determined (logs details on failure).
      49             :    This function is only used during shmem initialization as part of
      50             :    topology discovery so should not do any fancy caching under the hood. */
      51             : 
      52             : ulong
      53             : fd_numa_node_idx( ulong cpu_idx );
      54             : 
      55             : /* FIXME: probably should clean up the below APIs to get something
      56             :    that allows for cleaner integration with fd_shmem_admin.c (e.g. if we
      57             :    are going to replace libnuma calls with our own, no reason to use the
      58             :    historical clunky APIs). */
      59             : 
      60             : /* fd_numa_mlock locks the memory region to reside at a stable position
      61             :    in physical DRAM.  Wraps the `mlock(2)` Linux syscall.  See:
      62             : 
      63             :      https://man7.org/linux/man-pages/man2/mlock.2.html */
      64             : 
      65             : int
      66             : fd_numa_mlock( void const * addr,
      67             :                ulong        len );
      68             : 
      69             : /* fd_numa_mlock unlocks the memory region.  Wraps the `munlock(2)`
      70             :    Linux syscall.  See:
      71             : 
      72             :      https://man7.org/linux/man-pages/man2/munlock.2.html */
      73             : 
      74             : int
      75             : fd_numa_munlock( void const * addr,
      76             :                  ulong        len );
      77             : 
      78             : /* fd_numa_get_mempolicy retrieves the NUMA memory policy of the
      79             :    current thread.  Wraps the `get_mempolicy(2)` Linux syscall.  See:
      80             : 
      81             :      https://man7.org/linux/man-pages/man2/get_mempolicy.2.html */
      82             : 
      83             : long
      84             : fd_numa_get_mempolicy( int *   mode,
      85             :                        ulong * nodemask,
      86             :                        ulong   maxnode,
      87             :                        void *  addr,
      88             :                        uint    flags );
      89             : 
      90             : /* fd_numa_set_mempolicy sets the default NUMA memory policy of the
      91             :    current thread and its children.  Wraps the `set_mempolicy(2)` Linux
      92             :    syscall.  See:
      93             : 
      94             :      https://man7.org/linux/man-pages/man2/set_mempolicy.2.html */
      95             : 
      96             : long
      97             : fd_numa_set_mempolicy( int           mode,
      98             :                        ulong const * nodemask,
      99             :                        ulong         maxnode );
     100             : 
     101             : /* fd_numa_mbind sets the NUMA memory policy for a range of memory.
     102             :    Wraps the `mbind(2)` Linux syscall.  See:
     103             : 
     104             :      https://man7.org/linux/man-pages/man2/mbind.2.html */
     105             : 
     106             : long
     107             : fd_numa_mbind( void *        addr,
     108             :                ulong         len,
     109             :                int           mode,
     110             :                ulong const * nodemask,
     111             :                ulong         maxnode,
     112             :                uint          flags );
     113             : 
     114             : /* fd_numa_move_page moves pages of a process to another node.  Wraps
     115             :    the `move_pages(2)` Linux syscall.  See:
     116             : 
     117             :      https://man7.org/linux/man-pages/man2/move_pages.2.html
     118             : 
     119             :    Also useful to detect the true NUMA node ownership of pages of memory
     120             :    after calls to `mlock(2)` and `mbind(2)`. */
     121             : 
     122             : long
     123             : fd_numa_move_pages( int         pid,
     124             :                     ulong       count,
     125             :                     void **     pages,
     126             :                     int const * nodes,
     127             :                     int *       status,
     128             :                     int         flags );
     129             : 
     130             : /**********************************************************************/
     131             : 
     132             : #if FD_HAS_THREADS
     133             : extern pthread_mutex_t fd_shmem_private_lock[1];
     134             : #endif
     135             : 
     136             : extern char  fd_shmem_private_base[ FD_SHMEM_PRIVATE_BASE_MAX ]; /* ""  at thread group start, initialized at boot */
     137             : extern ulong fd_shmem_private_base_len;                          /* 0UL at ",                  initialized at boot */
     138             : 
     139             : static inline char *                         /* ==buf always */
     140             : fd_shmem_private_path( char const * name,    /* Valid name */
     141             :                        ulong        page_sz, /* Valid page size (normal, huge, gigantic) */
     142        3687 :                        char *       buf ) {  /* Non-NULL with FD_SHMEM_PRIVATE_PATH_BUF_MAX bytes */
     143        3687 :   return fd_cstr_printf( buf, FD_SHMEM_PRIVATE_PATH_BUF_MAX, NULL, "%s/.%s/%s",
     144        3687 :                          fd_shmem_private_base, fd_shmem_page_sz_to_cstr( page_sz ), name );
     145        3687 : }
     146             : 
     147             : FD_PROTOTYPES_END
     148             : 
     149             : #endif /* HEADER_fd_src_util_shmem_fd_shmem_private_h */

Generated by: LCOV version 1.14