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