root/opal/mca/rcache/base/rcache_base_create.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mca_rcache_base_module_create
  2. mca_rcache_base_module_destroy

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2005 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
  14  *                         reserved.
  15  * $COPYRIGHT$
  16  *
  17  * Additional copyrights may follow
  18  *
  19  * $HEADER$
  20  */
  21 
  22 #include "opal_config.h"
  23 
  24 #include <stdio.h>
  25 #include <string.h>
  26 
  27 #include "opal/mca/mca.h"
  28 #include "opal/mca/base/base.h"
  29 #include "opal/mca/rcache/rcache.h"
  30 #include "opal/mca/rcache/base/base.h"
  31 #include "opal/mca/rcache/base/rcache_base_mem_cb.h"
  32 #include "rcache_base_vma_tree.h"
  33 #include "opal/util/show_help.h"
  34 #include "opal/util/proc.h"
  35 
  36 #include "opal/runtime/opal_params.h"
  37 #include "opal/memoryhooks/memory.h"
  38 
  39 mca_rcache_base_module_t* mca_rcache_base_module_create (const char* name, void *user_data,
  40                                                          struct mca_rcache_base_resources_t* resources)
  41 {
  42     mca_rcache_base_component_t* component = NULL;
  43     mca_rcache_base_module_t* module = NULL;
  44     mca_base_component_list_item_t *cli;
  45     mca_rcache_base_selected_module_t *sm;
  46 
  47     /* on the very first creation of a module we init the memory
  48        callback */
  49     if (!mca_rcache_base_used_mem_hooks) {
  50         /* Use the memory hooks if leave_pinned or
  51          * leave_pinned_pipeline is enabled (note that either of these
  52          * leave_pinned variables may have been set by a user MCA
  53          * param or elsewhere in the code base).  Yes, we could havexc
  54          * coded this more succinctly, but this is more clear. Do not
  55          * check memory hooks if the rcache does not provide an
  56          * range invalidation function.. */
  57         if (opal_leave_pinned != 0 || opal_leave_pinned_pipeline) {
  58             /* open the memory manager components.  Memory hooks may be
  59                triggered before this (any time after mem_free_init(),
  60                actually).  This is a hook available for memory manager hooks
  61                without good initialization routine support */
  62             (void) mca_base_framework_open (&opal_memory_base_framework, 0);
  63 
  64             if ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) ==
  65                 ((OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT) &
  66                  opal_mem_hooks_support_level())) {
  67                 if (-1 == opal_leave_pinned) {
  68                     opal_leave_pinned = !opal_leave_pinned_pipeline;
  69                 }
  70                 opal_mem_hooks_register_release(mca_rcache_base_mem_cb, NULL);
  71             } else if (1 == opal_leave_pinned || opal_leave_pinned_pipeline) {
  72                 opal_show_help("help-rcache-base.txt", "leave pinned failed",
  73                                true, name, OPAL_NAME_PRINT(OPAL_PROC_MY_NAME),
  74                                opal_proc_local_get()->proc_hostname);
  75                 return NULL;
  76             }
  77 
  78             /* Set this to true so that rcache_base_close knows to
  79                cleanup */
  80             mca_rcache_base_used_mem_hooks = 1;
  81         }
  82     }
  83 
  84     OPAL_LIST_FOREACH(cli, &opal_rcache_base_framework.framework_components, mca_base_component_list_item_t) {
  85          component = (mca_rcache_base_component_t *) cli->cli_component;
  86          if(0 == strcmp(component->rcache_version.mca_component_name, name)) {
  87              module = component->rcache_init (resources);
  88              break;
  89          }
  90     }
  91 
  92     if ( NULL == module ) {
  93         return NULL;
  94     }
  95 
  96     sm = OBJ_NEW(mca_rcache_base_selected_module_t);
  97     sm->rcache_component = component;
  98     sm->rcache_module = module;
  99     sm->user_data = user_data;
 100     opal_list_append(&mca_rcache_base_modules, (opal_list_item_t*) sm);
 101 
 102     return module;
 103 }
 104 
 105 int mca_rcache_base_module_destroy(mca_rcache_base_module_t *module)
 106 {
 107     mca_rcache_base_selected_module_t *sm, *next;
 108 
 109     OPAL_LIST_FOREACH_SAFE(sm, next, &mca_rcache_base_modules, mca_rcache_base_selected_module_t) {
 110         if (module == sm->rcache_module) {
 111             opal_list_remove_item(&mca_rcache_base_modules, (opal_list_item_t*)sm);
 112             if (NULL != sm->rcache_module->rcache_finalize) {
 113                 sm->rcache_module->rcache_finalize(sm->rcache_module);
 114             }
 115             OBJ_RELEASE(sm);
 116             return OPAL_SUCCESS;
 117         }
 118     }
 119 
 120     return OPAL_ERR_NOT_FOUND;
 121 }

/* [<][>][^][v][top][bottom][index][help] */