Skip to content

Commit 0edfd32

Browse files
committed
opal: clean up init/finalize
This commit contains the following changes: - Remove the unused opal_test_init/opal_test_finalize functions. These functions are not used by anything in the code base or MTT. Tests use opal_init_util/opal_finalize_util instead. - Get rid of gotos in opal_init_util and opal_init. Replaced them with a cleaner solution. - Automatically register cleanup functions in init functions. The cleanup functions are executed in the reverse order of the initialization functions. The cleanup functions are run in opal_finalize_util() before tearing down the class system. Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
1 parent c5292a0 commit 0edfd32

31 files changed

+597
-634
lines changed

opal/datatype/opal_datatype.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
1717
* Copyright (c) 2017-2018 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
19+
* Copyright (c) 2018 Triad National Security, LLC. All rights
20+
* reserved.
1921
* $COPYRIGHT$
2022
*
2123
* Additional copyrights may follow
@@ -181,7 +183,6 @@ OPAL_DECLSPEC extern const opal_datatype_t opal_datatype_wchar;
181183
*/
182184
int opal_datatype_register_params(void);
183185
OPAL_DECLSPEC int32_t opal_datatype_init( void );
184-
OPAL_DECLSPEC int32_t opal_datatype_finalize( void );
185186
OPAL_DECLSPEC opal_datatype_t* opal_datatype_create( int32_t expectedSize );
186187
OPAL_DECLSPEC int32_t opal_datatype_create_desc( opal_datatype_t * datatype, int32_t expectedSize );
187188
OPAL_DECLSPEC int32_t opal_datatype_commit( opal_datatype_t * pData );

opal/datatype/opal_datatype_module.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* reserved.
1818
* Copyright (c) 2015 Research Organization for Information Science
1919
* and Technology (RIST). All rights reserved.
20+
* Copyright (c) 2018 Triad National Security, LLC. All rights
21+
* reserved.
2022
* $COPYRIGHT$
2123
*
2224
* Additional copyrights may follow
@@ -28,6 +30,7 @@
2830

2931
#include <stddef.h>
3032

33+
#include "opal/runtime/opal.h"
3134
#include "opal/util/arch.h"
3235
#include "opal/util/output.h"
3336
#include "opal/datatype/opal_datatype_internal.h"
@@ -204,6 +207,21 @@ int opal_datatype_register_params(void)
204207
return OPAL_SUCCESS;
205208
}
206209

210+
static void opal_datatype_finalize (void)
211+
{
212+
/* As the synonyms are just copies of the internal data we should not free them.
213+
* Anyway they are over the limit of OPAL_DATATYPE_MAX_PREDEFINED so they will never get freed.
214+
*/
215+
216+
/* As they are statically allocated they cannot be released. But we
217+
* can call OBJ_DESTRUCT, just to free all internally allocated ressources.
218+
*/
219+
/* clear all master convertors */
220+
opal_convertor_destroy_masters();
221+
222+
opal_output_close (opal_datatype_dfd);
223+
opal_datatype_dfd = -1;
224+
}
207225

208226
int32_t opal_datatype_init( void )
209227
{
@@ -242,27 +260,7 @@ int32_t opal_datatype_init( void )
242260
opal_output_set_verbosity(opal_datatype_dfd, opal_ddt_verbose);
243261
}
244262

245-
return OPAL_SUCCESS;
246-
}
247-
248-
249-
int32_t opal_datatype_finalize( void )
250-
{
251-
/* As the synonyms are just copies of the internal data we should not free them.
252-
* Anyway they are over the limit of OPAL_DATATYPE_MAX_PREDEFINED so they will never get freed.
253-
*/
254-
255-
/* As they are statically allocated they cannot be released. But we
256-
* can call OBJ_DESTRUCT, just to free all internally allocated ressources.
257-
*/
258-
#if defined(VERBOSE)
259-
if( opal_datatype_dfd != -1 )
260-
opal_output_close( opal_datatype_dfd );
261-
opal_datatype_dfd = -1;
262-
#endif /* VERBOSE */
263-
264-
/* clear all master convertors */
265-
opal_convertor_destroy_masters();
263+
opal_finalize_register_cleanup (opal_datatype_finalize);
266264

267265
return OPAL_SUCCESS;
268266
}

