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>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @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-05-05 19:24:16 +00:00
|
|
|
*
|
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-05-05 19:24:16 +00:00
|
|
|
*
|
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/>.
|
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
|
|
|
|
|
2016-09-19 20:58:41 -04:00
|
|
|
#include <stddef.h>
|
2016-10-30 18:39:22 -04:00
|
|
|
#include <stdint.h>
|
2018-07-02 19:00:55 +02:00
|
|
|
#include <stdbool.h>
|
2016-09-19 20:58:41 -04:00
|
|
|
|
2018-07-04 17:50:26 +02:00
|
|
|
#include <villas/config.h>
|
2018-07-02 14:17:50 +02:00
|
|
|
#include <villas/memory_type.h>
|
|
|
|
|
2018-06-28 13:42:50 +02:00
|
|
|
#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
|
|
|
|
2017-03-29 11:29:53 +02:00
|
|
|
/** Descriptor of a memory block. Associated block always starts at
|
2018-07-02 19:00:55 +02:00
|
|
|
* &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 */
|
2018-07-02 19:00:55 +02:00
|
|
|
struct memory_allocation {
|
|
|
|
struct memory_type *type;
|
|
|
|
|
|
|
|
struct memory_allocation *parent;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2018-07-02 19:00:55 +02:00
|
|
|
void *address;
|
|
|
|
size_t alignment;
|
|
|
|
size_t length;
|
|
|
|
|
|
|
|
union {
|
2018-07-04 17:50:26 +02:00
|
|
|
#ifdef IBVERBS_FOUND
|
2018-07-02 19:00:55 +02:00
|
|
|
struct {
|
|
|
|
struct ibv_mr *mr;
|
|
|
|
} ib;
|
|
|
|
#endif
|
|
|
|
struct {
|
|
|
|
struct memory_block *block;
|
|
|
|
} managed;
|
|
|
|
};
|
2016-09-15 21:25:32 -04:00
|
|
|
};
|
|
|
|
|
2016-11-20 02:45:16 -05:00
|
|
|
/** Initilialize memory subsystem */
|
2017-03-11 23:39:00 -03:00
|
|
|
int memory_init(int hugepages);
|
2016-11-20 02:45:16 -05:00
|
|
|
|
2016-10-30 16:54:39 -04:00
|
|
|
/** 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
|
|
|
|
2018-07-02 19:00:55 +02:00
|
|
|
int memory_free(void *ptr);
|
2018-06-28 13:42:50 +02:00
|
|
|
|
2018-07-04 16:34:38 +02:00
|
|
|
struct memory_allocation * memory_get_allocation(void *ptr);
|
|
|
|
|
2018-06-28 13:42:50 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|