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

90 lines
2.2 KiB
C
Raw Permalink 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 <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
2017-04-27 12:56:43 +02:00
* @license GNU General Public License (version 3)
*
* VILLASnode
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
2017-04-27 12:56:43 +02:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2017-04-27 12:56:43 +02:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
2016-09-15 21:25:32 -04:00
2018-06-29 08:37:14 +02:00
#pragma once
2016-09-19 20:58:41 -04:00
#include <stddef.h>
2016-10-30 18:39:22 -04:00
#include <stdint.h>
#include <stdbool.h>
2016-09-19 20:58:41 -04:00
#include <villas/config.h>
2018-07-02 14:17:50 +02:00
#include <villas/memory_type.h>
#ifdef __cplusplus
extern "C" {
#endif
2018-07-02 14:17:50 +02:00
/* Forward declarations */
struct node;
2016-09-15 21:25:32 -04:00
/** Descriptor of a memory block. Associated block always starts at
* &m + sizeof(struct memory_block). */
struct memory_block {
struct memory_block *prev;
struct memory_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 memory_allocation {
struct memory_type *type;
struct memory_allocation *parent;
void *address;
size_t alignment;
size_t length;
union {
#ifdef IBVERBS_FOUND
struct {
struct ibv_mr *mr;
} ib;
#endif
struct {
struct memory_block *block;
} managed;
};
2016-09-15 21:25:32 -04:00
};
/** Initilialize memory subsystem */
2017-03-11 23:39:00 -03:00
int memory_init(int hugepages);
/** Allocate \p len bytes memory of type \p m.
*
* @retval NULL If allocation failed.
* @retval <>0 If allocation was successful.
*/
2018-07-02 14:17:50 +02:00
void * memory_alloc(struct memory_type *m, size_t len);
2016-09-19 20:58:41 -04:00
2018-07-02 14:17:50 +02:00
void * memory_alloc_aligned(struct memory_type *m, size_t len, size_t alignment);
2016-09-15 21:25:32 -04:00
int memory_free(void *ptr);
2018-07-04 16:34:38 +02:00
struct memory_allocation * memory_get_allocation(void *ptr);
#ifdef __cplusplus
}
#endif