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 union { 43 void *addr; 44 uint64_t addr_64; 45 }; 46 size_t len; 47 }; 48 49 struct malloc_mp_req { 50 enum malloc_req_type t; 51 union { 52 struct malloc_req_alloc alloc_req; 53 struct malloc_req_free free_req; 54 }; 55 uint64_t id; /**< not to be populated by caller */ 56 enum malloc_req_result result; 57 }; 58 59 int 60 register_mp_requests(void); 61 62 void 63 unregister_mp_requests(void); 64 65 int 66 request_to_primary(struct malloc_mp_req *req); 67 68 /* synchronous memory map sync request */ 69 int 70 request_sync(void); 71 72 /* functions from malloc_heap exposed here */ 73 int 74 malloc_heap_free_pages(void *aligned_start, size_t aligned_len); 75 76 struct malloc_elem * 77 alloc_pages_on_heap(struct malloc_heap *heap, uint64_t pg_sz, size_t elt_size, 78 int socket, unsigned int flags, size_t align, size_t bound, 79 bool contig, struct rte_memseg **ms, int n_segs); 80 81 void 82 rollback_expand_heap(struct rte_memseg **ms, int n_segs, 83 struct malloc_elem *elem, void *map_addr, size_t map_len); 84 85 #endif /* MALLOC_MP_H */ 86