summaryrefslogtreecommitdiffstats
path: root/lib/librte_eal/common/malloc_mp.h
blob: 2b86b76f6848578cda7025cc72e9a358c76ae214 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2018 Intel Corporation
 */

#ifndef MALLOC_MP_H
#define MALLOC_MP_H

#include <stdbool.h>
#include <stdint.h>

#include <rte_common.h>
#include <rte_random.h>
#include <rte_spinlock.h>
#include <rte_tailq.h>

/* forward declarations */
struct malloc_heap;
struct rte_memseg;

/* multiprocess synchronization structures for malloc */
enum malloc_req_type {
	REQ_TYPE_ALLOC,     /**< ask primary to allocate */
	REQ_TYPE_FREE,      /**< ask primary to free */
	REQ_TYPE_SYNC       /**< ask secondary to synchronize its memory map */
};

enum malloc_req_result {
	REQ_RESULT_SUCCESS,
	REQ_RESULT_FAIL
};

struct malloc_req_alloc {
	struct malloc_heap *heap;
	uint64_t page_sz;
	size_t elt_size;
	int socket;
	unsigned int flags;
	size_t align;
	size_t bound;
	bool contig;
};

struct malloc_req_free {
	RTE_STD_C11
	union {
		void *addr;
		uint64_t addr_64;
	};
	uint64_t len;
};

struct malloc_mp_req {
	enum malloc_req_type t;
	RTE_STD_C11
	union {
		struct malloc_req_alloc alloc_req;
		struct malloc_req_free free_req;
	};
	uint64_t id; /**< not to be populated by caller */
	enum malloc_req_result result;
};

int
register_mp_requests(void);

int
request_to_primary(struct malloc_mp_req *req);

/* synchronous memory map sync request */
int
request_sync(void);

/* functions from malloc_heap exposed here */
int
malloc_heap_free_pages(void *aligned_start, size_t aligned_len);

struct malloc_elem *
alloc_pages_on_heap(struct malloc_heap *heap, uint64_t pg_sz, size_t elt_size,
		int socket, unsigned int flags, size_t align, size_t bound,
		bool contig, struct rte_memseg **ms, int n_segs);

void
rollback_expand_heap(struct rte_memseg **ms, int n_segs,
		struct malloc_elem *elem, void *map_addr, size_t map_len);

#endif /* MALLOC_MP_H */