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

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

DEFINITIONS

This source file includes following definitions.
  1. mca_rcache_base_vma_module_construct
  2. mca_rcache_base_vma_module_destruct
  3. mca_rcache_base_vma_module_alloc
  4. mca_rcache_base_vma_find
  5. mca_rcache_base_vma_find_all
  6. mca_rcache_base_vma_insert
  7. mca_rcache_base_vma_delete
  8. mca_rcache_base_vma_iterate
  9. mca_rcache_base_vma_dump_range
  10. mca_rcache_base_vma_size

   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-2007 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) 2006      Voltaire. All rights reserved.
  14  * Copyright (c) 2009-2013 Cisco Systems, Inc.  All rights reserved.
  15  * Copyright (c) 2009      IBM Corporation.  All rights reserved.
  16  * Copyright (c) 2013      NVIDIA Corporation.  All rights reserved.
  17  * Copyright (c) 2015-2018 Los Alamos National Security, LLC. All rights
  18  *                         reserved.
  19  *
  20  * $COPYRIGHT$
  21  *
  22  * Additional copyrights may follow
  23  *
  24  * $HEADER$
  25  */
  26 
  27 #include "opal_config.h"
  28 
  29 #include MCA_memory_IMPLEMENTATION_HEADER
  30 #include "opal/mca/memory/memory.h"
  31 #include "opal/mca/rcache/rcache.h"
  32 #include "rcache_base_vma.h"
  33 #include "rcache_base_vma_tree.h"
  34 #include "opal/mca/rcache/base/base.h"
  35 
  36 /**
  37  * Initialize the rcache
  38  */
  39 
  40 static void mca_rcache_base_vma_module_construct (mca_rcache_base_vma_module_t *vma_module) {
  41     OBJ_CONSTRUCT(&vma_module->vma_lock, opal_recursive_mutex_t);
  42     (void) mca_rcache_base_vma_tree_init (vma_module);
  43 }
  44 
  45 static void mca_rcache_base_vma_module_destruct (mca_rcache_base_vma_module_t *vma_module) {
  46     OBJ_DESTRUCT(&vma_module->vma_lock);
  47     mca_rcache_base_vma_tree_finalize (vma_module);
  48 }
  49 
  50 OBJ_CLASS_INSTANCE(mca_rcache_base_vma_module_t, opal_object_t,
  51                    mca_rcache_base_vma_module_construct,
  52                    mca_rcache_base_vma_module_destruct);
  53 
  54 mca_rcache_base_vma_module_t *mca_rcache_base_vma_module_alloc (void)
  55 {
  56     return OBJ_NEW(mca_rcache_base_vma_module_t);
  57 }
  58 
  59 int mca_rcache_base_vma_find (mca_rcache_base_vma_module_t *vma_module, void *addr,
  60                               size_t size, mca_rcache_base_registration_t **reg)
  61 {
  62     int rc;
  63     unsigned char *bound_addr;
  64 
  65     if (size == 0) {
  66         return OPAL_ERROR;
  67     }
  68 
  69     bound_addr = (unsigned char *) ((intptr_t) addr + size - 1);
  70 
  71     /* Check to ensure that the cache is valid */
  72     if (OPAL_UNLIKELY(opal_memory_changed() &&
  73                       NULL != opal_memory->memoryc_process &&
  74                       OPAL_SUCCESS != (rc = opal_memory->memoryc_process()))) {
  75         return rc;
  76     }
  77 
  78     *reg = mca_rcache_base_vma_tree_find (vma_module, (unsigned char *) addr, bound_addr);
  79 
  80     return OPAL_SUCCESS;
  81 }
  82 
  83 int mca_rcache_base_vma_find_all (mca_rcache_base_vma_module_t *vma_module, void *addr,
  84                                   size_t size, mca_rcache_base_registration_t **regs,
  85                                   int reg_cnt)
  86 {
  87     int rc;
  88     unsigned char *bound_addr;
  89 
  90     if(size == 0) {
  91         return OPAL_ERROR;
  92     }
  93 
  94     bound_addr = (unsigned char *) ((intptr_t) addr + size - 1);
  95 
  96     /* Check to ensure that the cache is valid */
  97     if (OPAL_UNLIKELY(opal_memory_changed() &&
  98                       NULL != opal_memory->memoryc_process &&
  99                       OPAL_SUCCESS != (rc = opal_memory->memoryc_process()))) {
 100         return rc;
 101     }
 102 
 103     return mca_rcache_base_vma_tree_find_all (vma_module, (unsigned char *) addr,
 104                                               bound_addr, regs, reg_cnt);
 105 }
 106 
 107 int mca_rcache_base_vma_insert (mca_rcache_base_vma_module_t *vma_module,
 108                                 mca_rcache_base_registration_t *reg, size_t limit)
 109 {
 110     size_t reg_size = reg->bound - reg->base + 1;
 111     int rc;
 112 
 113     if (limit != 0 && reg_size > limit) {
 114         /* return out of resources if request is bigger than cache size
 115          * return temp out of resources otherwise */
 116         return OPAL_ERR_OUT_OF_RESOURCE;
 117     }
 118 
 119     /* Check to ensure that the cache is valid */
 120     if (OPAL_UNLIKELY(opal_memory_changed() &&
 121                       NULL != opal_memory->memoryc_process &&
 122                       OPAL_SUCCESS != (rc = opal_memory->memoryc_process()))) {
 123         return rc;
 124     }
 125 
 126     rc = mca_rcache_base_vma_tree_insert (vma_module, reg, limit);
 127     if (OPAL_LIKELY(OPAL_SUCCESS == rc)) {
 128         /* If we successfully registered, then tell the memory manager
 129            to start monitoring this region */
 130         opal_memory->memoryc_register (reg->base, (uint64_t) reg_size,
 131                                        (uint64_t) (uintptr_t) reg);
 132     }
 133 
 134     return rc;
 135 }
 136 
 137 int mca_rcache_base_vma_delete (mca_rcache_base_vma_module_t *vma_module,
 138                                 mca_rcache_base_registration_t *reg)
 139 {
 140     /* Tell the memory manager that we no longer care about this
 141        region */
 142     opal_memory->memoryc_deregister (reg->base,
 143                                      (uint64_t) (reg->bound - reg->base),
 144                                      (uint64_t) (uintptr_t) reg);
 145     return mca_rcache_base_vma_tree_delete (vma_module, reg);
 146 }
 147 
 148 int mca_rcache_base_vma_iterate (mca_rcache_base_vma_module_t *vma_module,
 149                                  unsigned char *base, size_t size, bool partial_ok,
 150                                  int (*callback_fn) (struct mca_rcache_base_registration_t *, void *),
 151                                  void *ctx)
 152 {
 153     return mca_rcache_base_vma_tree_iterate (vma_module, base, size, partial_ok, callback_fn, ctx);
 154 }
 155 
 156 void mca_rcache_base_vma_dump_range (mca_rcache_base_vma_module_t *vma_module,
 157                                      unsigned char *base, size_t size, char *msg)
 158 {
 159     mca_rcache_base_vma_tree_dump_range (vma_module, base, size, msg);
 160 }
 161 
 162 size_t mca_rcache_base_vma_size (mca_rcache_base_vma_module_t *vma_module)
 163 {
 164     return mca_rcache_base_vma_tree_size (vma_module);
 165 }

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