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

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

DEFINITIONS

This source file includes following definitions.
  1. mca_rcache_base_vma_tree_init
  2. mca_rcache_base_vma_tree_finalize
  3. mca_rcache_base_vma_tree_find
  4. mca_rcache_base_vma_tree_find_all_helper
  5. mca_rcache_base_vma_tree_find_all
  6. mca_rcache_base_vma_tree_iterate_helper
  7. mca_rcache_base_vma_tree_iterate
  8. mca_rcache_base_vma_tree_insert
  9. mca_rcache_base_vma_tree_delete
  10. mca_rcache_base_tree_dump_range_helper
  11. mca_rcache_base_vma_tree_dump_range
  12. mca_rcache_base_vma_tree_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-2013 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  *
  14  * Copyright (c) 2006      Voltaire. All rights reserved.
  15  * Copyright (c) 2007      Mellanox Technologies. All rights reserved.
  16  * Copyright (c) 2009      IBM Corporation.  All rights reserved.
  17  * Copyright (c) 2013      NVIDIA Corporation.  All rights reserved.
  18  * Copyright (c) 2013-2018 Cisco Systems, Inc.  All rights reserved
  19  * Copyright (c) 2015-2018 Los Alamos National Security, LLC. All rights
  20  *                         reserved.
  21  * Copyright (c) 2015      Research Organization for Information Science
  22  *                         and Technology (RIST). All rights reserved.
  23  * $COPYRIGHT$
  24  *
  25  * Additional copyrights may follow
  26  *
  27  * $HEADER$
  28  */
  29 
  30 #include "opal/util/output.h"
  31 #include "rcache_base_vma_tree.h"
  32 #include "opal/mca/rcache/base/base.h"
  33 
  34 int mca_rcache_base_vma_tree_init (mca_rcache_base_vma_module_t *vma_module)
  35 {
  36     OBJ_CONSTRUCT(&vma_module->tree, opal_interval_tree_t);
  37     vma_module->reg_cur_cache_size = 0;
  38     return opal_interval_tree_init (&vma_module->tree);
  39 }
  40 
  41 void mca_rcache_base_vma_tree_finalize (mca_rcache_base_vma_module_t *vma_module)
  42 {
  43     OBJ_DESTRUCT(&vma_module->tree);
  44 }
  45 
  46 mca_rcache_base_registration_t *mca_rcache_base_vma_tree_find (mca_rcache_base_vma_module_t *vma_module,
  47                                                                unsigned char *base, unsigned char *bound)
  48 {
  49     return (mca_rcache_base_registration_t *) opal_interval_tree_find_overlapping (&vma_module->tree, (uintptr_t) base,
  50                                                                                    ((uintptr_t) bound) + 1);
  51 }
  52 
  53 struct mca_rcache_base_vma_tree_find_all_helper_args_t {
  54     mca_rcache_base_registration_t **regs;
  55     int reg_cnt;
  56     int reg_max;
  57 };
  58 
  59 typedef struct mca_rcache_base_vma_tree_find_all_helper_args_t mca_rcache_base_vma_tree_find_all_helper_args_t;
  60 
  61 static int mca_rcache_base_vma_tree_find_all_helper (uint64_t low, uint64_t high, void *data, void *ctx)
  62 {
  63     mca_rcache_base_vma_tree_find_all_helper_args_t *args = (mca_rcache_base_vma_tree_find_all_helper_args_t *) ctx;
  64     mca_rcache_base_registration_t *reg = (mca_rcache_base_registration_t *) data;
  65 
  66     if (args->reg_cnt == args->reg_max) {
  67         return args->reg_max;
  68     }
  69 
  70     args->regs[args->reg_cnt++] = reg;
  71 
  72     return OPAL_SUCCESS;
  73 }
  74 
  75 int mca_rcache_base_vma_tree_find_all (mca_rcache_base_vma_module_t *vma_module, unsigned char *base,
  76                                        unsigned char *bound, mca_rcache_base_registration_t **regs,
  77                                        int reg_cnt)
  78 {
  79     mca_rcache_base_vma_tree_find_all_helper_args_t args = {.regs = regs, .reg_max = reg_cnt, .reg_cnt = 0};
  80 
  81     (void) opal_interval_tree_traverse (&vma_module->tree, (uint64_t) (uintptr_t) base, ((uint64_t) (uintptr_t) bound) + 1,
  82                                         true, mca_rcache_base_vma_tree_find_all_helper, &args);
  83     return args.reg_cnt;
  84 }
  85 
  86 struct mca_rcache_base_vma_tree_iterate_helper_args_t {
  87     int (*callback_fn) (struct mca_rcache_base_registration_t *, void *);
  88     void *ctx;
  89 };
  90 typedef struct mca_rcache_base_vma_tree_iterate_helper_args_t mca_rcache_base_vma_tree_iterate_helper_args_t;
  91 
  92 static int mca_rcache_base_vma_tree_iterate_helper (uint64_t low, uint64_t high, void *data, void *ctx)
  93 {
  94     mca_rcache_base_vma_tree_iterate_helper_args_t *args = (mca_rcache_base_vma_tree_iterate_helper_args_t *) ctx;
  95     return args->callback_fn ((mca_rcache_base_registration_t *) data, args->ctx);
  96 }
  97 
  98 int mca_rcache_base_vma_tree_iterate (mca_rcache_base_vma_module_t *vma_module, unsigned char *base, size_t size,
  99                                       bool partial_ok, int (*callback_fn) (struct mca_rcache_base_registration_t *, void *),
 100                                       void *ctx)
 101 {
 102     mca_rcache_base_vma_tree_iterate_helper_args_t args = {.callback_fn = callback_fn, .ctx = ctx};
 103     uintptr_t bound = (uintptr_t) base + size;
 104 
 105     return opal_interval_tree_traverse (&vma_module->tree, (uint64_t) (intptr_t) base, bound, partial_ok,
 106                                         mca_rcache_base_vma_tree_iterate_helper, &args);
 107 }
 108 
 109 int mca_rcache_base_vma_tree_insert (mca_rcache_base_vma_module_t *vma_module,
 110                                      mca_rcache_base_registration_t *reg, size_t limit)
 111 {
 112     return opal_interval_tree_insert (&vma_module->tree, reg, (uintptr_t) reg->base, (uintptr_t) reg->bound + 1);
 113 }
 114 
 115 /**
 116  * Function to remove previously memory from the tree without freeing it
 117  *
 118  * @param base pointer to the memory to free
 119  *
 120  * @retval OPAL_SUCCESS
 121  * @retval OPAL_ERR_BAD_PARAM if the passed base pointer was invalid
 122  */
 123 int mca_rcache_base_vma_tree_delete (mca_rcache_base_vma_module_t *vma_module,
 124                                      mca_rcache_base_registration_t *reg)
 125 {
 126     return opal_interval_tree_delete (&vma_module->tree, (uintptr_t) reg->base, (uintptr_t) reg->bound + 1, reg);
 127 }
 128 
 129 static int mca_rcache_base_tree_dump_range_helper (uint64_t low, uint64_t high, void *data, void *ctx)
 130 {
 131     mca_rcache_base_registration_t *reg = ( mca_rcache_base_registration_t *) data;
 132 
 133     opal_output(0, "    reg: base=%p, bound=%p, ref_count=%d, flags=0x%x",
 134                 (void *) reg->base, (void *) reg->bound, reg->ref_count, reg->flags);
 135 
 136     return OPAL_SUCCESS;
 137 }
 138 
 139 /* Dump out rcache entries within a range of memory.  Useful for debugging. */
 140 void mca_rcache_base_vma_tree_dump_range (mca_rcache_base_vma_module_t *vma_module,
 141                                           unsigned char *base, size_t size, char *msg)
 142 {
 143     uintptr_t bound = (uintptr_t) base + size;
 144 
 145     opal_output(0, "Dumping rcache entries: %s", msg ? msg : "");
 146 
 147     if (opal_interval_tree_size (&vma_module->tree)) {
 148         (void) opal_interval_tree_traverse (&vma_module->tree, (uintptr_t) base, bound, false,
 149                                             mca_rcache_base_tree_dump_range_helper, NULL);
 150     } else {
 151         opal_output(0, "  rcache is empty");
 152     }
 153 }
 154 
 155 size_t mca_rcache_base_vma_tree_size (mca_rcache_base_vma_module_t *vma_module)
 156 {
 157     return opal_interval_tree_size (&vma_module->tree);
 158 }

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