11/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
22/*
3- * Copyright (c) 2011-2014 Los Alamos National Security, LLC. All rights
3+ * Copyright (c) 2011-2018 Los Alamos National Security, LLC. All rights
44 * reserved.
55 * Copyright (c) 2014 The University of Tennessee and The University
66 * of Tennessee Research Foundation. All rights
@@ -33,7 +33,6 @@ int mca_btl_vader_xpmem_init (void)
3333}
3434
3535struct vader_check_reg_ctx_t {
36- mca_rcache_base_vma_module_t * vma_module ;
3736 mca_btl_base_endpoint_t * ep ;
3837 mca_rcache_base_registration_t * * reg ;
3938 uintptr_t base ;
@@ -58,13 +57,24 @@ static int vader_check_reg (mca_rcache_base_registration_t *reg, void *ctx)
5857 return 1 ;
5958 }
6059
61- /* remove this pointer from the rcache and decrement its reference count
62- (so it is detached later) */
63- mca_rcache_base_vma_delete (vader_ctx -> vma_module , reg );
64-
6560 return 2 ;
6661}
6762
63+ void vader_return_registration (mca_rcache_base_registration_t * reg , struct mca_btl_base_endpoint_t * ep )
64+ {
65+ mca_rcache_base_vma_module_t * vma_module = mca_btl_vader_component .vma_module ;
66+ int32_t ref_count ;
67+
68+ ref_count = opal_atomic_add_fetch_32 (& reg -> ref_count , -1 );
69+ if (OPAL_UNLIKELY (0 == ref_count && !(reg -> flags & MCA_RCACHE_FLAGS_PERSIST ))) {
70+ mca_rcache_base_vma_delete (vma_module , reg );
71+
72+ opal_memchecker_base_mem_noaccess (reg -> rcache_context , (uintptr_t )(reg -> bound - reg -> base ));
73+ (void )xpmem_detach (reg -> rcache_context );
74+ OBJ_RELEASE (reg );
75+ }
76+ }
77+
6878/* look up the remote pointer in the peer rcache and attach if
6979 * necessary */
7080mca_rcache_base_registration_t * vader_get_registation (struct mca_btl_base_endpoint_t * ep , void * rem_ptr ,
@@ -73,7 +83,7 @@ mca_rcache_base_registration_t *vader_get_registation (struct mca_btl_base_endpo
7383 mca_rcache_base_vma_module_t * vma_module = mca_btl_vader_component .vma_module ;
7484 uint64_t attach_align = 1 << mca_btl_vader_component .log_attach_align ;
7585 mca_rcache_base_registration_t * reg = NULL ;
76- vader_check_reg_ctx_t check_ctx = {.ep = ep , .reg = & reg , . vma_module = vma_module };
86+ vader_check_reg_ctx_t check_ctx = {.ep = ep , .reg = & reg };
7787 xpmem_addr_t xpmem_addr ;
7888 uintptr_t base , bound ;
7989 int rc ;
@@ -88,16 +98,17 @@ mca_rcache_base_registration_t *vader_get_registation (struct mca_btl_base_endpo
8898 check_ctx .bound = bound ;
8999
90100 /* several segments may match the base pointer */
91- rc = mca_rcache_base_vma_iterate (vma_module , (void * ) base , bound - base , vader_check_reg , & check_ctx );
101+ rc = mca_rcache_base_vma_iterate (vma_module , (void * ) base , bound - base , true, vader_check_reg , & check_ctx );
92102 if (2 == rc ) {
103+ /* remove this pointer from the rcache and decrement its reference count
104+ (so it is detached later) */
105+ mca_rcache_base_vma_delete (vma_module , reg );
106+
93107 /* start the new segment from the lower of the two bases */
94108 base = (uintptr_t ) reg -> base < base ? (uintptr_t ) reg -> base : base ;
95109
96- if (OPAL_LIKELY (0 == opal_atomic_add_fetch_32 (& reg -> ref_count , -1 ))) {
97- /* this pointer is not in use */
98- (void ) xpmem_detach (reg -> rcache_context );
99- OBJ_RELEASE (reg );
100- }
110+ /* remove the last reference to this registration */
111+ vader_return_registration (reg , ep );
101112
102113 reg = NULL ;
103114 }
@@ -127,7 +138,9 @@ mca_rcache_base_registration_t *vader_get_registation (struct mca_btl_base_endpo
127138
128139 opal_memchecker_base_mem_defined (reg -> rcache_context , bound - base );
129140
130- mca_rcache_base_vma_insert (vma_module , reg , 0 );
141+ if (!(flags & MCA_RCACHE_FLAGS_PERSIST )) {
142+ mca_rcache_base_vma_insert (vma_module , reg , 0 );
143+ }
131144 }
132145 }
133146
@@ -138,30 +151,13 @@ mca_rcache_base_registration_t *vader_get_registation (struct mca_btl_base_endpo
138151 return reg ;
139152}
140153
141- void vader_return_registration (mca_rcache_base_registration_t * reg , struct mca_btl_base_endpoint_t * ep )
142- {
143- mca_rcache_base_vma_module_t * vma_module = mca_btl_vader_component .vma_module ;
144- int32_t ref_count ;
145-
146- ref_count = opal_atomic_add_fetch_32 (& reg -> ref_count , -1 );
147- if (OPAL_UNLIKELY (0 == ref_count && !(reg -> flags & MCA_RCACHE_FLAGS_PERSIST ))) {
148- /* protect rcache access */
149- mca_rcache_base_vma_delete (vma_module , reg );
150-
151- opal_memchecker_base_mem_noaccess (reg -> rcache_context , (uintptr_t )(reg -> bound - reg -> base ));
152- (void )xpmem_detach (reg -> rcache_context );
153- OBJ_RELEASE (reg );
154- }
155- }
156-
157154static int mca_btl_vader_endpoint_xpmem_rcache_cleanup (mca_rcache_base_registration_t * reg , void * ctx )
158155{
159156 mca_rcache_base_vma_module_t * vma_module = mca_btl_vader_component .vma_module ;
160157 mca_btl_vader_endpoint_t * ep = (mca_btl_vader_endpoint_t * ) ctx ;
161158 if ((intptr_t ) reg -> alloc_base == ep -> peer_smp_rank ) {
162159 /* otherwise dereg will fail on assert */
163160 reg -> ref_count = 0 ;
164- (void ) mca_rcache_base_vma_delete (vma_module , reg );
165161 OBJ_RELEASE (reg );
166162 }
167163
@@ -172,7 +168,7 @@ void mca_btl_vader_xpmem_cleanup_endpoint (struct mca_btl_base_endpoint_t *ep)
172168{
173169 /* clean out the registration cache */
174170 (void ) mca_rcache_base_vma_iterate (mca_btl_vader_component .vma_module ,
175- NULL , (size_t ) -1 ,
171+ NULL , (size_t ) -1 , true,
176172 mca_btl_vader_endpoint_xpmem_rcache_cleanup ,
177173 (void * ) ep );
178174 if (ep -> segment_base ) {
0 commit comments