GitLab maintenance scheduled for Tomorrow, 2020-08-11, from 17:00 to 18:00 CT - Services will be unavailable during this time.

Commit b51a996c authored by Swann Perarnau's avatar Swann Perarnau

[refactor] move struct area to main header

We're starting to agree on one main header for all the generic APIs of
building blocks, struct definitions included, and one header per
specific implementation.

Improve the spelling while we're at it.
parent b9b7efcd
......@@ -2,7 +2,6 @@ include_HEADERS=aml.h
include_aml_areadir=$(includedir)/aml/area
include_aml_area_HEADERS = \
aml/area/area.h \
aml/area/linux.h
include_aml_dmadir=$(includedir)/aml/dma
......
......@@ -63,12 +63,54 @@ int aml_finalize(void);
* This abstraction is meant to be implemented for several kind of devices,
* i.e the same function calls allocate different kinds of devices depending
* on the area implementation provided.
* List of aml area implementations each may provide additional functionnalities:
* List of aml area implementations each may provide additional functionalities:
* - <aml/area/linux.h>
**/
/* Implementation details of area building block */
#include "aml/area/area.h"
/* Opaque handle to areas data. Defined by implementations */
struct aml_area_data;
/** Implementation specific operations. **/
struct aml_area_ops {
/**
* Coarse grain allocator of virtual memory.
*
* "area_data": Opaque handle to implementation specific data.
* "ptr": A virtual address to be used by underlying implementation.
* Can be NULL.
* "size": The minimum size of allocation.
* Is greater than 0. Must not fail unless not enough
* memory is available, or ptr argument does not point to a
* suitable address.
* In case of failure, aml_errno must be set to an appropriate
* value.
*
* Returns a pointer to allocated memory object.
**/
void* (*mmap)(const struct aml_area_data *area_data,
void *ptr,
size_t size);
/**
* Unmapping of virtual memory mapped with map().
*
* "area_data": An opaque handle to implementation specific data.
* "ptr": Pointer to data mapped in physical memory. Cannot be NULL.
* "size": The size of data. Cannot be 0.
*
* Returns AML_AREA_* error code.
**/
int (*munmap)(const struct aml_area_data *area_data,
void *ptr,
size_t size);
};
struct aml_area {
/* Basic memory operations implementation */
struct aml_area_ops *ops;
/* Implementation specific data. Set to NULL at creation. */
struct aml_area_data *data;
};
/**
* Returns virtual memory from this area with at least queried size bytes.
......@@ -84,7 +126,7 @@ aml_area_mmap(const struct aml_area *area,
/**
* Release data provided with aml_area_mmap() and the same area.
* "area": A valid area implementing access to target memory.
* "ptr": A pointer to memory address provided with aml_area_mmap()
* "ptr": A pointer to memory address provided with aml_area_mmap()
* by same area and size.
**/
int
......
/*******************************************************************************
* 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
*******************************************************************************/
#ifndef AML_AREA_H
#define AML_AREA_H
#include <aml/utils/bitmap.h>
/******************************************************************************
* Lower level area management.
* Implementations list:
* - <aml/area/*.h>
* - <aml/area/linux.h>
******************************************************************************/
/* Opaque handle to areas data. Defined by implementations */
struct aml_area_data;
/** Implementation specific operations. **/
struct aml_area_ops {
/**
* Coarse grain allocator of virtual memory.
*
* "area_data": Opaque handle to implementation specific data.
* "ptr": A virtual address to be used by nderlying implementation. Can be NULL.
* "size": The minimum size of allocation.
* Is greater than 0. Must not fail unless not enough
* memory is available, or ptr argument does not point to a suitable address.
* In case of failure, aml_errno must be set to an appropriate value.
*
* Returns a pointer to allocated memory object.
**/
void* (*mmap)(const struct aml_area_data *area_data,
void *ptr,
size_t size);
/**
* Unmapping of virtual memory mapped with map().
*
* "area_data": An opaque handle to implementation specific data.
* "ptr": Pointer to data mapped in physical memory. Cannot be NULL.
* "size": The size of data. Cannot be 0.
*
* Returns AML_AREA_* error code.
**/
int (*munmap)(const struct aml_area_data *area_data,
void *ptr,
size_t size);
};
struct aml_area {
/* Basic memory operations implementation */
struct aml_area_ops *ops;
/* Implmentation specific data. Set to NULL at creation. */
struct aml_area_data *data;
};
#endif //AML_AREA_H
......@@ -24,7 +24,9 @@
#define AML_AREA_LINUX_MMAP_FLAG_PRIVATE (MAP_PRIVATE | MAP_ANONYMOUS)
#define AML_AREA_LINUX_MMAP_FLAG_SHARED (MAP_SHARED | MAP_ANONYMOUS)
/** User data stored inside area **/
extern struct aml_area_ops aml_area_linux_ops;
/* User data stored inside area */
struct aml_area_linux_data {
/** numanodes to use **/
struct bitmask *nodeset;
......@@ -34,6 +36,21 @@ struct aml_area_linux_data {
int mmap_flags;
};
/* Default linux area with private mapping and no binding. */
extern const struct aml_area aml_area_linux;
#define AML_AREA_LINUX_DECL(name) \
struct aml_area_linux_data __ ##name## _inner_data; \
struct aml_area name = { \
&aml_area_linux_ops, \
(struct aml_area_data *)&__ ## name ## _inner_data, \
}
#define AML_AREA_LINUX_ALLOCSIZE \
(sizeof(struct aml_area_linux_data) + \
sizeof(struct aml_area))
/**
* Initialize area data with struct aml_area_linux_binding. Subsequent calls to
* aml_area_mmap() with this returned area will apply binding settings.
......@@ -90,14 +107,8 @@ aml_area_linux_mmap(const struct aml_area_data *area_data,
* error investigations.
**/
int
aml_area_linux_munmap(const struct aml_area_data *area_data,
void *ptr,
const size_t size);
/** linux area hooks. mmap hook will also bind data unlike header mmap hook. **/
extern struct aml_area_ops aml_area_linux_ops;
/** Default linux area with private mapping and no binding. **/
extern const struct aml_area aml_area_linux;
aml_area_linux_munmap(const struct aml_area_data* area_data,
void *ptr,
const size_t size);
#endif //AML_AREA_LINUX_NUMA_H
#endif //AML_AREA_LINUX_NUMA_H
......@@ -11,7 +11,6 @@
#include <errno.h>
#include "aml.h"
#include "aml/area/area.h"
#include "aml/area/linux.h"
#define AML_AREA_LINUX_MBIND_FLAGS MPOL_MF_MOVE
......
......@@ -8,7 +8,6 @@
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#include "aml.h"
#include "aml/area/area.h"
#include "aml/area/linux.h"
#include <assert.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment