eal: add API to lock/unlock tailq list
[dpdk.git] / lib / librte_eal / common / include / rte_eal_memconfig.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #ifndef _RTE_EAL_MEMCONFIG_H_
6 #define _RTE_EAL_MEMCONFIG_H_
7
8 #include <rte_config.h>
9 #include <rte_tailq.h>
10 #include <rte_memory.h>
11 #include <rte_memzone.h>
12 #include <rte_malloc_heap.h>
13 #include <rte_rwlock.h>
14 #include <rte_pause.h>
15 #include <rte_fbarray.h>
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 /**
22  * memseg list is a special case as we need to store a bunch of other data
23  * together with the array itself.
24  */
25 struct rte_memseg_list {
26         RTE_STD_C11
27         union {
28                 void *base_va;
29                 /**< Base virtual address for this memseg list. */
30                 uint64_t addr_64;
31                 /**< Makes sure addr is always 64-bits */
32         };
33         uint64_t page_sz; /**< Page size for all memsegs in this list. */
34         int socket_id; /**< Socket ID for all memsegs in this list. */
35         volatile uint32_t version; /**< version number for multiprocess sync. */
36         size_t len; /**< Length of memory area covered by this memseg list. */
37         unsigned int external; /**< 1 if this list points to external memory */
38         struct rte_fbarray memseg_arr;
39 };
40
41 /**
42  * the structure for the memory configuration for the RTE.
43  * Used by the rte_config structure. It is separated out, as for multi-process
44  * support, the memory details should be shared across instances
45  */
46 struct rte_mem_config {
47         volatile uint32_t magic;   /**< Magic number - Sanity check. */
48
49         /* memory topology */
50         uint32_t nchannel;    /**< Number of channels (0 if unknown). */
51         uint32_t nrank;       /**< Number of ranks (0 if unknown). */
52
53         /**
54          * current lock nest order
55          *  - qlock->mlock (ring/hash/lpm)
56          *  - mplock->qlock->mlock (mempool)
57          * Notice:
58          *  *ALWAYS* obtain qlock first if having to obtain both qlock and mlock
59          */
60         rte_rwlock_t mlock;   /**< only used by memzone LIB for thread-safe. */
61         rte_rwlock_t qlock;   /**< used for tailq operation for thread safe. */
62         rte_rwlock_t mplock;  /**< only used by mempool LIB for thread-safe. */
63
64         rte_rwlock_t memory_hotplug_lock;
65         /**< indicates whether memory hotplug request is in progress. */
66
67         /* memory segments and zones */
68         struct rte_fbarray memzones; /**< Memzone descriptors. */
69
70         struct rte_memseg_list memsegs[RTE_MAX_MEMSEG_LISTS];
71         /**< list of dynamic arrays holding memsegs */
72
73         struct rte_tailq_head tailq_head[RTE_MAX_TAILQ]; /**< Tailqs for objects */
74
75         /* Heaps of Malloc */
76         struct malloc_heap malloc_heaps[RTE_MAX_HEAPS];
77
78         /* next socket ID for external malloc heap */
79         int next_socket_id;
80
81         /* address of mem_config in primary process. used to map shared config into
82          * exact same address the primary process maps it.
83          */
84         uint64_t mem_cfg_addr;
85
86         /* legacy mem and single file segments options are shared */
87         uint32_t legacy_mem;
88         uint32_t single_file_segments;
89
90         /* keeps the more restricted dma mask */
91         uint8_t dma_maskbits;
92 } __attribute__((__packed__));
93
94
95 inline static void
96 rte_eal_mcfg_wait_complete(struct rte_mem_config* mcfg)
97 {
98         /* wait until shared mem_config finish initialising */
99         while(mcfg->magic != RTE_MAGIC)
100                 rte_pause();
101 }
102
103 /**
104  * Lock the internal EAL shared memory configuration for shared access.
105  */
106 void
107 rte_mcfg_mem_read_lock(void);
108
109 /**
110  * Unlock the internal EAL shared memory configuration for shared access.
111  */
112 void
113 rte_mcfg_mem_read_unlock(void);
114
115 /**
116  * Lock the internal EAL shared memory configuration for exclusive access.
117  */
118 void
119 rte_mcfg_mem_write_lock(void);
120
121 /**
122  * Unlock the internal EAL shared memory configuration for exclusive access.
123  */
124 void
125 rte_mcfg_mem_write_unlock(void);
126
127 /**
128  * Lock the internal EAL TAILQ list for shared access.
129  */
130 void
131 rte_mcfg_tailq_read_lock(void);
132
133 /**
134  * Unlock the internal EAL TAILQ list for shared access.
135  */
136 void
137 rte_mcfg_tailq_read_unlock(void);
138
139 /**
140  * Lock the internal EAL TAILQ list for exclusive access.
141  */
142 void
143 rte_mcfg_tailq_write_lock(void);
144
145 /**
146  * Unlock the internal EAL TAILQ list for exclusive access.
147  */
148 void
149 rte_mcfg_tailq_write_unlock(void);
150
151 #ifdef __cplusplus
152 }
153 #endif
154
155 #endif /*__RTE_EAL_MEMCONFIG_H_*/