xref: /dpdk/lib/eal/common/malloc_mp.h (revision 9ad3a41ab2a10db0059e1decdbf3ec038f348e08)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4 
5 #ifndef MALLOC_MP_H
6 #define MALLOC_MP_H
7 
8 #include <stdbool.h>
9 #include <stdint.h>
10 
11 #include <rte_common.h>
12 #include <rte_random.h>
13 
14 /* forward declarations */
15 struct malloc_heap;
16 struct rte_memseg;
17 
18 /* multiprocess synchronization structures for malloc */
19 enum malloc_req_type {
20 	REQ_TYPE_ALLOC,     /**< ask primary to allocate */
21 	REQ_TYPE_FREE,      /**< ask primary to free */
22 	REQ_TYPE_SYNC       /**< ask secondary to synchronize its memory map */
23 };
24 
25 enum malloc_req_result {
26 	REQ_RESULT_SUCCESS,
27 	REQ_RESULT_FAIL
28 };
29 
30 struct malloc_req_alloc {
31 	uint32_t malloc_heap_idx;
32 	uint64_t page_sz;
33 	size_t elt_size;
34 	int socket;
35 	unsigned int flags;
36 	size_t align;
37 	size_t bound;
38 	bool contig;
39 };
40 
41 struct malloc_req_free {
42 	RTE_STD_C11
43 	union {
44 		void *addr;
45 		uint64_t addr_64;
46 	};
47 	size_t len;
48 };
49 
50 struct malloc_mp_req {
51 	enum malloc_req_type t;
52 	RTE_STD_C11
53 	union {
54 		struct malloc_req_alloc alloc_req;
55 		struct malloc_req_free free_req;
56 	};
57 	uint64_t id; /**< not to be populated by caller */
58 	enum malloc_req_result result;
59 };
60 
61 int
62 register_mp_requests(void);
63 
64 void
65 unregister_mp_requests(void);
66 
67 int
68 request_to_primary(struct malloc_mp_req *req);
69 
70 /* synchronous memory map sync request */
71 int
72 request_sync(void);
73 
74 /* functions from malloc_heap exposed here */
75 int
76 malloc_heap_free_pages(void *aligned_start, size_t aligned_len);
77 
78 struct malloc_elem *
79 alloc_pages_on_heap(struct malloc_heap *heap, uint64_t pg_sz, size_t elt_size,
80 		int socket, unsigned int flags, size_t align, size_t bound,
81 		bool contig, struct rte_memseg **ms, int n_segs);
82 
83 void
84 rollback_expand_heap(struct rte_memseg **ms, int n_segs,
85 		struct malloc_elem *elem, void *map_addr, size_t map_len);
86 
87 #endif /* MALLOC_MP_H */
88