2016-09-19 20:58:41 -04:00
|
|
|
/* Memory allocators.
|
2016-09-15 21:25:32 -04:00
|
|
|
*
|
2022-03-15 09:18:01 -04:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2017-03-03 20:20:13 -04:00
|
|
|
*/
|
2016-09-15 21:25:32 -04:00
|
|
|
|
2018-06-29 08:37:14 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-06-23 16:57:00 +02:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
2016-09-19 20:58:41 -04:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/node/config.hpp>
|
|
|
|
#include <villas/node/memory_type.hpp>
|
2018-07-02 14:17:50 +02:00
|
|
|
|
2023-09-07 14:21:24 +02:00
|
|
|
#ifdef IBVERBS_FOUND
|
|
|
|
#include <infiniband/verbs.h>
|
|
|
|
#endif // IBVERBS_FOUND
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
namespace memory {
|
2016-09-15 21:25:32 -04:00
|
|
|
|
2017-03-29 11:29:53 +02:00
|
|
|
/* Descriptor of a memory block. Associated block always starts at
|
2021-08-10 10:12:48 -04:00
|
|
|
* &m + sizeof(struct Block). */
|
|
|
|
struct Block {
|
2023-09-07 11:46:39 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2023-09-04 18:16:15 +02:00
|
|
|
// TODO: Unused for now
|
2021-08-10 10:12:48 -04:00
|
|
|
struct Allocation {
|
2023-09-07 11:46:39 +02:00
|
|
|
struct Type *type;
|
2018-07-02 19:00:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
struct Allocation *parent;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void *address;
|
|
|
|
size_t alignment;
|
|
|
|
size_t length;
|
2018-07-02 19:00:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
union {
|
2018-07-04 17:50:26 +02:00
|
|
|
#ifdef IBVERBS_FOUND
|
2023-09-07 11:46:39 +02:00
|
|
|
struct {
|
|
|
|
struct ibv_mr *mr;
|
|
|
|
} ib;
|
2018-07-02 19:00:55 +02:00
|
|
|
#endif
|
2023-09-07 11:46:39 +02:00
|
|
|
struct {
|
|
|
|
struct Block *block;
|
|
|
|
} managed;
|
|
|
|
};
|
2016-09-15 21:25:32 -04:00
|
|
|
};
|
|
|
|
|
2023-09-07 14:21:24 +02:00
|
|
|
// Initialize memory subsystem
|
2023-09-07 11:46:39 +02:00
|
|
|
int init(int hugepages) __attribute__((warn_unused_result));
|
2016-11-20 02:45:16 -05:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int lock(size_t lock);
|
2018-12-04 10:46:02 +01:00
|
|
|
|
2016-10-30 16:54:39 -04:00
|
|
|
/* Allocate \p len bytes memory of type \p m.
|
|
|
|
*
|
2019-06-23 16:58:28 +02:00
|
|
|
* @retval nullptr If allocation failed.
|
2016-10-30 16:54:39 -04:00
|
|
|
* @retval <>0 If allocation was successful.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
void *alloc(size_t len, struct Type *m = default_type);
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void *alloc_aligned(size_t len, size_t alignment,
|
|
|
|
struct Type *m = default_type);
|
2016-09-19 20:58:41 -04:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int free(void *ptr);
|
2016-09-15 21:25:32 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
struct Allocation *get_allocation(void *ptr);
|
2018-06-28 13:42:50 +02:00
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace memory
|
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|