Arax -8d09c51940345c86062e8ef2427c705ae66e5926
A Runtime Framework for Decoupling Applications from Heterogeneous Accelerators
Loading...
Searching...
No Matches
alloc.h
Go to the documentation of this file.
1#ifndef ARCH_ALLOCATOR_HEADER
2#define ARCH_ALLOCATOR_HEADER
3#include <stddef.h>
4#include "conf.h"
5#include "arax_types.h"
6#include <utils/bitmap.h>
7
8#ifdef __cplusplus
9extern "C" {
10#endif /* ifdef __cplusplus */
11
12typedef void *arch_alloc_state;
13
14/*
15 * TODO:Add canarry
16 */
18{
19 #ifdef ALLOC_STATS
20 size_t allocs[2]; // < Number of arch_alloc_allocate(failed/successfull).
21 size_t frees; // < Number of arch_alloc_free.
22 size_t alloc_ns[2]; // < Cumulative nanoseconds spend in alloc(failed/successful).
23 size_t free_ns; // < Cumulative nanoseconds spend in free.
24 #else
25 // This padd is necessary as empty struct have sizeof == 1 in C++, but 0 in C
26 char padd;
27 #endif
28};
29
40int arch_alloc_init_once(arch_alloc_s *alloc, size_t size);
41
51
60void* arch_alloc_allocate(arch_alloc_s *alloc, size_t size);
61
62void _arch_alloc_free(arch_alloc_s *alloc, void *mem);
63
70#define arch_alloc_free(ALLOC, MEM) \
71 ({ \
72 _arch_alloc_free(ALLOC, MEM); \
73 MEM = 0; \
74 })
75
81void arch_alloc_exit(arch_alloc_s *alloc);
82
83typedef struct
84{
85 size_t total_bytes; // <Bytes available for user data AND allocator metadata.
86 size_t used_bytes; // <Bytes used for user data AND allocator metadata.
87 #ifdef ALLOC_STATS
88 size_t allocs[2]; // < Number of arch_alloc_allocate(failed/successful).
89 size_t frees; // < Number of arch_alloc_free.
90 size_t alloc_ns[2]; // < Cumulative nanoseconds spend in alloc(failed/successful).
91 size_t free_ns; // < Cumulative nanoseconds spend in free.
92 #endif
94
96
97void arch_alloc_inspect(arch_alloc_s *alloc, void (*inspector)(void *start, void *end, size_t size,
98 void *arg), void *arg);
99
105void* arax_mmap(size_t s);
106
113void* arax_ummap(void *a, size_t s);
114
128
130#ifdef __cplusplus
131}
132#endif /* ifdef __cplusplus */
133
134#endif /* ifndef ARCH_ALLOCATOR_HEADER */
void * arax_ummap(void *a, size_t s)
arch_alloc_s * arch_alloc_create_sub_alloc(arch_alloc_s *parent)
int arch_alloc_init_once(arch_alloc_s *alloc, size_t size)
arch_alloc_stats_s arch_alloc_stats(arch_alloc_s *alloc)
utils_bitmap_s * arch_alloc_get_bitmap()
void * arax_mmap(size_t s)
void * arch_alloc_allocate(arch_alloc_s *alloc, size_t size)
void * arch_alloc_state
Definition alloc.h:12
void arch_alloc_init_always(arch_alloc_s *alloc)
void arch_alloc_inspect(arch_alloc_s *alloc, void(*inspector)(void *start, void *end, size_t size, void *arg), void *arg)
void arch_alloc_exit(arch_alloc_s *alloc)
void _arch_alloc_free(arch_alloc_s *alloc, void *mem)
struct utils_bitmap utils_bitmap_s
char padd
Definition alloc.h:26
size_t total_bytes
Definition alloc.h:85
size_t used_bytes
Definition alloc.h:86