File: gnix_mbox_allocator.h

package info (click to toggle)
mpich 4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 101,184 kB
  • sloc: ansic: 1,040,629; cpp: 82,270; javascript: 40,763; perl: 27,933; python: 16,041; sh: 14,676; xml: 14,418; f90: 12,916; makefile: 9,270; fortran: 8,046; java: 4,635; asm: 324; ruby: 103; awk: 27; lisp: 19; php: 8; sed: 4
file content (201 lines) | stat: -rw-r--r-- 6,543 bytes parent folder | download | duplicates (4)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * Copyright (c) 2015 Los Alamos National Security, LLC. All rights reserved.
 * Copyright (c) 2015-2016 Cray Inc.  All rights reserved.
 * Copyright (c) 2019 Triad National Security, LLC. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef _GNIX_MBOX_ALLOCATOR_
#define _GNIX_MBOX_ALLOCATOR_

#include <stddef.h>

#include "gni_pub.h"

#include "gnix.h"
#include "gnix_bitmap.h"

enum gnix_page_size {
	GNIX_PAGE_2MB   = 2,
	GNIX_PAGE_4MB   = 4,
	GNIX_PAGE_8MB   = 8,
	GNIX_PAGE_16MB  = 16,
	GNIX_PAGE_32MB  = 32,
	GNIX_PAGE_64MB  = 64,
	GNIX_PAGE_128MB = 128,
	GNIX_PAGE_256MB = 256,
	GNIX_PAGE_512MB = 512
};

/**
 * Structure representing mailbox allocated by mbox_allocator.
 *
 * @var memory_handle	Memory handle returned by GNI_MemRegister.
 * @var slab		Slab from which mbox was allocated.
 * @var base		Pointer to the start of the memory returned by mmap.
 * @var offset		Offset from the base pointer where mailbox is located.
 */
struct gnix_mbox {
	gni_mem_handle_t *memory_handle;
	struct gnix_slab *slab;

	void *base;
	ptrdiff_t offset;
};

/**
 * Structure representing a slab of memory allocated by the mbox_allocator.
 *
 * @var base		The pointer to the start of memory returned by mmap.
 * @var allocator	Pointer to the parent allocator.
 * @var used		Bitmap of slab usage.
 * @var memory_handle	The handle returned by GNI_MemRegister.
 * @var list_entry	Entry for storing structure in slist structs.
 */
struct gnix_slab {
	void *base;
	struct gnix_mbox_alloc_handle *allocator;

	gnix_bitmap_t *used;
	gni_mem_handle_t memory_handle;

	struct slist_entry list_entry;
};

/**
 * Structure representing an mbox_allocator.
 *
 * @var nic_handle	Gnix_nic that the memory is associated with.
 * @var cq_handle	CQ handle that the memory is associated with.
 * @var last_offset	Last offset within file with name filename.
 * @var filename	File name created in the HUGETLBFS.
 * @var fd		Opened descriptor for file with name filename.
 * @var page_size	The page size used for HUGETLBFS and mmap.
 * @var mbox_size	Size per each mailbox.
 * @var mpmmap		Mailboxes per mmap slab.
 * @var slab_list	List of slab objects.
 *
 * @note  If HUGETLBFS is not available, memory is allocated via ANON mmap.
 */
struct gnix_mbox_alloc_handle {
	struct gnix_nic *nic_handle;
	ofi_spin_t lock;
	gni_cq_handle_t cq_handle;

	size_t last_offset;
	char *filename;
	int fd;

	size_t page_size;
	size_t mbox_size;
	size_t mpmmap;

	struct slist slab_list;
};

/**
 * Creates an allocator that can be used with mbox_alloc to allocate mailboxes.
 *
 * @param nic		IN	Gnix_nic memory is associated with.
 * @param cq_handle	IN	CQ handle memory is associated with.
 * @param page_size	IN	Page size used for HUGETLBFS and mmap.
 * @param mbox_size	IN	Size per each mailbox.
 * @param mpmmap	IN	Mailboxes per mmap slab.
 * @param alloc_handle	IN/OUT	Handle needed for use with mbox_alloc.
 *
 * @return FI_SUCCESS	Upon successfully creating an allocator.
 * @return -FI_EINVAL	Upon getting an invalid nic, mbox_size, mpmmap, or
 * alloc_handle.
 * @return -FI_ENOMEM	Upon failure to allocate a handle using calloc.
 * @return -FI_EIO	Upon failure to open a huge page.
 * @return [Unspec]	If failure in GNI_MemRegister. Converts gni_return_t
 * status code to FI_ERRNO value.
 */
int _gnix_mbox_allocator_create(struct gnix_nic *nic,
				gni_cq_handle_t cq_handle,
				enum gnix_page_size page_size,
				size_t mbox_size,
				size_t mpmmap,
				struct gnix_mbox_alloc_handle **alloc_handle);

/**
 * Releases all resources associated with an allocator handle.
 *
 * @param alloc_handle	IN	Alloc handle to destroy.
 *
 * @return FI_SUCCESS	Upon successfully destroying an allocator.
 * @return -FI_EINVAL	Upon receiving an invalid alloc handle.
 * @return -FI_EBUSY	Upon finding that there are still mailboxes allocated
 * that haven't been freed using gnix_mbox_free.
 */
int _gnix_mbox_allocator_destroy(struct gnix_mbox_alloc_handle *alloc_handle);

/**
 * Allocate a new mailbox.
 *
 * @param alloc_handle	IN	Gnix_mbox_alloc_handle to use as allocator.
 * @param ptr		IN/OUT	Pointer to gnix_mbox to be allocated.
 *
 * @return FI_SUCCESS	Upon successfully allocating a mailbox.
 * @return -FI_ENOMEM	Upon not being able to allocate memory for a slab or
 * bitmap.
 * @return -FI_EINVAL	Upon finding that input generates invalid location for
 * mbox.
 * @return [Unspec]	Upon failure in alloc_bitmap. Returns error code from
 * alloc_bitmap.
 * @return [Unspec]	Upon failure in GNI_MemRegister. Converts gni_return_t
 * to FI_ERRNO value.
 */
int _gnix_mbox_alloc(struct gnix_mbox_alloc_handle *alloc_handle,
		     struct gnix_mbox **ptr);

/**
 * Mark mailbox as free.
 *
 * @param ptr		IN	Pointer to allocated gnix_mbox to free.
 *
 * @return FI_SUCCESS	Upon successful free.
 * @return -FI_EINVAL	Upon an invalid parameter, or finding that the bitmap
 * is in a corrupted state.
 */
int _gnix_mbox_free(struct gnix_mbox *ptr);

/*
 * Initialized in gnix_init.c, used for updating filename when creating
 * hugepages.
 */
extern ofi_atomic32_t file_id_counter;

/*
 * safety valve for disabling mbox allocator fallback to base pages
 */

extern bool gnix_mbox_alloc_allow_fallback;
#endif /* _GNIX_MBOX_ALLOCATOR_ */