Commit f8c0ce7d authored by Swann Perarnau's avatar Swann Perarnau

[refactor] remove now useless binding abstraction

Since we removed `move` from the dma API, bindings are now useless.
parent e04522e9
Pipeline #6776 passed with stage
in 9 minutes and 43 seconds
......@@ -78,7 +78,6 @@ void *th_work(void *arg)
}
int main(int argc, char *argv[])
{
AML_BINDING_SINGLE_DECL(binding);
AML_ARENA_JEMALLOC_DECL(arena);
AML_DMA_LINUX_SEQ_DECL(dma);
struct bitmask *slowb, *fastb;
......@@ -101,7 +100,6 @@ int main(int argc, char *argv[])
}
/* initialize all the supporting struct */
assert(!aml_binding_init(&binding, AML_BINDING_TYPE_SINGLE, 0));
assert(!aml_tiling_init(&tiling, AML_TILING_TYPE_1D, tilesz, memsize));
assert(!aml_arena_jemalloc_init(&arena, AML_ARENA_JEMALLOC_TYPE_REGULAR));
......@@ -159,7 +157,6 @@ int main(int argc, char *argv[])
aml_area_linux_destroy(&slow);
aml_area_linux_destroy(&fast);
aml_tiling_destroy(&tiling, AML_TILING_TYPE_1D);
aml_binding_destroy(&binding, AML_BINDING_TYPE_SINGLE);
aml_finalize();
return 0;
}
......@@ -83,7 +83,6 @@ AC_CONFIG_FILES([Makefile
src/area/Makefile
src/dma/Makefile
src/tiling/Makefile
src/binding/Makefile
src/scratch/Makefile
src/arena/Makefile
src/utils/Makefile
......
......@@ -23,8 +23,7 @@
#include <sys/mman.h>
#include <unistd.h>
/* Used by bindings, specifically in aml_binding_nbpages() and
* aml_binding_pages(). */
/* Used by mbind */
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif
......@@ -56,7 +55,6 @@ int aml_finalize(void);
******************************************************************************/
struct aml_area;
struct aml_binding;
/*******************************************************************************
* Arenas:
......@@ -221,8 +219,6 @@ struct aml_area_ops {
void (*release)(struct aml_area_data *area, void *ptr);
void *(*mmap)(struct aml_area_data *area, void *ptr, size_t size);
int (*available)(const struct aml_area_data *area);
int (*binding)(const struct aml_area_data *area,
struct aml_binding **binding);
};
struct aml_area {
......@@ -319,8 +315,6 @@ struct aml_area_linux_mbind_ops {
int (*pre_bind)(struct aml_area_linux_mbind_data *data);
int (*post_bind)(struct aml_area_linux_mbind_data *data, void *ptr,
size_t size);
int (*binding)(const struct aml_area_linux_mbind_data *data,
struct aml_binding **binding);
};
/*
......@@ -331,16 +325,6 @@ struct aml_area_linux_mbind_ops {
*/
int aml_area_linux_mbind_setdata(struct aml_area_linux_mbind_data *data,
int policy, const struct aml_bitmap *nodemask);
/*
* Creates a new binding structure based on an existing Linux memory policy
* structure.
* "data": an initialized Linux memory policy structure.
* "binding": an address where the pointer to the newly allocated binding
* structure will be stored.
* Returns 0 if successful; an error code otherwise.
*/
int aml_area_linux_mbind_generic_binding(const struct aml_area_linux_mbind_data *data,
struct aml_binding **binding);
/*
* Sets current memory policy before memory allocation using the Linux memory
* area.
......@@ -655,14 +639,6 @@ void aml_area_release(struct aml_area *area, void *ptr);
void *aml_area_mmap(struct aml_area *area, void *ptr, size_t size);
/* FIXME! */
int aml_area_available(const struct aml_area *area);
/*
* Creates a new binding structure based on an existing Linux memory area.
* "area": an initialized memory area structure.
* "binding": an address where the pointer to the newly allocated binding
* structure will be stored.
* Returns 0 if successful; an error code otherwise.
*/
int aml_area_binding(const struct aml_area *area, struct aml_binding **binding);
/*******************************************************************************
* Tiling:
......@@ -948,164 +924,6 @@ struct aml_tiling_iterator_2d_data {
(sizeof(struct aml_tiling_iterator_2d_data) + \
sizeof(struct aml_tiling_iterator))
/*******************************************************************************
* Binding:
* Representation of page bindings in an area
******************************************************************************/
/* opaque handle to all bindings */
struct aml_binding_data;
struct aml_binding_ops {
int (*nbpages)(const struct aml_binding_data *binding,
const struct aml_tiling *tiling, const void *ptr,
int tileid);
int (*pages)(const struct aml_binding_data *binding, void **pages,
const struct aml_tiling *tiling, const void *ptr,
int tileid);
int (*nodes)(const struct aml_binding_data *binding, int *nodes,
const struct aml_tiling *tiling, const void *ptr,
int tileid);
};
struct aml_binding {
struct aml_binding_ops *ops;
struct aml_binding_data *data;
};
/*
* Provides the size of a tile in memory, in pages.
* "binding": an initialized binding structure.
* "tiling": an initialized tiling structure.
* "ptr", "tileid": see aml_tiling_tilestart().
* Returns the total number of pages that a tile occupies, including partial
* pages.
*/
int aml_binding_nbpages(const struct aml_binding *binding,
const struct aml_tiling *tiling,
const void *ptr, int tileid);
/*
* Provides the addresses of pages that a tile occupies.
* "binding": an initialized binding structure.
* "pages": an array that will be filled with start addresses of all pages
* that a tile occupies. The array must be at least
* aml_binding_nbpages() elements long.
* "tiling": an initialized tiling structure.
* "ptr", "tileid": see aml_tiling_tilestart().
* Returns 0 if successful; an error code otherwise.
*/
int aml_binding_pages(const struct aml_binding *binding, void **pages,
const struct aml_tiling *tiling, const void *ptr,
int tileid);
/*
* Provides the NUMA node information of pages that a tile occupies.
* "binding": an initialized binding structure.
* "nodes": an array that will be filled with NUMA node id's of all pages
* that a tile occupies. The array must be at least
* aml_binding_nbpages() elements long.
* "tiling": an initialized tiling structure.
* "ptr", "tileid": see aml_tiling_tilestart().
* Returns 0 if successful; an error code otherwise.
*/
int aml_binding_nodes(const struct aml_binding *binding, int *nodes,
const struct aml_tiling *tiling, const void *ptr,
int tileid);
/* Binding types passed to the binding create()/init()/vinit() routines. */
/* Binding where all pages are bound to the same NUMA node. */
#define AML_BINDING_TYPE_SINGLE 0
/* Binding where pages are interleaved among multiple NUMA nodes. */
#define AML_BINDING_TYPE_INTERLEAVE 1
/*
* Allocates and initializes a new binding.
* "binding": an address where the pointer to the newly allocated binding
* structure will be stored.
* "type": see AML_BINDING_TYPE_*.
* Variadic arguments:
* - if "type" equals AML_BINDING_TYPE_SINGLE, one additional argument is
* needed:
* - "node": an argument of type int; provides a NUMA node id where pages
* will be allocated from.
* - if "type" equals AML_BINDING_TYPE_INTERLEAVE, one additional argument is
* needed:
* - "mask": an argument of type const struct aml_bitmap*; storing a bitmask of
* NUMA node ids where pages will be allocated from. See
* aml_bitmap for more information.
* Returns 0 if successful; an error code otherwise.
*/
int aml_binding_create(struct aml_binding **binding, int type, ...);
/*
* Initializes a new binding. This is a varags-variant of the
* aml_binding_vinit() routine.
* "binding": an allocated binding structure.
* "type": see aml_binding_create().
* Variadic arguments: see aml_binding_create().
* Returns 0 if successful; an error code otherwise.
*/
int aml_binding_init(struct aml_binding *binding, int type, ...);
/*
* Initializes a new binding.
* "binding": an allocated binding structure.
* "type": see aml_binding_create().
* "args": see the variadic arguments of aml_binding_create().
* Returns 0 if successful; an error code otherwise.
*/
int aml_binding_vinit(struct aml_binding *binding, int type, va_list args);
/*
* Tears down an initialized binding.
* "binding": an initialized binding structure.
* "type": see aml_binding_create().
* Returns 0 if successful; an error code otherwise.
*/
int aml_binding_destroy(struct aml_binding *binding, int type);
/*******************************************************************************
* Single Binding:
* All pages on the same node
******************************************************************************/
extern struct aml_binding_ops aml_binding_single_ops;
struct aml_binding_single_data {
int node;
};
#define AML_BINDING_SINGLE_DECL(name) \
struct aml_binding_single_data __ ##name## _inner_data; \
struct aml_binding name = { \
&aml_binding_single_ops, \
(struct aml_binding_data *)&__ ## name ## _inner_data, \
};
#define AML_BINDING_SINGLE_ALLOCSIZE (sizeof(struct aml_binding_single_data) + \
sizeof(struct aml_binding))
/*******************************************************************************
* Interleave Binding:
* 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 {
int nodes[AML_MAX_NUMA_NODES];
int count;
};
#define AML_BINDING_INTERLEAVE_DECL(name) \
struct aml_binding_interleave_data __ ##name## _inner_data; \
struct aml_binding name = { \
&aml_binding_interleave_ops, \
(struct aml_binding_data *)&__ ## name ## _inner_data, \
};
#define AML_BINDING_INTERLEAVE_ALLOCSIZE \
(sizeof(struct aml_binding_interleave_data) + \
sizeof(struct aml_binding))
/*******************************************************************************
* DMA:
* Management of low-level movement of memory.
......
......@@ -20,9 +20,6 @@ libaml_la_LIBADD+=$(top_srcdir)/src/dma/libamldma.la
SUBDIRS+=tiling
libaml_la_LIBADD+=$(top_srcdir)/src/tiling/libamltiling.la
SUBDIRS+=binding
libaml_la_LIBADD+=$(top_srcdir)/src/binding/libamlbinding.la
SUBDIRS+=scratch
libaml_la_LIBADD+=$(top_srcdir)/src/scratch/libamlscratch.la
......
......@@ -70,9 +70,3 @@ int aml_area_available(const struct aml_area *area)
assert(area != NULL);
return area->ops->available(area->data);
}
int aml_area_binding(const struct aml_area *area, struct aml_binding **binding)
{
assert(area != NULL);
return area->ops->binding(area->data, binding);
}
......@@ -34,13 +34,6 @@ int aml_area_linux_available(const struct aml_area_data *a)
return 1;
}
int aml_area_linux_binding(const struct aml_area_data *a, struct aml_binding **b)
{
assert(a != NULL);
const struct aml_area_linux *area = (const struct aml_area_linux *)a;
return area->ops.mbind.binding(&area->data.mbind, b);
}
/*******************************************************************************
* Public API:
* The actual functions that will be called on the area from users
......@@ -156,7 +149,6 @@ struct aml_area_ops aml_area_linux_ops = {
aml_area_linux_release,
aml_area_linux_mmap,
aml_area_linux_available,
aml_area_linux_binding,
};
/*******************************************************************************
......
......@@ -18,30 +18,6 @@
* Only handles the actual mbind/mempolicy calls
******************************************************************************/
/* common to both methods */
int aml_area_linux_mbind_generic_binding(const struct aml_area_linux_mbind_data *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_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,
nodemask);
}
return 0;
}
int aml_area_linux_mbind_regular_pre_bind(struct aml_area_linux_mbind_data *data)
{
assert(data != NULL);
......@@ -61,7 +37,6 @@ int aml_area_linux_mbind_regular_post_bind(struct aml_area_linux_mbind_data *dat
struct aml_area_linux_mbind_ops aml_area_linux_mbind_regular_ops = {
aml_area_linux_mbind_regular_pre_bind,
aml_area_linux_mbind_regular_post_bind,
aml_area_linux_mbind_generic_binding,
};
int aml_area_linux_mbind_setdata(struct aml_area_linux_mbind_data *data,
......@@ -111,7 +86,6 @@ int aml_area_linux_mbind_mempolicy_post_bind(struct aml_area_linux_mbind_data *d
struct aml_area_linux_mbind_ops aml_area_linux_mbind_mempolicy_ops = {
aml_area_linux_mbind_mempolicy_pre_bind,
aml_area_linux_mbind_mempolicy_post_bind,
aml_area_linux_mbind_generic_binding,
};
int aml_area_linux_mbind_init(struct aml_area_linux_mbind_data *data,
......
......@@ -33,16 +33,6 @@ int aml_area_posix_available(const struct aml_area_data *data)
return 1;
}
/* same thing here, it makes no sense to ask for this area to provide its
* binding scheme, as no-one should migrate to this area.
*/
int aml_area_posix_binding(const struct aml_area_data *data, struct aml_binding **b)
{
assert(data != NULL);
/* numa node 0 should always be available */
return aml_binding_create(b, AML_BINDING_TYPE_SINGLE, 0);
}
/*******************************************************************************
* Public API:
* The actual functions that will be called on the area from users
......@@ -102,7 +92,6 @@ struct aml_area_ops aml_area_posix_ops = {
aml_area_posix_release,
aml_area_posix_mmap,
aml_area_posix_available,
aml_area_posix_binding,
};
/*******************************************************************************
......
AM_CFLAGS=-I$(top_srcdir)/include
AM_CPPFLAGS=$(AM_CFLAGS)
noinst_LTLIBRARIES=libamlbinding.la
libamlbinding_la_SOURCES=\
binding.c \
binding_single.c \
binding_interleave.c
libamlbinding_la_CFLAGS=$(AM_CFLAGS)
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#include "aml.h"
#include <assert.h>
/*******************************************************************************
* Binding functions
* Most of the stuff is dispatched to a different layer, using type-specific
* functions.
******************************************************************************/
int aml_binding_nbpages(const struct aml_binding *binding,
const struct aml_tiling *tiling, const void *ptr, int tileid)
{
assert(binding != NULL);
assert(tiling != NULL);
return binding->ops->nbpages(binding->data, tiling, ptr, tileid);
}
int aml_binding_pages(const struct aml_binding *binding, void **pages,
const struct aml_tiling *tiling, const void *ptr, int tileid)
{
assert(binding != NULL);
assert(pages != NULL);
assert(tiling != NULL);
return binding->ops->pages(binding->data, pages, tiling, ptr, tileid);
}
int aml_binding_nodes(const struct aml_binding *binding, int *nodes,
const struct aml_tiling *tiling, const void *ptr, int tileid)
{
assert(binding != NULL);
assert(nodes != NULL);
assert(tiling != NULL);
return binding->ops->nodes(binding->data, nodes, tiling, ptr, tileid);
}
/*******************************************************************************
* Init functions
******************************************************************************/
/* allocate and init the binding according to type */
int aml_binding_create(struct aml_binding **b, int type, ...)
{
va_list ap;
va_start(ap, type);
struct aml_binding *ret = NULL;
intptr_t baseptr, dataptr;
if(type == AML_BINDING_TYPE_SINGLE)
{
/* alloc */
baseptr = (intptr_t) calloc(1, AML_BINDING_SINGLE_ALLOCSIZE);
dataptr = baseptr + sizeof(struct aml_binding);
ret = (struct aml_binding *)baseptr;
ret->data = (struct aml_binding_data *)dataptr;
aml_binding_vinit(ret, type, ap);
}
else if(type == AML_BINDING_TYPE_INTERLEAVE)
{
/* alloc */
baseptr = (intptr_t) calloc(1, AML_BINDING_INTERLEAVE_ALLOCSIZE);
dataptr = baseptr + sizeof(struct aml_binding);
ret = (struct aml_binding *)baseptr;
ret->data = (struct aml_binding_data *)dataptr;
aml_binding_vinit(ret, type, ap);
}
va_end(ap);
*b = ret;
return 0;
}
int aml_binding_vinit(struct aml_binding *b, int type, va_list ap)
{
if(type == AML_BINDING_TYPE_SINGLE)
{
b->ops = &aml_binding_single_ops;
struct aml_binding_single_data *data =
(struct aml_binding_single_data *)b->data;
data->node = va_arg(ap, int);
}
else if(type == AML_BINDING_TYPE_INTERLEAVE)
{
b->ops = &aml_binding_interleave_ops;
struct aml_binding_interleave_data *data =
(struct aml_binding_interleave_data *)b->data;
/* receive a nodemask, transform into a list of nodes */
struct aml_bitmap *mask = va_arg(ap, struct aml_bitmap *);
data->count = 0;
for(int i = 0; i < AML_BITMAP_MAX; i++)
if(aml_bitmap_isset(mask, i))
{
data->nodes[data->count] = i;
data->count++;
}
}
return 0;
}
int aml_binding_init(struct aml_binding *b, int type, ...)
{
int err;
va_list ap;
va_start(ap, type);
err = aml_binding_vinit(b, type, ap);
va_end(ap);
return err;
}
int aml_binding_destroy(struct aml_binding *b, int type)
{
return 0;
}
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#include "aml.h"
#include <assert.h>
/*******************************************************************************
* interleave Binding
* Pages interleaved across all nodes
******************************************************************************/
int aml_binding_interleave_getinfo(const struct aml_binding_data *data,
intptr_t *start, intptr_t *end,
const struct aml_tiling *tiling, const void *ptr,
int tileid)
{
assert(data != NULL);
assert(tiling != NULL);
size_t size = aml_tiling_tilesize(tiling, tileid);
*start = (intptr_t) aml_tiling_tilestart(tiling, ptr, tileid);
*end = *start + size;
/* include first and last pages */
*start -= *start % PAGE_SIZE;
*end += (PAGE_SIZE - (*end % PAGE_SIZE)) % PAGE_SIZE;
return (*end - *start) / PAGE_SIZE;
}
int aml_binding_interleave_nbpages(const struct aml_binding_data *data,
const struct aml_tiling *tiling, const void *ptr,
int tileid)
{
assert(data != NULL);
assert(tiling != NULL);
intptr_t start, end;
return aml_binding_interleave_getinfo(data, &start, &end, tiling, ptr, tileid);
}
int aml_binding_interleave_pages(const struct aml_binding_data *data, void **pages,
const struct aml_tiling *tiling, const void *ptr,
int tileid)
{
assert(data != NULL);
assert(pages != NULL);
assert(tiling != NULL);
intptr_t start, end;
int i, count;
count = aml_binding_interleave_getinfo(data, &start, &end, tiling, ptr, tileid);
for(i = 0; i < count; i++)
pages[i] = (void *)(start + i * PAGE_SIZE);
return 0;
}
int aml_binding_interleave_nodes(const struct aml_binding_data *data, int *nodes,
const struct aml_tiling *tiling, const void *ptr,
int tileid)
{
assert(data != NULL);
assert(nodes != NULL);
assert(tiling != NULL);
struct aml_binding_interleave_data *binding =
(struct aml_binding_interleave_data *)data;
intptr_t start, end;
int i, count;
count = aml_binding_interleave_getinfo(data, &start, &end, tiling, ptr, tileid);
for(i = 0; i < count; i++)
nodes[i] = binding->nodes[i%binding->count];
return 0;
}
struct aml_binding_ops aml_binding_interleave_ops = {
aml_binding_interleave_nbpages,
aml_binding_interleave_pages,
aml_binding_interleave_nodes,
};
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#include "aml.h"
#include <assert.h>
/*******************************************************************************
* Single Binding
* All pages on the same node
******************************************************************************/
int aml_binding_single_getinfo(const struct aml_binding_data *data,
intptr_t *start, intptr_t *end,
const struct aml_tiling *tiling, const void *ptr,
int tileid)
{
assert(data != NULL);
assert(tiling != NULL);
size_t size = aml_tiling_tilesize(tiling, tileid);
*start = (intptr_t) aml_tiling_tilestart(tiling, ptr, tileid);
*end = *start + size;
/* include first and last pages */
*start -= *start % PAGE_SIZE;
*end += (PAGE_SIZE - (*end % PAGE_SIZE)) % PAGE_SIZE;
return (*end - *start) / PAGE_SIZE;
}
int aml_binding_single_nbpages(const struct aml_binding_data *data,
const struct aml_tiling *tiling, const void *ptr,
int tileid)
{
assert(data != NULL);
assert(tiling != NULL);
intptr_t start, end;
return aml_binding_single_getinfo(data, &start, &end, tiling, ptr, tileid);
}
int aml_binding_single_pages(const struct aml_binding_data *data, void **pages,
const struct aml_tiling *tiling, const void *ptr,
int tileid)
{
assert(data != NULL);
assert(pages != NULL);
assert(tiling != NULL);
intptr_t start, end;
int i, count;
count = aml_binding_single_getinfo(data, &start, &end, tiling, ptr, tileid);
for(i = 0; i < count; i++)
pages[i] = (void *)(start + i * PAGE_SIZE);
return 0;
}
int aml_binding_single_nodes(const struct aml_binding_data *data, int *nodes,
const struct aml_tiling *tiling, const void *ptr,
int tileid)
{
assert(data != NULL);
assert(nodes != NULL);
assert(tiling != NULL);
struct aml_binding_single_data *binding =
(struct aml_binding_single_data *)data;
intptr_t start, end;
int i, count;
count = aml_binding_single_getinfo(data, &start, &end, tiling, ptr,
tileid);
for(i = 0; i < count; i++)
nodes[i] = binding->node;
return 0;
}
struct aml_binding_ops aml_binding_single_ops = {
aml_binding_single_nbpages,
aml_binding_single_pages,
aml_binding_single_nodes,
};
......@@ -25,8 +25,6 @@ AREA_POSIX_TESTS = area/test_posix
TILING_TESTS = tiling/test_tiling \
tiling/test_tiling_2d
BINDING_TESTS = binding/test_binding
DMA_LINUX_TESTS = dma/test_dma_linux_seq \
dma/test_dma_linux_par
......
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#include "aml.h"
#include <assert.h>
#define TILESIZE (2)
#define NBTILES (4)
int main(int argc, char *argv[])
{
struct aml_binding *a;
AML_BINDING_SINGLE_DECL(b);
AML_TILING_1D_DECL(t);
void *ptr;
/* library initialization */
aml_init(&argc, &argv);