123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- /*
- * Copyright 2011 Institute of Communication and Computer Systems (ICCS)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- /**
- * \file heap.h
- * \author Ioannis Koutras (joko@microlab.ntua.gr)
- * \date September, 2011
- * Basic structures needed for the dmmlib allocator.
- */
- #ifndef HEAP_H
- #define HEAP_H
- #include "dmm_config.h"
- #include <stdbool.h>
- #ifndef LEON3
- #include <stdint.h>
- #include <stddef.h> /* For size_t support */
- #else
- #include <sys/types.h>
- #endif
- #ifdef HAVE_LOCKS
- #include <pthread.h>
- #endif /* HAVE_LOCKS */
- #ifdef WITH_KNOBS
- /**
- * A structure for knobs states (currently 5)
- *
- * FIXME Have to check them
- *
- * */
- typedef uint8_t knob_state_t;
- #endif /* WITH_KNOBS */
- /** A structure to represent a maptable node.
- * This is a single-linked list holoding blocks of specific size, thus acting
- * as a fixed list within the allocator.
- */
- typedef struct maptable_node_s {
- unsigned int size; /**< The size of the blocks of the fixed list. */
- void *fixed_list_head; /**< Pointer to the head node of the fixed list. */
- struct maptable_node_s *next; /**< Pointer to the next node of the
- maptable. */
- } maptable_node_t;
- #ifdef WITH_STATS
- /** Statistics data structure. */
- typedef struct dmmstats_s {
- size_t max_mem_allocated; /**< Maximum total memory allocated. */
- size_t max_mem_requested; /**< Maximum total memory requested. */
- size_t mem_allocated; /**< Total memory currently allocated. */
- size_t mem_requested; /**< Total memory currently requested. */
- uint32_t live_objects; /**< Number of the currently used blocks. */
- uint32_t read_mem_accesses; /**< Number of read accesses. */
- uint32_t write_mem_accesses; /**< Number of write accesses. */
- uint32_t num_malloc; /**< Number of malloc()'s served. */
- uint32_t num_free; /**< Number of free()'s served. */
- } dmmstats_t;
- #endif /* WITH_STATS */
- #ifdef WITH_KNOBS
- /** A structure to represent tunable parameters of a heap */
- typedef struct dmmknobs_s {
- float frag_threshold; /**< Fragmentation threshold to enable coalescing
- or not. */
- uint32_t mem_threshold; /**< Memory size threshold. */
- #ifdef GOOD_FIT
- float fit_percentage; /**< Fit percentage for good-fit searches. */
- #endif /* GOOD_FIT */
- #ifdef HEAP_VAR_FIT
- /** Current search policy on the allocator's free lists. */
- void *(*search_policy)(heap_t * heap, size_t requested_size);
- #endif /* HEAP_VAR_FIT */
- #ifdef COALESCING_VARIABLE
- size_t max_coalesce_size; /**< Maximum coalesce size; -1 if coalescing
- is not supported */
- #endif /* COALESCING_VARIABLE */
- #ifdef SPLITTING_VARIABLE
- size_t min_split_size; /**< Minimum split size. */
- #endif /* SPLITTING_VARIABLE */
- /* FIXME Need to find explanation */
- float empty_threshold; /**< Empty Threshold */
- uint32_t percentage; /**< Percentage value */
- knob_state_t frag_state; /**< The current state of fragmentation. */
- knob_state_t foot_state; /**< The current state of footprint. */
- } dmmknobs_t;
- #endif /* WITH_KNOBS */
- /** A structure to store heap information. */
- typedef struct heap_s {
- #ifdef WITH_FIXED_LISTS
- maptable_node_t *maptable_head; /**< The head of the maptable list. */
- #endif /* WITH_FIXED_LISTS */
- void *free_list_head; /**< The head of the free list. */
- #ifdef FUTURE_FEATURES
- void *used_blocks_head; /**< The head of the used blocks list. */
- void *rov_ptr; /**< Roving pointer. */
- #endif /* FUTURE_FEATURES */
- #ifndef LEON3
- uint64_t num_objects; /**< Number of objects in the heap. */
- #else
- unsigned long num_objects; /**< Number of objects in the heap. */
- #endif /* LEON3 */
- #ifdef WITH_STATS
- dmmstats_t dmm_stats; /**< Statistics of the heap. */
- #endif /* WITH_STATS */
- #ifdef WITH_KNOBS
- dmmknobs_t dmm_knobs; /**< Tunable parameters of the heap. */
- #endif /* WITH_KNOBS */
- #ifdef HAVE_LOCKS
- pthread_mutex_t mutex;/**< Mutex when POSIX Threads are used. */
- #endif /* HAVE_LOCKS */
- } heap_t;
- /** The allocator structure of dmmlib. */
- typedef struct allocator_s {
- heap_t heaps[NUM_HEAPS]; /**< The heaps that the allocator manages. */
- bool initialized; /**< Initialization flag of the allocator. */
- void *border_ptr; /**< Border pointer of the allocator. */
- size_t remaining_size; /**< The size of the remaining free space which
- is handled by the allocator. */
- #ifdef ALLOC_VAR_FIT
- /** Current search policy on the allocator's free lists. */
- void *(*search_policy)(heap_t * heap, size_t requested_size);
- #endif /* ALLOC_VAR_FIT */
- } allocator_t;
- #endif /* HEAP_H */
|