opal/dss/dss.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* -*- C -*-
2-
*
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
33
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
@@ -12,6 +12,8 @@
1212
* All rights reserved.
1313
* Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
1414
* Copyright (c) 2014-2017 Intel, Inc. All rights reserved.
15+
* Copyright (c) 2018 Triad National Security, LLC. All rights
16+
* reserved.
1517
* $COPYRIGHT$
1618
*
1719
* Additional copyrights may follow
@@ -357,12 +359,6 @@ OPAL_DECLSPEC int opal_dss_register_vars (void);
357359
*/
358360
OPAL_DECLSPEC int opal_dss_open(void);
359361

360-
/**
361-
* DSS finalize function
362-
*/
363-
OPAL_DECLSPEC int opal_dss_close(void);
364-
365-
366362
/**
367363
* Copy a data value from one location to another.
368364
*

opal/dss/dss_open_close.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* -*- Mode: C; c-basic-offset:4 ; -*- */
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
22
/*
33
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
44
* University Research and Technology
@@ -15,6 +15,8 @@
1515
* Copyright (c) 2015 Research Organization for Information Science
1616
* and Technology (RIST). All rights reserved.
1717
* Copyright (c) 2017 IBM Corporation. All rights reserved.
18+
* Copyright (c) 2018 Triad National Security, LLC. All rights
19+
* reserved.
1820
* $COPYRIGHT$
1921
*
2022
* Additional copyrights may follow
@@ -26,6 +28,7 @@
2628
*/
2729
#include "opal_config.h"
2830

31+
#include "opal/runtime/opal.h"
2932
#include "opal/mca/base/mca_base_var.h"
3033

3134
#include "opal/dss/dss_internal.h"
@@ -312,6 +315,21 @@ int opal_dss_register_vars (void)
312315
return (0 > ret) ? ret : OPAL_SUCCESS;
313316
}
314317

318+
static void opal_dss_close (void)
319+
{
320+
opal_dss_initialized = false;
321+
322+
for (int i = 0 ; i < opal_pointer_array_get_size(&opal_dss_types) ; ++i) {
323+
opal_dss_type_info_t *info = (opal_dss_type_info_t*)opal_pointer_array_get_item(&opal_dss_types, i);
324+
if (NULL != info) {
325+
opal_pointer_array_set_item(&opal_dss_types, i, NULL);
326+
OBJ_RELEASE(info);
327+
}
328+
}
329+
330+
OBJ_DESTRUCT(&opal_dss_types);
331+
}
332+
315333
int opal_dss_open(void)
316334
{
317335
int rc;
@@ -658,28 +676,8 @@ int opal_dss_open(void)
658676
/* All done */
659677

660678
opal_dss_initialized = true;
661-
return OPAL_SUCCESS;
662-
}
663679

664-
665-
int opal_dss_close(void)
666-
{
667-
int32_t i;
668-
669-
if (!opal_dss_initialized) {
670-
return OPAL_SUCCESS;
671-
}
672-
opal_dss_initialized = false;
673-
674-
for (i = 0 ; i < opal_pointer_array_get_size(&opal_dss_types) ; ++i) {
675-
opal_dss_type_info_t *info = (opal_dss_type_info_t*)opal_pointer_array_get_item(&opal_dss_types, i);
676-
if (NULL != info) {
677-
opal_pointer_array_set_item(&opal_dss_types, i, NULL);
678-
OBJ_RELEASE(info);
679-
}
680-
}
681-
682-
OBJ_DESTRUCT(&opal_dss_types);
680+
opal_finalize_register_cleanup (opal_dss_close);
683681

684682
return OPAL_SUCCESS;
685683
}

opal/mca/base/base.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* Copyright (c) 2015 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
1818
* Copyright (c) 2017 IBM Corporation. All rights reserved.
19+
* Copyright (c) 2018 Triad National Security, LLC. All rights
20+
* reserved.
1921
* $COPYRIGHT$
2022
*
2123
* Additional copyrights may follow
@@ -130,7 +132,7 @@ OPAL_DECLSPEC int mca_base_open(void);
130132
* It must be the last MCA function invoked. It is normally invoked
131133
* during the finalize stage.
132134
*/
133-
OPAL_DECLSPEC int mca_base_close(void);
135+
OPAL_DECLSPEC void mca_base_close(void);
134136

