Commit 0a807455 authored by Nicolas Denoyelle's avatar Nicolas Denoyelle Committed by Swann Perarnau

[refactor] make bitmasks closer to a real type

While the current bitmask management is heavily inspired by libnuma, it is not
as easy to use has the libnuma API. This patch is an attempt to refactor
to code towards something cleaner.
parent e02e5a22
Pipeline #6716 passed with stage
in 18 minutes and 44 seconds
......@@ -2,5 +2,6 @@ include_HEADERS=aml.h
include_amlutilsdir=$(includedir)/aml/utils
include_amlutils_HEADERS = \
aml/utils/vector.h
aml/utils/vector.h \
aml/utils/bitmap.h
......@@ -29,6 +29,7 @@
#define PAGE_SIZE 4096
#endif
#include <aml/utils/bitmap.h>
#include <aml/utils/vector.h>
......@@ -291,44 +292,8 @@ int aml_area_linux_manager_single_init(struct aml_area_linux_manager_data *data,
*/
int aml_area_linux_manager_single_destroy(struct aml_area_linux_manager_data *data);
/* Size of the bitmask (in bits) passed to aml_area_linux_mbind_init(). */
#define AML_MAX_NUMA_NODES 128
/* Size of the bitmask (in bytes) passed to aml_area_linux_mbind_init(). */
#define AML_NODEMASK_BYTES (AML_MAX_NUMA_NODES/8)
/* Size of the bitmask (in array elements) passed to
aml_area_linux_mbind_init(). */
#define AML_NODEMASK_SZ (AML_NODEMASK_BYTES/sizeof(unsigned long))
#define AML_NODEMASK_NBITS (8*sizeof(unsigned long))
#define AML_NODEMASK_ELT(i) ((i) / AML_NODEMASK_NBITS)
#define AML_NODEMASK_BITMASK(i) ((unsigned long)1 << ((i) % AML_NODEMASK_NBITS))
#define AML_NODEMASK_ISSET(mask, i) \
((mask[AML_NODEMASK_ELT(i)] & AML_NODEMASK_BITMASK(i)) != 0)
/*
* Sets a bit in a nodemask.
* "mask": an array of type "unsigned long", at least AML_NODEMASK_SZ long.
* "i": bit to set, indicating a NUMA node.
*/
#define AML_NODEMASK_SET(mask, i) (mask[AML_NODEMASK_ELT(i)] |= AML_NODEMASK_BITMASK(i))
/*
* Clears a bit in a nodemask.
* "mask": an array of type "unsigned long", at least AML_NODEMASK_SZ long.
* "i": bit to clear, indicating a NUMA node.
*/
#define AML_NODEMASK_CLR(mask, i) (mask[AML_NODEMASK_ELT(i)] &= ~AML_NODEMASK_BITMASK(i))
/*
* Zero-initializes a nodemask.
* "mask": an array of type "unsigned long", at least AML_NODEMASK_SZ long.
*/
#define AML_NODEMASK_ZERO(mask) \
do { \
for(unsigned int __i = 0; __i < AML_NODEMASK_SZ; __i++) \
mask[__i] = 0; \
} while(0)
struct aml_area_linux_mbind_data {
unsigned long nodemask[AML_NODEMASK_SZ];
struct aml_bitmap nodemask;
int policy;
};
......@@ -347,7 +312,7 @@ struct aml_area_linux_mbind_ops {
* Returns 0 if successful; an error code otherwise.
*/
int aml_area_linux_mbind_setdata(struct aml_area_linux_mbind_data *data,
int policy, const unsigned long *nodemask);
int policy, const struct aml_bitmap *nodemask);
/*
* Creates a new binding structure based on an existing Linux memory policy
* structure.
......@@ -410,7 +375,7 @@ int aml_area_linux_mbind_mempolicy_post_bind(struct aml_area_linux_mbind_data *d
* Returns 0 if successful; an error code otherwise.
*/
int aml_area_linux_mbind_init(struct aml_area_linux_mbind_data *data,
int policy, const unsigned long *nodemask);
int policy, const struct aml_bitmap *nodemask);
/*
* Tears down an initialized Linx memory policy.
* "data": an initialized Linux memory policy structure.
......@@ -1046,10 +1011,9 @@ int aml_binding_nodes(const struct aml_binding *binding, int *nodes,
* will be allocated from.
* - if "type" equals AML_BINDING_TYPE_INTERLEAVE, one additional argument is
* needed:
* - "mask": an argument of type const unsigned long*; provides an array
* at least AML_NODEMASK_SZ elements long, storing a bitmask of
* - "mask": an argument of type const struct aml_bitmap*; storing a bitmask of
* NUMA node ids where pages will be allocated from. See
* AML_NODEMASK_* macros for more information.
* aml_bitmap for more information.
* Returns 0 if successful; an error code otherwise.
*/
int aml_binding_create(struct aml_binding **binding, int type, ...);
......@@ -1104,6 +1068,8 @@ struct aml_binding_single_data {
* each page, of each tile, interleaved across nodes.
******************************************************************************/
#define AML_MAX_NUMA_NODES AML_BITMAP_MAX
extern struct aml_binding_ops aml_binding_interleave_ops;
struct aml_binding_interleave_data {
......
#ifndef AML_BITMAP_H
#define AML_BITMAP_H
/*******************************************************************************
* bitmap API:
******************************************************************************/
#define AML_BITMAP_MAX 2048
#define AML_BITMAP_BYTES (AML_BITMAP_MAX/8)
#define AML_BITMAP_TYPE unsigned long
#define AML_BITMAP_SIZE (AML_BITMAP_BYTES/sizeof(AML_BITMAP_TYPE))
struct aml_bitmap {
unsigned long mask[AML_BITMAP_SIZE];
};
/**
* On heap allocation of new empty bitmap.
**/
struct aml_bitmap *aml_bitmap_create(void);
/**
* On heap allocation of a copy of an existing bitmap.
**/
struct aml_bitmap *aml_bitmap_dup(const struct aml_bitmap *src);
/**
* Free on heap allocated bitmap.
**/
void aml_bitmap_destroy(struct aml_bitmap *bitmap);
/**
* Copy bitmap content.
**/
void aml_bitmap_copy(struct aml_bitmap *dst, const struct aml_bitmap *src);
/**
* Empty a bitmap with all bits cleared.
**/
void aml_bitmap_zero(struct aml_bitmap *bitmap);
/**
* Fill a bitmap with all bits set.
**/
void aml_bitmap_fill(struct aml_bitmap *bitmap);
/**
* Check whether a bit in bitmap is set.
* Returns -1 if i is greater than bitmap length,
* 0 if bit is not set else a positive value..
**/
int aml_bitmap_isset(const struct aml_bitmap *bitmap, const unsigned i);
/**
* Check whether a bit in bitmap is empty.
* Returns 1 if yes, else 0.
**/
int aml_bitmap_iszero(const struct aml_bitmap *bitmap);
/**
* Check whether a bit in bitmap is full.
* Returns 1 if yes, else 0.
**/
int aml_bitmap_isfull(const struct aml_bitmap *bitmap);
/**
* Check whether two bitmaps have identical value.
**/
int aml_bitmap_isequal(const struct aml_bitmap *a, const struct aml_bitmap *b);
/**
* Set a bit in bitmap.
* Returns -1 if i is greater than bitmap length, else 0.
**/
int aml_bitmap_set(struct aml_bitmap *bitmap, const unsigned i);
/**
* Clear a bit in bitmap.
* Returns -1 if i is greater than bitmap length, else 0.
**/
int aml_bitmap_clear(struct aml_bitmap *bitmap, const unsigned i);
/**
* Set a range [[i, ii]] of bits in bitmap.
* Returns -1 if i or ii is greater than bitmap length, else 0.
**/
int aml_bitmap_set_range(struct aml_bitmap *bitmap, const unsigned i, const unsigned ii);
/**
* Clear a range [[i, ii]] of bits in bitmap.
* Returns -1 if i or ii is greater than bitmap length, else 0.
**/
int aml_bitmap_clear_range(struct aml_bitmap *bitmap, const unsigned i, const unsigned ii);
/**
* Count the number of bits set in bitmap.
**/
unsigned long aml_bitmap_nset(const struct aml_bitmap *bitmap);
/*
* Copy a unsigned long array used as a bitmap into an actual bitmap.
* Takes the array and its max set bit as input.
*/
void aml_bitmap_copy_ulong(struct aml_bitmap *bitmap, unsigned long *, size_t);
#endif //AML_BITMAP_H
......@@ -23,19 +23,20 @@ int aml_area_linux_mbind_generic_binding(const struct aml_area_linux_mbind_data
struct aml_binding **b)
{
assert(data != NULL);
const struct aml_bitmap *nodemask = &data->nodemask;
/* not exactly proper, we should inspect the nodemask to find the real
* binding policy.
*/
if(data->policy == MPOL_BIND)
{
for(int i = 0; i < AML_MAX_NUMA_NODES; i++)
if(AML_NODEMASK_ISSET(data->nodemask, i))
for(int i = 0; i < AML_BITMAP_MAX; i++)
if(aml_bitmap_isset(nodemask, i))
return aml_binding_create(b, AML_BINDING_TYPE_SINGLE,i);
}
else if(data->policy == MPOL_INTERLEAVE)
{
return aml_binding_create(b, AML_BINDING_TYPE_INTERLEAVE,
data->nodemask);
nodemask);
}
return 0;
}
......@@ -54,7 +55,7 @@ int aml_area_linux_mbind_regular_post_bind(struct aml_area_linux_mbind_data *dat
/* realign ptr to match mbind requirement that it is aligned on a page */
intptr_t aligned = (intptr_t)ptr & (intptr_t)(~(PAGE_SIZE -1));
size_t end = sz + ((intptr_t)ptr - aligned);
return mbind((void*)aligned, sz, data->policy, data->nodemask, AML_MAX_NUMA_NODES, 0);
return mbind((void*)aligned, sz, data->policy, data->nodemask.mask, AML_BITMAP_MAX, 0);
}
struct aml_area_linux_mbind_ops aml_area_linux_mbind_regular_ops = {
......@@ -64,11 +65,11 @@ struct aml_area_linux_mbind_ops aml_area_linux_mbind_regular_ops = {
};
int aml_area_linux_mbind_setdata(struct aml_area_linux_mbind_data *data,
int policy, const unsigned long *nodemask)
int policy, const struct aml_bitmap *nodemask)
{
assert(data != NULL);
data->policy = policy;
memcpy(data->nodemask, nodemask, AML_NODEMASK_BYTES);
aml_bitmap_copy(&data->nodemask, nodemask);
return 0;
}
......@@ -79,11 +80,13 @@ int aml_area_linux_mbind_mempolicy_pre_bind(struct aml_area_linux_mbind_data *da
* our data, and apply the one the user actually want
*/
int policy;
unsigned long nodemask[AML_NODEMASK_SZ];
int err;
get_mempolicy(&policy, nodemask, AML_MAX_NUMA_NODES, NULL, 0);
err = set_mempolicy(data->policy, data->nodemask, AML_MAX_NUMA_NODES);
aml_area_linux_mbind_setdata(data, policy, nodemask);
struct aml_bitmap bitmap;
get_mempolicy(&policy, (unsigned long *)&bitmap.mask,
AML_BITMAP_MAX, NULL, 0);
err = set_mempolicy(data->policy, (unsigned long *)&data->nodemask.mask,
AML_BITMAP_MAX);
aml_area_linux_mbind_setdata(data, policy, &bitmap);
return err;
}
......@@ -95,11 +98,13 @@ int aml_area_linux_mbind_mempolicy_post_bind(struct aml_area_linux_mbind_data *d
* to it, and restore the generic mempolicy we saved earlier.
*/
int policy;
unsigned long nodemask[AML_NODEMASK_SZ];
int err;
get_mempolicy(&policy, nodemask, AML_MAX_NUMA_NODES, NULL, 0);
err = set_mempolicy(data->policy, data->nodemask, AML_MAX_NUMA_NODES);
aml_area_linux_mbind_setdata(data, policy, nodemask);
struct aml_bitmap bitmap;
get_mempolicy(&policy, (unsigned long *)&bitmap.mask,
AML_BITMAP_MAX, NULL, 0);
err = set_mempolicy(data->policy, (unsigned long *)data->nodemask.mask,
AML_BITMAP_MAX);
aml_area_linux_mbind_setdata(data, policy, &bitmap);
return err;
}
......@@ -110,7 +115,7 @@ struct aml_area_linux_mbind_ops aml_area_linux_mbind_mempolicy_ops = {
};
int aml_area_linux_mbind_init(struct aml_area_linux_mbind_data *data,
int policy, const unsigned long *nodemask)
int policy, const struct aml_bitmap *nodemask)
{
assert(data != NULL);
aml_area_linux_mbind_setdata(data, policy, nodemask);
......
......@@ -96,10 +96,10 @@ int aml_binding_vinit(struct aml_binding *b, int type, va_list ap)
struct aml_binding_interleave_data *data =
(struct aml_binding_interleave_data *)b->data;
/* receive a nodemask, transform into a list of nodes */
unsigned long *mask = va_arg(ap, unsigned long*);
struct aml_bitmap *mask = va_arg(ap, struct aml_bitmap *);
data->count = 0;
for(int i = 0; i < AML_MAX_NUMA_NODES; i++)
if(AML_NODEMASK_ISSET(mask, i))
for(int i = 0; i < AML_BITMAP_MAX; i++)
if(aml_bitmap_isset(mask, i))
{
data->nodes[data->count] = i;
data->count++;
......
......@@ -4,7 +4,8 @@ AM_CPPFLAGS=$(AM_CFLAGS)
noinst_LTLIBRARIES=libamlutils.la
libamlutils_la_SOURCES=\
vector.c
vector.c \
bitmap.c
libamlutils_la_CFLAGS=$(AM_CFLAGS)
libamlutils_la_LDFLAGS=
......
#include "aml.h"
#define AML_BITMAP_EMPTY (0UL)
#define AML_BITMAP_FULL (~0UL)
#define AML_BITMAP_NBITS (8 * sizeof(AML_BITMAP_TYPE))
#define AML_BITMAP_NTH(i) ((i) / AML_BITMAP_NBITS)
#define AML_BITMAP_ITH(i) (((i) % AML_BITMAP_NBITS))
struct aml_bitmap *aml_bitmap_alloc(void)
{
struct aml_bitmap *b = malloc(sizeof(struct aml_bitmap));
if(b == NULL)
return NULL;
aml_bitmap_zero(b);
return b;
}
void aml_bitmap_copy(struct aml_bitmap *dst, const struct aml_bitmap *src)
{
if(dst == NULL || src == NULL)
return;
memcpy(dst, src, sizeof(struct aml_bitmap));
}
void aml_bitmap_copy_ulong(struct aml_bitmap *dst, unsigned long *src,
size_t maxbit)
{
if(dst == NULL || src == NULL)
return;
if(maxbit > AML_BITMAP_MAX)
maxbit = AML_BITMAP_MAX;
for(size_t i = 0; i < maxbit; i++)
if(src[AML_BITMAP_NTH(i)] & (1UL << AML_BITMAP_ITH(i)) != 0)
aml_bitmap_set(dst, i);
}
struct aml_bitmap *aml_bitmap_dup(const struct aml_bitmap *a)
{
struct aml_bitmap *b = aml_bitmap_alloc();
if(b == NULL)
return NULL;
aml_bitmap_copy(b, a);
return b;
}
void aml_bitmap_free(struct aml_bitmap *bitmap)
{
free(bitmap);
}
void aml_bitmap_zero(struct aml_bitmap *bitmap)
{
memset(bitmap, 0, sizeof(struct aml_bitmap));
}
int aml_bitmap_iszero(const struct aml_bitmap *bitmap){
int i;
for(i=0; i<AML_BITMAP_SIZE; i++)
if(bitmap->mask[i] != AML_BITMAP_EMPTY)
return 0;
return 1;
}
int aml_bitmap_isfull(const struct aml_bitmap *bitmap)
{
int i;
for(i=0; i<AML_BITMAP_SIZE; i++)
if(bitmap->mask[i] != AML_BITMAP_FULL)
return 0;
return 1;
}
void aml_bitmap_fill(struct aml_bitmap *bitmap){
memset(bitmap, AML_BITMAP_FULL, sizeof(struct aml_bitmap));
}
int aml_bitmap_isset(const struct aml_bitmap *bitmap, const unsigned i)
{
if(i >= AML_BITMAP_MAX)
return -1;
return (bitmap->mask[AML_BITMAP_NTH(i)] &
(1UL << AML_BITMAP_ITH(i))) > 0UL;
}
int aml_bitmap_set(struct aml_bitmap *bitmap, const unsigned i)
{
if(i >= AML_BITMAP_MAX)
return -1;
bitmap->mask[AML_BITMAP_NTH(i)] |= (1UL << AML_BITMAP_ITH(i));
return 0;
}
int aml_bitmap_isequal(const struct aml_bitmap *a, const struct aml_bitmap *b)
{
int i;
for(i = 0; i < AML_BITMAP_SIZE; i++)
if(a->mask[i] != b->mask[i])
return 0;
return 1;
}
int aml_bitmap_clear(struct aml_bitmap *bitmap, const unsigned i)
{
if(i >= AML_BITMAP_MAX)
return -1;
bitmap->mask[AML_BITMAP_NTH(i)] &= ~(1UL << AML_BITMAP_ITH(i));
return 0;
}
int aml_bitmap_set_range(struct aml_bitmap *bitmap,
const unsigned i, const unsigned ii)
{
if(i >= AML_BITMAP_MAX || ii >= AML_BITMAP_MAX || i > ii)
return -1;
if(i == ii)
return aml_bitmap_set(bitmap, i);
unsigned long k = AML_BITMAP_ITH(ii+1);
unsigned long low = (AML_BITMAP_FULL << AML_BITMAP_ITH(i));
unsigned long n = AML_BITMAP_NTH(i);
unsigned long nn = AML_BITMAP_NTH(ii);
unsigned long high = k == 0 ? AML_BITMAP_FULL : ~(AML_BITMAP_FULL << k);
if(nn>n)
{
for(k=n+1; k<=nn-1; k++)
bitmap->mask[k] = AML_BITMAP_FULL;
bitmap->mask[n] |= low;
bitmap->mask[nn] |= high;
}
else
bitmap->mask[n] |= (low & high);
return 0;
}
int aml_bitmap_clear_range(struct aml_bitmap *bitmap,
const unsigned i, const unsigned ii)
{
if(i >= AML_BITMAP_MAX || ii >= AML_BITMAP_MAX || i > ii)
return -1;
if(i == ii)
return aml_bitmap_set(bitmap, i);
unsigned long k = AML_BITMAP_ITH(ii+1);
unsigned long low = ~(AML_BITMAP_FULL << AML_BITMAP_ITH(i));
unsigned long n = AML_BITMAP_NTH(i);
unsigned long nn = AML_BITMAP_NTH(ii);
unsigned long high = k == 0 ? AML_BITMAP_EMPTY : (AML_BITMAP_FULL << k);
if(nn>n)
{
for(k=n+1; k<=nn-1; k++)
bitmap->mask[k] = AML_BITMAP_EMPTY;
bitmap->mask[n] &= low;
bitmap->mask[nn] &= high;
}
else
bitmap->mask[n] &= (low | high);
return 0;
}
unsigned long aml_bitmap_nset(const struct aml_bitmap *bitmap)
{
unsigned long i, b, n;
unsigned long test = 1UL;
unsigned long nset = 0;
;
for(n = 0; n < AML_BITMAP_SIZE; n++){
b = bitmap->mask[n];
for(i = 0; i < AML_BITMAP_NBITS; i++){
nset += b & test ? 1 : 0;
b = b >> 1;
}
}
return nset;
}
......@@ -9,7 +9,8 @@ if TEST_VALGRIND
TESTS_ENVIRONMENT= @LIBTOOL@ --mode=execute @VALGRIND@ --tool=memcheck -q --leak-check=full
endif
UTILS_TESTS = utils/test_vector
UTILS_TESTS = utils/test_vector \
utils/test_bitmap
ARENA_JEMALLOC_TESTS = arena/test_jemalloc
......
......@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
{
AML_ARENA_JEMALLOC_DECL(arena);
AML_AREA_LINUX_DECL(area);
unsigned long nodemask[AML_NODEMASK_SZ];
struct aml_bitmap nodemask;
struct bitmask *allowed;
/* library initialization */
......@@ -79,14 +79,14 @@ int main(int argc, char *argv[])
/* init arguments */
allowed = numa_get_mems_allowed();
memcpy(nodemask, allowed->maskp, AML_NODEMASK_BYTES);
aml_bitmap_copy_ulong(&nodemask, allowed->maskp, numa_max_node());
assert(!aml_arena_jemalloc_init(&arena, AML_ARENA_JEMALLOC_TYPE_REGULAR));
assert(!aml_area_linux_init(&area,
AML_AREA_LINUX_MANAGER_TYPE_SINGLE,
AML_AREA_LINUX_MBIND_TYPE_REGULAR,
AML_AREA_LINUX_MMAP_TYPE_ANONYMOUS,
&arena, MPOL_BIND, nodemask));
&arena, MPOL_BIND, &nodemask));
doit(&area);
......
......@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
AML_ARENA_JEMALLOC_DECL(arena);
AML_AREA_LINUX_DECL(area);
AML_DMA_LINUX_PAR_DECL(dma);
unsigned long nodemask[AML_NODEMASK_SZ];
struct aml_bitmap nodemask;
void *dst, *src;
/* library initialization */
......@@ -31,15 +31,15 @@ int main(int argc, char *argv[])
assert(!aml_binding_init(&binding, AML_BINDING_TYPE_SINGLE, 0));
assert(!aml_tiling_init(&tiling, AML_TILING_TYPE_1D, TILESIZE*PAGE_SIZE,
TILESIZE*PAGE_SIZE*NBTILES));
AML_NODEMASK_ZERO(nodemask);
AML_NODEMASK_SET(nodemask, 0);
aml_bitmap_zero(&nodemask);
aml_bitmap_set(&nodemask, 0);
assert(!aml_arena_jemalloc_init(&arena, AML_ARENA_JEMALLOC_TYPE_REGULAR));
assert(!aml_area_linux_init(&area,
AML_AREA_LINUX_MANAGER_TYPE_SINGLE,
AML_AREA_LINUX_MBIND_TYPE_REGULAR,
AML_AREA_LINUX_MMAP_TYPE_ANONYMOUS,
&arena, MPOL_BIND, nodemask));
&arena, MPOL_BIND, &nodemask));
size_t maxrequests = NBTILES;
size_t maxthreads = 4;
......
......@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
AML_ARENA_JEMALLOC_DECL(arena);
AML_AREA_LINUX_DECL(area);
AML_DMA_LINUX_SEQ_DECL(dma);
unsigned long nodemask[AML_NODEMASK_SZ];
struct aml_bitmap nodemask;
void *dst, *src;
/* library initialization */
......@@ -31,15 +31,15 @@ int main(int argc, char *argv[])
assert(!aml_binding_init(&binding, AML_BINDING_TYPE_SINGLE, 0));
assert(!aml_tiling_init(&tiling, AML_TILING_TYPE_1D, TILESIZE*PAGE_SIZE,
TILESIZE*PAGE_SIZE*NBTILES));
AML_NODEMASK_ZERO(nodemask);
AML_NODEMASK_SET(nodemask, 0);
aml_bitmap_zero(&nodemask);
aml_bitmap_set(&nodemask, 0);
assert(!aml_arena_jemalloc_init(&arena, AML_ARENA_JEMALLOC_TYPE_REGULAR));
assert(!aml_area_linux_init(&area,
AML_AREA_LINUX_MANAGER_TYPE_SINGLE,
AML_AREA_LINUX_MBIND_TYPE_REGULAR,
AML_AREA_LINUX_MMAP_TYPE_ANONYMOUS,
&arena, MPOL_BIND, nodemask));
&arena, MPOL_BIND, &nodemask));
size_t maxrequests = NBTILES;
assert(!aml_dma_linux_seq_init(&dma, maxrequests));
......
......@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
AML_AREA_LINUX_DECL(area);
AML_DMA_LINUX_SEQ_DECL(dma);
AML_SCRATCH_PAR_DECL(scratch);
unsigned long nodemask[AML_NODEMASK_SZ];
struct aml_bitmap nodemask;
void *dst, *src;
/* library initialization */
......@@ -32,15 +32,15 @@ int main(int argc, char *argv[])
assert(!aml_binding_init(&binding, AML_BINDING_TYPE_SINGLE, 0));
assert(!aml_tiling_init(&tiling, AML_TILING_TYPE_1D, TILESIZE*PAGE_SIZE,
TILESIZE*PAGE_SIZE*NBTILES));
AML_NODEMASK_ZERO(nodemask);
AML_NODEMASK_SET(nodemask, 0);
aml_bitmap_zero(&nodemask);
aml_bitmap_set(&nodemask, 0);
assert(!aml_arena_jemalloc_init(&arena, AML_ARENA_JEMALLOC_TYPE_REGULAR));
assert(!aml_area_linux_init(&area,
AML_AREA_LINUX_MANAGER_TYPE_SINGLE,
AML_AREA_LINUX_MBIND_TYPE_REGULAR,
AML_AREA_LINUX_MMAP_TYPE_ANONYMOUS,
&arena, MPOL_BIND, nodemask));
&arena, MPOL_BIND, &nodemask));
size_t maxrequests = NBTILES;
assert(!aml_dma_linux_seq_init(&dma, maxrequests));
......
......@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
AML_AREA_LINUX_DECL(area);
AML_DMA_LINUX_PAR_DECL(dma);
AML_SCRATCH_SEQ_DECL(scratch);
unsigned long nodemask[AML_NODEMASK_SZ];
struct aml_bitmap nodemask;
void *dst, *src;
/* library initialization */
......@@ -32,15 +32,15 @@ int main(int argc, char *argv[])
assert(!aml_binding_init(&binding, AML_BINDING_TYPE_SINGLE, 0));
assert(!aml_tiling_init(&tiling, AML_TILING_TYPE_1D, TILESIZE*PAGE_SIZE,
TILESIZE*PAGE_SIZE*NBTILES));
AML_NODEMASK_ZERO(nodemask);
AML_NODEMASK_SET(nodemask, 0);
aml_bitmap_zero(&nodemask);
aml_bitmap_set(&nodemask, 0);
assert(!aml_arena_jemalloc_init(&arena, AML_ARENA_JEMALLOC_TYPE_REGULAR));
assert(!aml_area_linux_init(&area,
AML_AREA_LINUX_MANAGER_TYPE_SINGLE,
AML_AREA_LINUX_MBIND_TYPE_REGULAR,
AML_AREA_LINUX_MMAP_TYPE_ANONYMOUS,
&arena, MPOL_BIND, nodemask));
&arena, MPOL_BIND, &nodemask));
size_t maxrequests = NBTILES;
size_t maxthreads = 4;
......
#include "aml.h"
#include <assert.h>
void test_bitmap_fill(){
unsigned long i;
struct aml_bitmap b;
aml_bitmap_fill(&b);
for(i = 0; i < AML_BITMAP_MAX; i++)
assert(aml_bitmap_isset(&b, i));
assert(aml_bitmap_nset(&b) == AML_BITMAP_MAX);
}
void test_bitmap_zero(){
unsigned long i;
struct aml_bitmap b;
aml_bitmap_zero(&b);
for(i = 0; i < AML_BITMAP_MAX; i++)
assert(!aml_bitmap_isset(&b, i));
assert(aml_bitmap_nset(&b) == 0);
}
void test_bitmap_set(){
unsigned long i,j;
struct aml_bitmap b;
aml_bitmap_zero(&b);
for(i = 0; i < AML_BITMAP_MAX; i++){
aml_bitmap_set(&b, i);
assert(aml_bitmap_isset(&b, i));
for(j = 0; j < i; j++)
assert(!aml_bitmap_isset(&b, j));
for(j = i+1; j < AML_BITMAP_MAX; j++)
assert(!aml_bitmap_isset(&b, j));
assert(aml_bitmap_nset(&b) == 1);
aml_bitmap_clear(&b, i);
assert(!aml_bitmap_isset(&b, i));
}
}
void test_bitmap_clear(){
unsigned long i,j;
struct aml_bitmap b;
aml_bitmap_fill(&b);
for(i = 0; i < AML_BITMAP_MAX; i++){
aml_bitmap_clear(&b, i);
assert(!aml_bitmap_isset(&b, i));
for(j = 0; j < i; j++)
assert(aml_bitmap_isset(&b, j));
for(j = i+1; j < AML_BITMAP_MAX; j++)
assert(aml_bitmap_isset(&b, j));
assert(aml_bitmap_nset(&b) == (AML_BITMAP_MAX-1));
aml_bitmap_set(&b, i);
assert(aml_bitmap_isset(&b, i));
}
}
void test_bitmap_set_range(){
unsigned long i, ii, j;
struct aml_bitmap b;
aml_bitmap_zero(&b);
for(i = 0; i < AML_BITMAP_MAX; i++){
for(ii = i+1; ii < AML_BITMAP_MAX; ii++){
assert(aml_bitmap_set_range(&b, i, ii) == 0);
assert(aml_bitmap_nset(&b) == (1 + ii - i));
for(j = 0; j < i; j++)
assert(!aml_bitmap_isset(&b, j));
for(j = i; j <= ii; j++)
assert(aml_bitmap_isset(&b, j));
for(j = ii+1; j < AML_BITMAP_MAX; j++)
assert(!aml_bitmap_isset(&b, j));
aml_bitmap_zero(&b);
}