1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 #ifndef MCA_MEMHEAP_BUDDY_H
  15 #define MCA_MEMHEAP_BUDDY_H
  16 
  17 #include "oshmem_config.h"
  18 #include "oshmem/mca/mca.h"
  19 #include "opal/class/opal_list.h"
  20 #include "opal/threads/mutex.h"
  21 #include "oshmem/mca/memheap/memheap.h"
  22 #include "oshmem/mca/memheap/base/base.h"
  23 #include "oshmem/mca/spml/spml.h"
  24 #include "oshmem/util/oshmem_util.h"
  25 #include "opal/class/opal_hash_table.h"
  26 #include "opal/mca/btl/btl.h"
  27 #include <string.h>
  28 #include <sys/types.h>
  29 #include <math.h>
  30 
  31 #define BITS_PER_BYTE                    8
  32 #define __BITOPS_WORDSIZE                64
  33 #define DEFAULT_HASHTABLE_SIZE           100
  34 
  35 #define BITOP_WORD(nr)                   ((nr) / bits_per_long())
  36 #define DIV_ROUND_UP(n,d)                (((n) + (d) - 1) / (d))
  37 #define BITS_TO_LONGS(nr)                DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(unsigned long))
  38 #define __BITOPS_WORDS(bits)             (((bits)+__BITOPS_WORDSIZE-1)/__BITOPS_WORDSIZE)
  39 #define clear_bit(x,y)                   __clear_bit((x), (y))
  40 #define set_bit(x,y)                     __set_bit((x), (y))
  41 #define find_first_bit(addr, size)      find_next_bit((addr), (size), 0)
  42 
  43 BEGIN_C_DECLS
  44 
  45 struct mca_memheap_buddy_heap_t {
  46     unsigned long **bits; 
  47     unsigned *num_free; 
  48     unsigned max_order; 
  49     unsigned min_order; 
  50     void* symmetric_heap; 
  51     opal_hash_table_t* symmetric_heap_hashtable; 
  52 };
  53 typedef struct mca_memheap_buddy_heap_t mca_memheap_buddy_heap_t;
  54 
  55 
  56 struct mca_memheap_buddy_module_t {
  57     mca_memheap_base_module_t super;
  58 
  59     int priority; 
  60     mca_memheap_buddy_heap_t heap;
  61     mca_memheap_buddy_heap_t private_heap;
  62     opal_mutex_t lock; 
  63 };
  64 typedef struct mca_memheap_buddy_module_t mca_memheap_buddy_module_t;
  65 OSHMEM_DECLSPEC extern mca_memheap_buddy_module_t memheap_buddy;
  66 
  67 
  68 
  69 
  70 
  71 OSHMEM_DECLSPEC extern int mca_memheap_buddy_module_init(memheap_context_t *);
  72 OSHMEM_DECLSPEC extern int mca_memheap_buddy_alloc(size_t, void**);
  73 OSHMEM_DECLSPEC extern int mca_memheap_buddy_realloc(size_t, void*, void **);
  74 OSHMEM_DECLSPEC extern int mca_memheap_buddy_align(size_t, size_t, void**);
  75 OSHMEM_DECLSPEC extern int mca_memheap_buddy_free(void*);
  76 OSHMEM_DECLSPEC extern int mca_memheap_buddy_finalize(void);
  77 
  78 
  79 OSHMEM_DECLSPEC extern int mca_memheap_buddy_private_alloc(size_t, void**);
  80 OSHMEM_DECLSPEC extern int mca_memheap_buddy_private_free(void*);
  81 
  82 
  83 
  84 
  85 
  86 END_C_DECLS
  87 
  88 #endif