xref: /dpdk/lib/eal/common/malloc_mp.h (revision 971d2b57972919527e27ed683032a71864a2eb56)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2018 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef MALLOC_MP_H
699a2dd95SBruce Richardson #define MALLOC_MP_H
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson #include <stdbool.h>
999a2dd95SBruce Richardson #include <stdint.h>
1099a2dd95SBruce Richardson 
1199a2dd95SBruce Richardson #include <rte_common.h>
1299a2dd95SBruce Richardson #include <rte_random.h>
1399a2dd95SBruce Richardson 
1499a2dd95SBruce Richardson /* forward declarations */
1599a2dd95SBruce Richardson struct malloc_heap;
1699a2dd95SBruce Richardson struct rte_memseg;
1799a2dd95SBruce Richardson 
1899a2dd95SBruce Richardson /* multiprocess synchronization structures for malloc */
1999a2dd95SBruce Richardson enum malloc_req_type {
2099a2dd95SBruce Richardson 	REQ_TYPE_ALLOC,     /**< ask primary to allocate */
2199a2dd95SBruce Richardson 	REQ_TYPE_FREE,      /**< ask primary to free */
2299a2dd95SBruce Richardson 	REQ_TYPE_SYNC       /**< ask secondary to synchronize its memory map */
2399a2dd95SBruce Richardson };
2499a2dd95SBruce Richardson 
2599a2dd95SBruce Richardson enum malloc_req_result {
2699a2dd95SBruce Richardson 	REQ_RESULT_SUCCESS,
2799a2dd95SBruce Richardson 	REQ_RESULT_FAIL
2899a2dd95SBruce Richardson };
2999a2dd95SBruce Richardson 
3099a2dd95SBruce Richardson struct malloc_req_alloc {
3199a2dd95SBruce Richardson 	uint32_t malloc_heap_idx;
3299a2dd95SBruce Richardson 	uint64_t page_sz;
3399a2dd95SBruce Richardson 	size_t elt_size;
3499a2dd95SBruce Richardson 	int socket;
3599a2dd95SBruce Richardson 	unsigned int flags;
3699a2dd95SBruce Richardson 	size_t align;
3799a2dd95SBruce Richardson 	size_t bound;
3899a2dd95SBruce Richardson 	bool contig;
3999a2dd95SBruce Richardson };
4099a2dd95SBruce Richardson 
4199a2dd95SBruce Richardson struct malloc_req_free {
4299a2dd95SBruce Richardson 	union {
4399a2dd95SBruce Richardson 		void *addr;
4499a2dd95SBruce Richardson 		uint64_t addr_64;
4599a2dd95SBruce Richardson 	};
4699a2dd95SBruce Richardson 	size_t len;
4799a2dd95SBruce Richardson };
4899a2dd95SBruce Richardson 
4999a2dd95SBruce Richardson struct malloc_mp_req {
5099a2dd95SBruce Richardson 	enum malloc_req_type t;
5199a2dd95SBruce Richardson 	union {
5299a2dd95SBruce Richardson 		struct malloc_req_alloc alloc_req;
5399a2dd95SBruce Richardson 		struct malloc_req_free free_req;
5499a2dd95SBruce Richardson 	};
5599a2dd95SBruce Richardson 	uint64_t id; /**< not to be populated by caller */
5699a2dd95SBruce Richardson 	enum malloc_req_result result;
5799a2dd95SBruce Richardson };
5899a2dd95SBruce Richardson 
5999a2dd95SBruce Richardson int
6099a2dd95SBruce Richardson register_mp_requests(void);
6199a2dd95SBruce Richardson 
62*a0cc7be2SStephen Hemminger void
63*a0cc7be2SStephen Hemminger unregister_mp_requests(void);
64*a0cc7be2SStephen Hemminger 
6599a2dd95SBruce Richardson int
6699a2dd95SBruce Richardson request_to_primary(struct malloc_mp_req *req);
6799a2dd95SBruce Richardson 
6899a2dd95SBruce Richardson /* synchronous memory map sync request */
6999a2dd95SBruce Richardson int
7099a2dd95SBruce Richardson request_sync(void);
7199a2dd95SBruce Richardson 
7299a2dd95SBruce Richardson /* functions from malloc_heap exposed here */
7399a2dd95SBruce Richardson int
7499a2dd95SBruce Richardson malloc_heap_free_pages(void *aligned_start, size_t aligned_len);
7599a2dd95SBruce Richardson 
7699a2dd95SBruce Richardson struct malloc_elem *
7799a2dd95SBruce Richardson alloc_pages_on_heap(struct malloc_heap *heap, uint64_t pg_sz, size_t elt_size,
7899a2dd95SBruce Richardson 		int socket, unsigned int flags, size_t align, size_t bound,
7999a2dd95SBruce Richardson 		bool contig, struct rte_memseg **ms, int n_segs);
8099a2dd95SBruce Richardson 
8199a2dd95SBruce Richardson void
8299a2dd95SBruce Richardson rollback_expand_heap(struct rte_memseg **ms, int n_segs,
8399a2dd95SBruce Richardson 		struct malloc_elem *elem, void *map_addr, size_t map_len);
8499a2dd95SBruce Richardson 
8599a2dd95SBruce Richardson #endif /* MALLOC_MP_H */
86