4d650025c21727e2ed45e032047721daac1d61ba
[dpdk.git] / lib / librte_eal / common / eal_memcfg.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4
5 #ifndef EAL_MEMCFG_H
6 #define EAL_MEMCFG_H
7
8 #include <rte_config.h>
9 #include <rte_memory.h>
10 #include <rte_memzone.h>
11 #include <rte_pause.h>
12 #include <rte_spinlock.h>
13 #include <rte_rwlock.h>
14 #include <rte_tailq.h>
15
16 #include "malloc_heap.h"
17
18 /**
19  * Memory configuration shared across multiple processes.
20  */
21 struct rte_mem_config {
22         volatile uint32_t magic;   /**< Magic number - sanity check. */
23         uint32_t version;
24         /**< Prevent secondary processes using different DPDK versions. */
25
26         /* memory topology */
27         uint32_t nchannel;    /**< Number of channels (0 if unknown). */
28         uint32_t nrank;       /**< Number of ranks (0 if unknown). */
29
30         /**
31          * current lock nest order
32          *  - qlock->mlock (ring/hash/lpm)
33          *  - mplock->qlock->mlock (mempool)
34          * Notice:
35          *  *ALWAYS* obtain qlock first if having to obtain both qlock and mlock
36          */
37         rte_rwlock_t mlock;   /**< used by memzones for thread safety. */
38         rte_rwlock_t qlock;   /**< used by tailqs for thread safety. */
39         rte_rwlock_t mplock;  /**< used by mempool library for thread safety. */
40         rte_spinlock_t tlock; /**< used by timer library for thread safety. */
41
42         rte_rwlock_t memory_hotplug_lock;
43         /**< Indicates whether memory hotplug request is in progress. */
44
45         /* memory segments and zones */
46         struct rte_fbarray memzones; /**< Memzone descriptors. */
47
48         struct rte_memseg_list memsegs[RTE_MAX_MEMSEG_LISTS];
49         /**< List of dynamic arrays holding memsegs */
50
51         struct rte_tailq_head tailq_head[RTE_MAX_TAILQ];
52         /**< Tailqs for objects */
53
54         struct malloc_heap malloc_heaps[RTE_MAX_HEAPS];
55         /**< DPDK malloc heaps */
56
57         int next_socket_id; /**< Next socket ID for external malloc heap */
58
59         /* rte_mem_config has to be mapped at the exact same address in all
60          * processes, so we need to store it.
61          */
62         uint64_t mem_cfg_addr; /**< Address of this structure in memory. */
63
64         /* Primary and secondary processes cannot run with different legacy or
65          * single file segments options, so to avoid having to specify these
66          * options to all processes, store them in shared config and update the
67          * internal config at init time.
68          */
69         uint32_t legacy_mem; /**< stored legacy mem parameter. */
70         uint32_t single_file_segments;
71         /**< stored single file segments parameter. */
72
73         uint64_t tsc_hz;
74         /**< TSC rate */
75
76         uint8_t dma_maskbits; /**< Keeps the more restricted dma mask. */
77 };
78
79 /* update internal config from shared mem config */
80 void
81 eal_mcfg_update_internal(void);
82
83 /* update shared mem config from internal config */
84 void
85 eal_mcfg_update_from_internal(void);
86
87 /* wait until primary process initialization is complete */
88 void
89 eal_mcfg_wait_complete(void);
90
91 /* check if DPDK version of current process matches one stored in the config */
92 int
93 eal_mcfg_check_version(void);
94
95 /* set mem config as complete */
96 void
97 eal_mcfg_complete(void);
98
99 #endif /* EAL_MEMCFG_H */