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