File: rcache_base_create.c

package info (click to toggle)
openmpi 4.1.0-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 126,560 kB
  • sloc: ansic: 685,465; makefile: 42,952; f90: 19,220; sh: 7,002; java: 6,360; perl: 3,524; cpp: 2,227; python: 1,350; lex: 989; fortran: 61; tcl: 12
file content (121 lines) | stat: -rw-r--r-- 4,887 bytes parent folder | download | duplicates (3)
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
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2005 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
 *                         reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "opal_config.h"

#include <stdio.h>
#include <string.h>

#include "opal/mca/mca.h"
#include "opal/mca/base/base.h"
#include "opal/mca/rcache/rcache.h"
#include "opal/mca/rcache/base/base.h"
#include "opal/mca/rcache/base/rcache_base_mem_cb.h"
#include "rcache_base_vma_tree.h"
#include "opal/util/show_help.h"
#include "opal/util/proc.h"

#include "opal/runtime/opal_params.h"
#include "opal/memoryhooks/memory.h"

mca_rcache_base_module_t* mca_rcache_base_module_create (const char* name, void *user_data,
                                                         struct mca_rcache_base_resources_t* resources)
{
    mca_rcache_base_component_t* component = NULL;
    mca_rcache_base_module_t* module = NULL;
    mca_base_component_list_item_t *cli;
    mca_rcache_base_selected_module_t *sm;

    /* on the very first creation of a module we init the memory
       callback */
    if (!mca_rcache_base_used_mem_hooks) {
        /* Use the memory hooks if leave_pinned or
         * leave_pinned_pipeline is enabled (note that either of these
         * leave_pinned variables may have been set by a user MCA
         * param or elsewhere in the code base).  Yes, we could havexc
         * coded this more succinctly, but this is more clear. Do not
         * check memory hooks if the rcache does not provide an
         * range invalidation function.. */
        if (opal_leave_pinned != 0 || opal_leave_pinned_pipeline) {
            /* open the memory manager components.  Memory hooks may be
               triggered before this (any time after mem_free_init(),
               actually).  This is a hook available for memory manager hooks
               without good initialization routine support */
            (void) mca_base_framework_open (&opal_memory_base_framework, 0);

            if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) ==
                ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) &
                 opal_mem_hooks_support_level())) {
                if (-1 == opal_leave_pinned) {
                    opal_leave_pinned = !opal_leave_pinned_pipeline;
                }
                opal_mem_hooks_register_release(mca_rcache_base_mem_cb, NULL);
            } else if (1 == opal_leave_pinned || opal_leave_pinned_pipeline) {
                opal_show_help("help-rcache-base.txt", "leave pinned failed",
                               true, name, OPAL_NAME_PRINT(OPAL_PROC_MY_NAME),
                               opal_proc_local_get()->proc_hostname);
                return NULL;
            }

            /* Set this to true so that rcache_base_close knows to
               cleanup */
            mca_rcache_base_used_mem_hooks = 1;
        }
    }

    OPAL_LIST_FOREACH(cli, &opal_rcache_base_framework.framework_components, mca_base_component_list_item_t) {
         component = (mca_rcache_base_component_t *) cli->cli_component;
         if(0 == strcmp(component->rcache_version.mca_component_name, name)) {
             module = component->rcache_init (resources);
             break;
         }
    }

    if ( NULL == module ) {
        return NULL;
    }

    sm = OBJ_NEW(mca_rcache_base_selected_module_t);
    sm->rcache_component = component;
    sm->rcache_module = module;
    sm->user_data = user_data;
    opal_list_append(&mca_rcache_base_modules, (opal_list_item_t*) sm);

    return module;
}

int mca_rcache_base_module_destroy(mca_rcache_base_module_t *module)
{
    mca_rcache_base_selected_module_t *sm, *next;

    OPAL_LIST_FOREACH_SAFE(sm, next, &mca_rcache_base_modules, mca_rcache_base_selected_module_t) {
        if (module == sm->rcache_module) {
            opal_list_remove_item(&mca_rcache_base_modules, (opal_list_item_t*)sm);
            if (NULL != sm->rcache_module->rcache_finalize) {
                sm->rcache_module->rcache_finalize(sm->rcache_module);
            }
            OBJ_RELEASE(sm);
            return OPAL_SUCCESS;
        }
    }

    return OPAL_ERR_NOT_FOUND;
}