This source file includes following definitions.
- mca_memheap_base_reg
- mca_memheap_base_dereg
- _dereg_segment
- _reg_segment
1
2
3
4
5
6
7
8
9
10
11
12 #include "oshmem_config.h"
13
14 #include "oshmem/util/oshmem_util.h"
15 #include "oshmem/proc/proc.h"
16 #include "oshmem/mca/memheap/memheap.h"
17 #include "oshmem/mca/memheap/base/base.h"
18
19 #include <stdio.h>
20
21 static int _dereg_segment(map_segment_t *s);
22 static int _reg_segment(map_segment_t *s, int *num_btl);
23
24 int mca_memheap_base_reg(mca_memheap_map_t *memheap_map)
25 {
26 int ret;
27 int i;
28
29 for (i = 0; i < memheap_map->n_segments; i++) {
30 map_segment_t *s = &memheap_map->mem_segs[i];
31
32 MEMHEAP_VERBOSE(5,
33 "register seg#%02d: 0x%p - 0x%p %llu bytes type=0x%X id=0x%X",
34 i,
35 s->super.va_base,
36 s->super.va_end,
37 (long long)((uintptr_t)s->super.va_end - (uintptr_t)s->super.va_base),
38 s->type,
39 s->seg_id);
40 ret = _reg_segment(s, &memheap_map->num_transports);
41 if (OSHMEM_SUCCESS != ret) {
42 mca_memheap_base_dereg(memheap_map);
43 return ret;
44 }
45 }
46
47 return OSHMEM_SUCCESS;
48 }
49
50 int mca_memheap_base_dereg(mca_memheap_map_t *memheap_map)
51 {
52 int i;
53
54 for (i = 0; i < memheap_map->n_segments; i++) {
55 map_segment_t *s = &memheap_map->mem_segs[i];
56
57 if (!MAP_SEGMENT_IS_VALID(s))
58 continue;
59
60 MEMHEAP_VERBOSE(5,
61 "deregistering segment#%d: %p - %p %llu bytes",
62 i,
63 s->super.va_base,
64 s->super.va_end,
65 (long long)((uintptr_t)s->super.va_end - (uintptr_t)s->super.va_base));
66 (void)_dereg_segment(s);
67 }
68
69 return OSHMEM_SUCCESS;
70 }
71
72 static int _dereg_segment(map_segment_t *s)
73 {
74 int rc = OSHMEM_SUCCESS;
75 int j;
76 int nprocs, my_pe;
77
78 nprocs = oshmem_num_procs();
79 my_pe = oshmem_my_proc_id();
80
81 MCA_SPML_CALL(deregister(s->mkeys));
82
83 if (s->mkeys_cache) {
84 for (j = 0; j < nprocs; j++) {
85 if (j == my_pe)
86 continue;
87 if (s->mkeys_cache[j]) {
88 if (s->mkeys_cache[j]->len) {
89 MCA_SPML_CALL(rmkey_free(s->mkeys_cache[j]));
90 free(s->mkeys_cache[j]->u.data);
91 s->mkeys_cache[j]->len = 0;
92 }
93 free(s->mkeys_cache[j]);
94 s->mkeys_cache[j] = NULL;
95 }
96 }
97 free(s->mkeys_cache);
98 s->mkeys_cache = NULL;
99 }
100
101 MAP_SEGMENT_INVALIDATE(s);
102
103 return rc;
104 }
105
106 static int _reg_segment(map_segment_t *s, int *num_btl)
107 {
108 int rc = OSHMEM_SUCCESS;
109 int my_pe;
110 int nprocs;
111
112 nprocs = oshmem_num_procs();
113 my_pe = oshmem_my_proc_id();
114
115 s->mkeys_cache = (sshmem_mkey_t **) calloc(nprocs,
116 sizeof(sshmem_mkey_t *));
117 if (NULL == s->mkeys_cache) {
118 MEMHEAP_ERROR("Failed to allocate memory for remote segments");
119 rc = OSHMEM_ERROR;
120 }
121
122 if (!rc) {
123 s->mkeys = MCA_SPML_CALL(register((void *)(unsigned long)s->super.va_base,
124 (uintptr_t)s->super.va_end - (uintptr_t)s->super.va_base,
125 s->seg_id,
126 num_btl));
127 if (NULL == s->mkeys) {
128 free(s->mkeys_cache);
129 s->mkeys_cache = NULL;
130
131 MEMHEAP_ERROR("Failed to register segment");
132 rc = OSHMEM_ERROR;
133 }
134 }
135
136 if (OSHMEM_SUCCESS == rc) {
137 s->mkeys_cache[my_pe] = s->mkeys;
138 MAP_SEGMENT_SET_VALID(s);
139 }
140
141 return rc;
142 }