4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef _RTE_MEMORY_H_
35 #define _RTE_MEMORY_H_
40 * Memory-related RTE API.
47 #include <rte_config.h>
53 #include <rte_common.h>
57 RTE_PGSIZE_4K = 1ULL << 12,
58 RTE_PGSIZE_64K = 1ULL << 16,
59 RTE_PGSIZE_256K = 1ULL << 18,
60 RTE_PGSIZE_2M = 1ULL << 21,
61 RTE_PGSIZE_16M = 1ULL << 24,
62 RTE_PGSIZE_256M = 1ULL << 28,
63 RTE_PGSIZE_512M = 1ULL << 29,
64 RTE_PGSIZE_1G = 1ULL << 30,
65 RTE_PGSIZE_4G = 1ULL << 32,
66 RTE_PGSIZE_16G = 1ULL << 34,
69 #define SOCKET_ID_ANY -1 /**< Any NUMA socket. */
70 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1) /**< Cache line mask. */
72 #define RTE_CACHE_LINE_ROUNDUP(size) \
73 (RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE))
74 /**< Return the first cache-aligned value greater or equal to size. */
76 /**< Cache line size in terms of log2 */
77 #if RTE_CACHE_LINE_SIZE == 64
78 #define RTE_CACHE_LINE_SIZE_LOG2 6
79 #elif RTE_CACHE_LINE_SIZE == 128
80 #define RTE_CACHE_LINE_SIZE_LOG2 7
82 #error "Unsupported cache line size"
85 #define RTE_CACHE_LINE_MIN_SIZE 64 /**< Minimum Cache line size. */
88 * Force alignment to cache line.
90 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE)
93 * Force minimum cache line alignment.
95 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
97 typedef uint64_t phys_addr_t; /**< Physical address definition. */
98 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1)
101 * Physical memory segment descriptor.
104 phys_addr_t phys_addr; /**< Start physical address. */
107 void *addr; /**< Start virtual address. */
108 uint64_t addr_64; /**< Makes sure addr is always 64 bits */
110 size_t len; /**< Length of the segment. */
111 uint64_t hugepage_sz; /**< The pagesize of underlying memory */
112 int32_t socket_id; /**< NUMA socket ID. */
113 uint32_t nchannel; /**< Number of channels. */
114 uint32_t nrank; /**< Number of ranks. */
118 * Lock page in physical memory and prevent from swapping.
121 * The virtual address.
123 * 0 on success, negative on error.
125 int rte_mem_lock_page(const void *virt);
128 * Get physical address of any mapped virtual address in the current process.
129 * It is found by browsing the /proc/self/pagemap special file.
130 * The page must be locked.
133 * The virtual address.
135 * The physical address or RTE_BAD_PHYS_ADDR on error.
137 phys_addr_t rte_mem_virt2phy(const void *virt);
140 * Get the layout of the available physical memory.
142 * It can be useful for an application to have the full physical
143 * memory layout to decide the size of a memory zone to reserve. This
144 * table is stored in rte_config (see rte_eal_get_configuration()).
147 * - On success, return a pointer to a read-only table of struct
148 * rte_physmem_desc elements, containing the layout of all
149 * addressable physical memory. The last element of the table
150 * contains a NULL address.
151 * - On error, return NULL. This should not happen since it is a fatal
152 * error that will probably cause the entire system to panic.
154 const struct rte_memseg *rte_eal_get_physmem_layout(void);
157 * Dump the physical memory layout to a file.
160 * A pointer to a file for output
162 void rte_dump_physmem_layout(FILE *f);
165 * Get the total amount of available physical memory.
168 * The total amount of available physical memory in bytes.
170 uint64_t rte_eal_get_physmem_size(void);
173 * Get the number of memory channels.
176 * The number of memory channels on the system. The value is 0 if unknown
177 * or not the same on all devices.
179 unsigned rte_memory_get_nchannel(void);
182 * Get the number of memory ranks.
185 * The number of memory ranks on the system. The value is 0 if unknown or
186 * not the same on all devices.
188 unsigned rte_memory_get_nrank(void);
194 #endif /* _RTE_MEMORY_H_ */