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 * 14 * Copyright (c) 2006 Voltaire. All rights reserved. 15 * Copyright (c) 2009 IBM Corporation. All rights reserved. 16 * 17 * Copyright (c) 2013 Cisco Systems, Inc. All rights reserved. 18 * Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights 19 * reserved. 20 * $COPYRIGHT$ 21 * 22 * Additional copyrights may follow 23 * 24 * $HEADER$ 25 */ 26 /** 27 * @file 28 * Registation cache VMA tree implementation 29 */ 30 #ifndef MCA_RCACHE_BASE_VMA_TREE_H 31 #define MCA_RCACHE_BASE_VMA_TREE_H 32 33 #include "opal_config.h" 34 35 #include "opal/mca/rcache/rcache.h" 36 #include "rcache_base_vma.h" 37 38 /* 39 * Data structures for the tree of allocated memory 40 */ 41 42 struct mca_rcache_base_vma_reg_list_item_t 43 { 44 opal_list_item_t super; 45 mca_rcache_base_registration_t *reg; 46 }; 47 typedef struct mca_rcache_base_vma_reg_list_item_t mca_rcache_base_vma_reg_list_item_t; 48 OBJ_CLASS_DECLARATION(mca_rcache_base_vma_reg_list_item_t); 49 50 /** 51 * The item in the vma_tree itself 52 */ 53 struct mca_rcache_base_vma_item_t 54 { 55 opal_free_list_item_t super; /**< the parent class */ 56 uintptr_t start; /**< the base of the memory range */ 57 uintptr_t end; /**< the bound of the memory range */ 58 opal_list_t reg_list; /**< list of regs on this vma */ 59 bool in_use; /**< vma is in use in iterate */ 60 mca_rcache_base_vma_module_t *vma_module; /**< pointer to rcache vma belongs to */ 61 }; 62 typedef struct mca_rcache_base_vma_item_t mca_rcache_base_vma_item_t; 63 64 OBJ_CLASS_DECLARATION(mca_rcache_base_vma_item_t); 65 66 67 /* 68 * initialize the vma tree 69 */ 70 int mca_rcache_base_vma_tree_init (mca_rcache_base_vma_module_t *vma_module); 71 72 /* 73 * clean up the vma tree 74 */ 75 void mca_rcache_base_vma_tree_finalize(mca_rcache_base_vma_module_t *vma_module); 76 77 /** 78 * Returns the item in the vma tree 79 */ 80 mca_rcache_base_registration_t *mca_rcache_base_vma_tree_find (mca_rcache_base_vma_module_t *vma_module, 81 unsigned char *base, 82 unsigned char *bound); 83 /** 84 * Returns all registration that overlaps given memory region 85 */ 86 int mca_rcache_base_vma_tree_find_all ( 87 mca_rcache_base_vma_module_t *vma_module, unsigned char *base, 88 unsigned char *bound, mca_rcache_base_registration_t **regs, 89 int reg_cnt); 90 91 /* 92 * insert an item in the vma tree 93 */ 94 int mca_rcache_base_vma_tree_insert (mca_rcache_base_vma_module_t *vma_module, 95 mca_rcache_base_registration_t* reg, size_t limit); 96 97 /* 98 * remove an item from the vma tree 99 */ 100 int mca_rcache_base_vma_tree_delete (mca_rcache_base_vma_module_t *vma_module, 101 mca_rcache_base_registration_t *reg); 102 103 /* 104 * Dump out the contents of the rcache for debugging. 105 */ 106 void mca_rcache_base_vma_tree_dump_range (mca_rcache_base_vma_module_t *vma_module, 107 unsigned char *base, size_t size, char *msg); 108 109 110 /* 111 * Iterate over matching registration handles in the tree. 112 */ 113 int mca_rcache_base_vma_tree_iterate (mca_rcache_base_vma_module_t *vma_module, 114 unsigned char *base, size_t size, 115 int (*callback_fn) (struct mca_rcache_base_registration_t *, void *), 116 void *ctx); 117 118 #endif /* MCA_RCACHE_BASE_VMA_TREE_H */ 119