-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathib.cpp
More file actions
98 lines (76 loc) · 2.25 KB
/
Copy pathib.cpp
File metadata and controls
98 lines (76 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* Infiniband memory allocator.
*
* 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
*/
#include <infiniband/verbs.h>
#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>
using namespace villas;
using namespace villas::utils;
using namespace villas::node;
using namespace villas::node::memory;
struct ibv_mr *villas::node::memory::ib_get_mr(void *ptr) {
auto *ma = get_allocation(ptr);
return ma->ib.mr;
}
static struct Allocation *ib_alloc(size_t len, size_t alignment,
struct Type *m) {
auto *mi = (struct IB *)m->_vd;
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;
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;
}
return ma;
}
static int ib_free(struct Allocation *ma, struct Type *m) {
int ret;
auto *mi = (struct IB *)m->_vd;
ibv_dereg_mr(ma->ib.mr);
ret = mi->parent->free(ma->parent, mi->parent);
if (ret)
return ret;
return 0;
}
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));
if (!mt) {
throw MemoryAllocationError();
}
mt->name = "ib";
mt->flags = 0;
mt->alloc = ib_alloc;
mt->free = ib_free;
mt->alignment = 1;
mt->_vd = malloc(sizeof(struct IB));
if (!mt->_vd) {
free(mt);
throw MemoryAllocationError();
}
auto *mi = (struct memory::IB *)mt->_vd;
mi->pd = i->ctx.pd;
mi->parent = parent;
return mt;
}