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/lib/memory/ib.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
2.1 KiB
C++
Raw Permalink Normal View History

/* Infiniband memory allocator.
2018-06-29 17:37:10 +02:00
*
* Author: Steffen Vogel <post@steffenvogel.de>
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
* SPDX-License-Identifier: Apache-2.0
*/
2018-06-29 17:37:10 +02:00
#include <infiniband/verbs.h>
2018-07-04 17:27:26 +02:00
2021-09-13 14:59:38 +02:00
#include <villas/exceptions.hpp>
#include <villas/memory/ib.h>
#include <villas/node/memory.hpp>
#include <villas/node_compat.hpp>
#include <villas/nodes/infiniband.hpp>
#include <villas/utils.hpp>
2018-06-29 17:37:10 +02:00
2021-09-13 14:59:38 +02:00
using namespace villas;
2019-06-04 16:55:38 +02:00
using namespace villas::utils;
using namespace villas::node;
using namespace villas::node::memory;
2019-06-04 16:55:38 +02:00
struct ibv_mr *villas::node::memory::ib_get_mr(void *ptr) {
auto *ma = get_allocation(ptr);
2018-06-29 17:37:10 +02:00
return ma->ib.mr;
2018-06-29 17:37:10 +02:00
}
static struct Allocation *ib_alloc(size_t len, size_t alignment,
struct Type *m) {
auto *mi = (struct IB *)m->_vd;
2018-06-29 17:37:10 +02:00
auto *ma = new struct Allocation;
if (!ma)
throw MemoryAllocationError();
ma->type = m;
ma->length = len;
ma->alignment = alignment;
ma->parent =
mi->parent->alloc(len + sizeof(struct ibv_mr *), alignment, mi->parent);
ma->address = ma->parent->address;
2018-06-29 17:37:10 +02:00
if (!mi->pd) {
auto logger = Log::get("memory:ib");
logger->error("Protection domain is not registered!");
}
ma->ib.mr = ibv_reg_mr(mi->pd, ma->address, ma->length,
IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE);
if (!ma->ib.mr) {
mi->parent->free(ma->parent, mi->parent);
delete ma;
return nullptr;
}
2018-06-29 17:37:10 +02:00
return ma;
2018-06-29 17:37:10 +02:00
}
static int ib_free(struct Allocation *ma, struct Type *m) {
int ret;
auto *mi = (struct IB *)m->_vd;
2018-06-29 17:37:10 +02:00
ibv_dereg_mr(ma->ib.mr);
2018-06-29 17:37:10 +02:00
ret = mi->parent->free(ma->parent, mi->parent);
if (ret)
return ret;
2018-06-29 17:37:10 +02:00
return 0;
2018-06-29 17:37:10 +02:00
}
struct Type *villas::node::memory::ib(NodeCompat *n, struct Type *parent) {
auto *i = n->getData<struct infiniband>();
auto *mt = (struct Type *)malloc(sizeof(struct Type));
2018-06-29 17:37:10 +02:00
mt->name = "ib";
mt->flags = 0;
mt->alloc = ib_alloc;
mt->free = ib_free;
mt->alignment = 1;
2018-06-29 17:37:10 +02:00
mt->_vd = malloc(sizeof(struct IB));
2018-06-29 17:37:10 +02:00
auto *mi = (struct memory::IB *)mt->_vd;
2018-06-29 17:37:10 +02:00
mi->pd = i->ctx.pd;
mi->parent = parent;
2018-06-29 17:37:10 +02:00
return mt;
2018-06-29 17:37:10 +02:00
}