1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/include/villas/node/memory.hpp

77 lines
1.6 KiB
C++
Raw Normal View History

2016-09-19 20:58:41 -04:00
/** Memory allocators.
2016-09-15 21:25:32 -04:00
*
2016-09-19 20:58:41 -04:00
* @file
* @author Steffen Vogel <post@steffenvogel.de>
2022-03-15 09:28:57 -04:00
* @copyright 2014-2022, Institute for Automation of Complex Power Systems, EONERC
2022-07-04 18:20:03 +02:00
* @license Apache 2.0
*********************************************************************************/
2016-09-15 21:25:32 -04:00
2018-06-29 08:37:14 +02:00
#pragma once
#ifdef IBVERBS_FOUND
#include <infiniband/verbs.h>
#endif /* IBVERBS_FOUND */
#include <cstddef>
#include <cstdint>
2016-09-19 20:58:41 -04:00
#include <villas/node/config.hpp>
#include <villas/node/memory_type.hpp>
2018-07-02 14:17:50 +02:00
namespace villas {
namespace node {
namespace memory {
2016-09-15 21:25:32 -04:00
/** Descriptor of a memory block. Associated block always starts at
* &m + sizeof(struct Block). */
struct Block {
struct Block *prev;
struct Block *next;
size_t length; /**< Length of the block; doesn't include the descriptor itself */
bool used;
2016-09-15 21:25:32 -04:00
};
/** @todo Unused for now */
struct Allocation {
struct Type *type;
struct Allocation *parent;
void *address;
size_t alignment;
size_t length;
union {
#ifdef IBVERBS_FOUND
struct {
struct ibv_mr *mr;
} ib;
#endif
struct {
struct Block *block;
} managed;
};
2016-09-15 21:25:32 -04:00
};
/** Initilialize memory subsystem */
int init(int hugepages) __attribute__ ((warn_unused_result));
int lock(size_t lock);
/** Allocate \p len bytes memory of type \p m.
*
2019-06-23 16:58:28 +02:00
* @retval nullptr If allocation failed.
* @retval <>0 If allocation was successful.
*/
void * alloc(size_t len, struct Type *m = default_type);
void * alloc_aligned(size_t len, size_t alignment, struct Type *m = default_type);
2016-09-19 20:58:41 -04:00
int free(void *ptr);
2016-09-15 21:25:32 -04:00
struct Allocation * get_allocation(void *ptr);
} // namespace memory
} // namespace node
} // namespace villas