135137
/**
136138
* A generic select function

opal/mca/base/mca_base_close.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,34 @@ extern int mca_base_opened;
3333
/*
3434
* Main MCA shutdown.
3535
*/
36-
int mca_base_close(void)
36+
37+
void mca_base_close (void)
3738
{
3839
assert (mca_base_opened);
39-
if (!--mca_base_opened) {
40-
/* deregister all MCA base parameters */
41-
int group_id = mca_base_var_group_find ("opal", "mca", "base");
40+
if (--mca_base_opened) {
41+
return;
42+
}
4243

43-
if (-1 < group_id) {
44-
mca_base_var_group_deregister (group_id);
45-
}
44+
/* deregister all MCA base parameters */
45+
int group_id = mca_base_var_group_find ("opal", "mca", "base");
4646

47-
/* release the default paths */
48-
if (NULL != mca_base_system_default_path) {
49-
free(mca_base_system_default_path);
50-
}
51-
if (NULL != mca_base_user_default_path) {
52-
free(mca_base_user_default_path);
53-
}
47+
if (-1 < group_id) {
48+
mca_base_var_group_deregister (group_id);
49+
}
5450

55-
/* Close down the component repository */
56-
mca_base_component_repository_finalize();
51+
/* release the default paths */
52+
free (mca_base_system_default_path);
53+
mca_base_system_default_path = NULL;
5754

58-
/* Shut down the dynamic component finder */
59-
mca_base_component_find_finalize();
55+
free (mca_base_user_default_path);
56+
mca_base_user_default_path = NULL;
6057

61-
/* Close opal output stream 0 */
62-
opal_output_close(0);
63-
}
58+
/* Close down the component repository */
59+
mca_base_component_repository_finalize();
60+
61+
/* Shut down the dynamic component finder */
62+
mca_base_component_find_finalize();
6463

65-
/* All done */
66-
return OPAL_SUCCESS;
64+
/* Close opal output stream 0 */
65+
opal_output_close(0);
6766
}

opal/mca/base/mca_base_framework.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
66
* Copyright (c) 2017 IBM Corporation. All rights reserved.
77
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
8+
* Copyright (c) 2018 Triad National Security, LLC. All rights
9+
* reserved.
810
* $COPYRIGHT$
911
*
1012
* Additional copyrights may follow
@@ -140,6 +142,22 @@ int mca_base_framework_register (struct mca_base_framework_t *framework,
140142
return OPAL_SUCCESS;
141143
}
142144

145+
int mca_base_framework_register_list (mca_base_framework_t **frameworks, mca_base_register_flag_t flags)
146+
{
147+
if (NULL == frameworks) {
148+
return OPAL_ERR_BAD_PARAM;
149+
}
150+
151+
for (int i = 0 ; frameworks[i] ; ++i) {
152+
int ret = mca_base_framework_register (frameworks[i], flags);
153+
if (OPAL_UNLIKELY(OPAL_SUCCESS != ret && OPAL_ERR_NOT_AVAILABLE != ret)) {
154+
return ret;
155+
}
156+
}
157+
158+
return OPAL_SUCCESS;
159+
}
160+
143161
int mca_base_framework_open (struct mca_base_framework_t *framework,
144162
mca_base_open_flag_t flags) {
145163
int ret;
@@ -189,6 +207,22 @@ int mca_base_framework_open (struct mca_base_framework_t *framework,
189207
return ret;
190208
}
191209

210+
int mca_base_framework_open_list (mca_base_framework_t **frameworks, mca_base_open_flag_t flags)
211+
{
212+
if (NULL == frameworks) {
213+
return OPAL_ERR_BAD_PARAM;
214+
}
215+
216+
for (int i = 0 ; frameworks[i] ; ++i) {
217+
int ret = mca_base_framework_open (frameworks[i], flags);
218+
if (OPAL_UNLIKELY(OPAL_SUCCESS != ret && OPAL_ERR_NOT_AVAILABLE != ret)) {
219+
return ret;
220+
}
221+
}
222+
223+
return OPAL_SUCCESS;
224+
}
225+
192226
int mca_base_framework_close (struct mca_base_framework_t *framework) {
193227
bool is_open = mca_base_framework_is_open (framework);
194228
bool is_registered = mca_base_framework_is_registered (framework);
@@ -247,3 +281,19 @@ int mca_base_framework_close (struct mca_base_framework_t *framework) {
247281

248282
return ret;
249283
}
284+
285+
int mca_base_framework_close_list (mca_base_framework_t **frameworks)
286+
{
287+
if (NULL == frameworks) {
288+
return OPAL_ERR_BAD_PARAM;
289+
}
290+
291+
for (int i = 0 ; frameworks[i] ; ++i) {
292+
int ret = mca_base_framework_close (frameworks[i]);
293+
if (OPAL_UNLIKELY(OPAL_SUCCESS != ret)) {
294+
return ret;
295+
}
296+
}
297+
298+
return OPAL_SUCCESS;
299+
}

0 commit comments

Comments
 (0)