DPDK  24.11.0-rc3
rte_memory.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 #ifndef _RTE_MEMORY_H_
6 #define _RTE_MEMORY_H_
7 
14 #include <stdint.h>
15 #include <stddef.h>
16 #include <stdio.h>
17 
18 #include <rte_bitops.h>
19 #include <rte_common.h>
20 #include <rte_config.h>
21 #include <rte_eal_memconfig.h>
22 #include <rte_fbarray.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define RTE_PGSIZE_4K (1ULL << 12)
29 #define RTE_PGSIZE_64K (1ULL << 16)
30 #define RTE_PGSIZE_256K (1ULL << 18)
31 #define RTE_PGSIZE_2M (1ULL << 21)
32 #define RTE_PGSIZE_16M (1ULL << 24)
33 #define RTE_PGSIZE_256M (1ULL << 28)
34 #define RTE_PGSIZE_512M (1ULL << 29)
35 #define RTE_PGSIZE_1G (1ULL << 30)
36 #define RTE_PGSIZE_4G (1ULL << 32)
37 #define RTE_PGSIZE_16G (1ULL << 34)
38 
39 #define SOCKET_ID_ANY -1
42 #define RTE_MEMSEG_FLAG_DO_NOT_FREE RTE_BIT32(0)
43 
44 #define RTE_MEMSEG_FLAG_DIRTY RTE_BIT32(1)
45 
49 struct rte_memseg {
51  union {
52  void *addr;
53  uint64_t addr_64;
54  };
55  size_t len;
56  uint64_t hugepage_sz;
57  int32_t socket_id;
58  uint32_t nchannel;
59  uint32_t nrank;
60  uint32_t flags;
61 } __rte_packed;
62 
68  union {
69  void *base_va;
71  uint64_t addr_64;
73  };
74  uint64_t page_sz;
75  int socket_id;
76  volatile uint32_t version;
77  size_t len;
78  unsigned int external;
79  unsigned int heap;
80  struct rte_fbarray memseg_arr;
81 };
82 
91 int rte_mem_lock_page(const void *virt);
92 
103 phys_addr_t rte_mem_virt2phy(const void *virt);
104 
118 rte_iova_t rte_mem_virt2iova(const void *virt);
119 
132 void *
134 
146 struct rte_memseg *
147 rte_mem_virt2memseg(const void *virt, const struct rte_memseg_list *msl);
148 
157 struct rte_memseg_list *
158 rte_mem_virt2memseg_list(const void *virt);
159 
167 typedef int (*rte_memseg_walk_t)(const struct rte_memseg_list *msl,
168  const struct rte_memseg *ms, void *arg);
169 
179 typedef int (*rte_memseg_contig_walk_t)(const struct rte_memseg_list *msl,
180  const struct rte_memseg *ms, size_t len, void *arg);
181 
190 typedef int (*rte_memseg_list_walk_t)(const struct rte_memseg_list *msl,
191  void *arg);
192 
211 int
212 rte_memseg_walk(rte_memseg_walk_t func, void *arg);
213 
232 int
234 
253 int
255  __rte_locks_excluded(rte_mcfg_mem_get_lock());
256 
272 int
274 
290 int
292 
308 int
310 
332 int
333 rte_memseg_get_fd(const struct rte_memseg *ms);
334 
356 int
358 
380 int
381 rte_memseg_get_fd_offset(const struct rte_memseg *ms, size_t *offset);
382 
404 int
406  size_t *offset);
407 
442 int
443 rte_extmem_register(void *va_addr, size_t len, rte_iova_t iova_addrs[],
444  unsigned int n_pages, size_t page_sz);
445 
469 int
470 rte_extmem_unregister(void *va_addr, size_t len);
471 
492 int
493 rte_extmem_attach(void *va_addr, size_t len);
494 
515 int
516 rte_extmem_detach(void *va_addr, size_t len);
517 
527 void rte_dump_physmem_layout(FILE *f);
528 
538 uint64_t rte_eal_get_physmem_size(void);
539 
547 unsigned rte_memory_get_nchannel(void);
548 
556 unsigned rte_memory_get_nrank(void);
557 
565 int rte_mem_check_dma_mask(uint8_t maskbits);
566 
580 int rte_mem_check_dma_mask_thread_unsafe(uint8_t maskbits);
581 
587 void rte_mem_set_dma_mask(uint8_t maskbits);
588 
598 int rte_eal_using_phys_addrs(void);
599 
600 
608 };
609 #define RTE_MEM_EVENT_CALLBACK_NAME_LEN 64
610 
615 typedef void (*rte_mem_event_callback_t)(enum rte_mem_event event_type,
616  const void *addr, size_t len, void *arg);
617 
643 int
645  void *arg);
646 
661 int
662 rte_mem_event_callback_unregister(const char *name, void *arg);
663 
664 
665 #define RTE_MEM_ALLOC_VALIDATOR_NAME_LEN 64
666 
674  size_t cur_limit, size_t new_len);
675 
710 int
711 rte_mem_alloc_validator_register(const char *name,
712  rte_mem_alloc_validator_t clb, int socket_id, size_t limit);
713 
728 int
729 rte_mem_alloc_validator_unregister(const char *name, int socket_id);
730 
731 #ifdef __cplusplus
732 }
733 #endif
734 
735 #endif /* _RTE_MEMORY_H_ */
__rte_internal rte_rwlock_t * rte_mcfg_mem_get_lock(void)
uint32_t flags
Definition: rte_memory.h:60
void * addr
Definition: rte_memory.h:52
unsigned rte_memory_get_nchannel(void)
int rte_memseg_walk(rte_memseg_walk_t func, void *arg)
void * rte_mem_iova2virt(rte_iova_t iova)
rte_iova_t iova
Definition: rte_memory.h:50
uint32_t nchannel
Definition: rte_memory.h:58
int rte_memseg_contig_walk_thread_unsafe(rte_memseg_contig_walk_t func, void *arg)
int rte_mem_alloc_validator_unregister(const char *name, int socket_id)
Unregister validator callback for memory allocations.
int rte_mem_event_callback_register(const char *name, rte_mem_event_callback_t clb, void *arg)
uint64_t rte_iova_t
Definition: rte_common.h:658
int rte_eal_using_phys_addrs(void)
int rte_mem_lock_page(const void *virt)
int rte_memseg_get_fd(const struct rte_memseg *ms)
unsigned rte_memory_get_nrank(void)
int rte_memseg_get_fd_thread_unsafe(const struct rte_memseg *ms)
int32_t socket_id
Definition: rte_memory.h:57
uint64_t addr_64
Definition: rte_memory.h:53
int rte_extmem_attach(void *va_addr, size_t len)
int(* rte_memseg_walk_t)(const struct rte_memseg_list *msl, const struct rte_memseg *ms, void *arg)
Definition: rte_memory.h:167
size_t len
Definition: rte_memory.h:55
rte_mem_event
Definition: rte_memory.h:605
#define __rte_packed
Definition: rte_common.h:108
uint64_t hugepage_sz
Definition: rte_memory.h:56
phys_addr_t rte_mem_virt2phy(const void *virt)
int rte_mem_check_dma_mask(uint8_t maskbits)
struct rte_memseg * rte_mem_virt2memseg(const void *virt, const struct rte_memseg_list *msl)
uint64_t rte_eal_get_physmem_size(void)
int rte_mem_alloc_validator_register(const char *name, rte_mem_alloc_validator_t clb, int socket_id, size_t limit)
Register validator callback for memory allocations.
void(* rte_mem_event_callback_t)(enum rte_mem_event event_type, const void *addr, size_t len, void *arg)
Definition: rte_memory.h:615
uint64_t phys_addr_t
Definition: rte_common.h:648
int rte_extmem_unregister(void *va_addr, size_t len)
void rte_mem_set_dma_mask(uint8_t maskbits)
void * base_va
Definition: rte_memory.h:69
volatile uint32_t version
Definition: rte_memory.h:76
uint64_t addr_64
Definition: rte_memory.h:71
int rte_extmem_detach(void *va_addr, size_t len)
int rte_memseg_get_fd_offset_thread_unsafe(const struct rte_memseg *ms, size_t *offset)
void rte_dump_physmem_layout(FILE *f)
int rte_extmem_register(void *va_addr, size_t len, rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz)
int rte_mem_check_dma_mask_thread_unsafe(uint8_t maskbits)
int rte_memseg_get_fd_offset(const struct rte_memseg *ms, size_t *offset)
struct rte_memseg_list * rte_mem_virt2memseg_list(const void *virt)
int rte_memseg_list_walk_thread_unsafe(rte_memseg_list_walk_t func, void *arg)
int rte_memseg_list_walk(rte_memseg_list_walk_t func, void *arg) __rte_locks_excluded(rte_mcfg_mem_get_lock())
unsigned int heap
Definition: rte_memory.h:79
unsigned int external
Definition: rte_memory.h:78
int rte_mem_event_callback_unregister(const char *name, void *arg)
uint64_t page_sz
Definition: rte_memory.h:74
int(* rte_memseg_contig_walk_t)(const struct rte_memseg_list *msl, const struct rte_memseg *ms, size_t len, void *arg)
Definition: rte_memory.h:179
int(* rte_mem_alloc_validator_t)(int socket_id, size_t cur_limit, size_t new_len)
Definition: rte_memory.h:673
int(* rte_memseg_list_walk_t)(const struct rte_memseg_list *msl, void *arg)
Definition: rte_memory.h:190
int rte_memseg_walk_thread_unsafe(rte_memseg_walk_t func, void *arg)
uint32_t nrank
Definition: rte_memory.h:59
int rte_memseg_contig_walk(rte_memseg_contig_walk_t func, void *arg)
rte_iova_t rte_mem_virt2iova(const void *virt)