Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On-Demand-Paging support #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ PROJECT_NAME = libinfinity

##################################################

CC = g++
CC_FLAGS = -O3 -std=c++0x
CC = g++
CC_FLAGS = -O3 -std=c++0x -D_RDMA_USE_ODP
LD_FLAGS = -linfinity -libverbs

##################################################
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Infinity is a simple, powerful, object-oriented abstraction of ibVerbs. The libr

## Installation

### Note

**If you would like to build this library without On-Demand-Paging for RDMA (e.g., your device does not support it), then remove the `-D_RDMA_USE_ODP` flag from `CC_FLAGS` in the `Makefile`.**

Installing ''ibVerbs'' is a prerequisite before building Infinity. The output is located in ''release/libinfinity.a''.

```sh
Expand Down
12 changes: 12 additions & 0 deletions src/infinity/core/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ Context::Context(uint16_t device, uint16_t devicePort) {
defaultRequestToken = new infinity::requests::RequestToken(this);
defaultAtomic = new infinity::memory::Atomic(this);

#ifdef _RDMA_USE_ODP
// Check if On-Demand-Paging (ODP) is supported by the device
ibv_device_attr_ex da;
INFINITY_ASSERT(ibv_query_device_ex(this->ibvContext, NULL, &da) == 0, "[INFINITY][CORE][CONTEXT] Failed to query device for extended device properties.\n");
INFINITY_ASSERT(da.odp_caps.general_caps & IBV_ODP_SUPPORT, "[INFINITY][CORE][CONTEXT] ODP is not supported.\n");
INFINITY_ASSERT(da.odp_caps.general_caps & IBV_ODP_SUPPORT_IMPLICIT, "[INFINITY][CORE][CONTEXT] ODP implicit is not supported.\n");
INFINITY_ASSERT(da.odp_caps.per_transport_caps.rc_odp_caps & IBV_ODP_SUPPORT_READ, "[INFINITY][CORE][CONTEXT] ODP for reads is not supported.\n");
INFINITY_ASSERT(da.odp_caps.per_transport_caps.rc_odp_caps & IBV_ODP_SUPPORT_RECV, "[INFINITY][CORE][CONTEXT] ODP for receives is not supported.\n");
INFINITY_ASSERT(da.odp_caps.per_transport_caps.rc_odp_caps & IBV_ODP_SUPPORT_WRITE, "[INFINITY][CORE][CONTEXT] ODP for writes is not supported.\n");
INFINITY_ASSERT(da.odp_caps.per_transport_caps.rc_odp_caps & IBV_ODP_SUPPORT_SEND, "[INFINITY][CORE][CONTEXT] ODP for sends is not supported.\n");
#endif // _RDMA_USE_ODP

}

Context::~Context() {
Expand Down
29 changes: 29 additions & 0 deletions src/infinity/memory/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ Buffer::Buffer(infinity::core::Context* context, uint64_t sizeInBytes) {

memset(this->data, 0, sizeInBytes);

#ifdef _RDMA_USE_ODP
this->ibvMemoryRegion = ibv_reg_mr(this->context->getProtectionDomain(), NULL, SIZE_MAX,
IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_READ | IBV_ACCESS_ON_DEMAND);
#else
this->ibvMemoryRegion = ibv_reg_mr(this->context->getProtectionDomain(), this->data, this->sizeInBytes,
IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_READ);
#endif // _RDMA_USE_ODP

INFINITY_ASSERT(this->ibvMemoryRegion != NULL, "[INFINITY][MEMORY][BUFFER] Registration failed.\n");

this->memoryAllocated = true;
Expand Down Expand Up @@ -60,8 +66,15 @@ Buffer::Buffer(infinity::core::Context *context, void *memory, uint64_t sizeInBy
this->memoryRegionType = RegionType::BUFFER;

this->data = memory;

#ifdef _RDMA_USE_ODP
this->ibvMemoryRegion = ibv_reg_mr(this->context->getProtectionDomain(), NULL, SIZE_MAX,
IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_READ | IBV_ACCESS_ON_DEMAND);
#else
this->ibvMemoryRegion = ibv_reg_mr(this->context->getProtectionDomain(), this->data, this->sizeInBytes,
IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_READ);
#endif // _RDMA_USE_ODP

INFINITY_ASSERT(this->ibvMemoryRegion != NULL, "[INFINITY][MEMORY][BUFFER] Registration failed.\n");

this->memoryAllocated = false;
Expand All @@ -84,6 +97,16 @@ void* Buffer::getData() {
return reinterpret_cast<void *>(this->getAddress());
}

void Buffer::setData(void *data, uint64_t sizeInBytes) {
if (this->memoryAllocated) {
free(this->data);
}

this->data = data;
this->sizeInBytes = sizeInBytes;
this->memoryAllocated = false;
}

void Buffer::resize(uint64_t newSize, void* newData) {

void *oldData = this->data;
Expand All @@ -100,8 +123,14 @@ void Buffer::resize(uint64_t newSize, void* newData) {

if (memoryRegistered) {
ibv_dereg_mr(this->ibvMemoryRegion);

// When using ODP, nothing needs to be done since we don't register specific addresses anyway.
// So re-assigning a new buffer and new size is a no-op in the ODP case in terms of registering.
#ifndef _RDMA_USE_ODP
this->ibvMemoryRegion = ibv_reg_mr(this->context->getProtectionDomain(), newData, newSize,
IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_READ);
#endif // _RDMA_USE_ODP

this->data = newData;
this->sizeInBytes = newSize;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/infinity/memory/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Buffer : public Region {
public:

void * getData();
void setData(void *data, uint64_t sizeInBytes);
void resize(uint64_t newSize, void *newData = NULL);

protected:
Expand Down
12 changes: 12 additions & 0 deletions src/infinity/memory/RegisteredMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ RegisteredMemory::RegisteredMemory(infinity::core::Context* context, uint64_t si

memset(this->data, 0, sizeInBytes);

#ifdef _RDMA_USE_ODP
this->ibvMemoryRegion = ibv_reg_mr(this->context->getProtectionDomain(), NULL, SIZE_MAX,
IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_READ | IBV_ACCESS_ON_DEMAND);
#else
this->ibvMemoryRegion = ibv_reg_mr(this->context->getProtectionDomain(), this->data, this->sizeInBytes,
IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_READ);
#endif // _RDMA_USE_ODP

INFINITY_ASSERT(this->ibvMemoryRegion != NULL, "[INFINITY][MEMORY][REGISTERED] Registration failed.\n");
}

Expand All @@ -41,8 +47,14 @@ RegisteredMemory::RegisteredMemory(infinity::core::Context* context, void *data,

this->data = data;

#ifdef _RDMA_USE_ODP
this->ibvMemoryRegion = ibv_reg_mr(this->context->getProtectionDomain(), NULL, SIZE_MAX,
IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_READ | IBV_ACCESS_ON_DEMAND);
#else
this->ibvMemoryRegion = ibv_reg_mr(this->context->getProtectionDomain(), this->data, this->sizeInBytes,
IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_READ);
#endif // _RDMA_USE_ODP

INFINITY_ASSERT(this->ibvMemoryRegion != NULL, "[INFINITY][MEMORY][REGISTERED] Registration failed.\n");
}

Expand Down
27 changes: 26 additions & 1 deletion src/infinity/queues/QueuePair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ int OperationFlags::ibvFlags() {
QueuePair::QueuePair(infinity::core::Context* context) :
context(context) {

#ifdef _RDMA_USE_ODP
ibv_qp_init_attr_ex qpInitAttributes;
memset(&qpInitAttributes, 0, sizeof(qpInitAttributes));

qpInitAttributes.send_cq = context->getSendCompletionQueue();
qpInitAttributes.recv_cq = context->getReceiveCompletionQueue();
qpInitAttributes.srq = context->getSharedReceiveQueue();
qpInitAttributes.cap.max_send_wr = MAX(infinity::core::Configuration::SEND_COMPLETION_QUEUE_LENGTH, 1);
qpInitAttributes.cap.max_send_sge = infinity::core::Configuration::MAX_NUMBER_OF_SGE_ELEMENTS;
qpInitAttributes.cap.max_recv_wr = MAX(infinity::core::Configuration::RECV_COMPLETION_QUEUE_LENGTH, 1);
qpInitAttributes.cap.max_recv_sge = infinity::core::Configuration::MAX_NUMBER_OF_SGE_ELEMENTS;
qpInitAttributes.qp_type = IBV_QPT_RC;
qpInitAttributes.sq_sig_all = 0;
qpInitAttributes.pd = context->getProtectionDomain();
qpInitAttributes.comp_mask = IBV_QP_INIT_ATTR_PD | IBV_QP_INIT_ATTR_SEND_OPS_FLAGS;
qpInitAttributes.send_ops_flags = IBV_QP_EX_WITH_SEND;

this->ibvQueuePair = ibv_create_qp_ex(context->getInfiniBandContext(), &qpInitAttributes);
INFINITY_ASSERT(this->ibvQueuePair != NULL, "[INFINITY][QUEUES][QUEUEPAIR] Cannot create queue pair.\n");

unsigned int qp_access_flags = 0;
#else
ibv_qp_init_attr qpInitAttributes;
memset(&qpInitAttributes, 0, sizeof(qpInitAttributes));

Expand All @@ -54,13 +76,16 @@ QueuePair::QueuePair(infinity::core::Context* context) :
this->ibvQueuePair = ibv_create_qp(context->getProtectionDomain(), &(qpInitAttributes));
INFINITY_ASSERT(this->ibvQueuePair != NULL, "[INFINITY][QUEUES][QUEUEPAIR] Cannot create queue pair.\n");

unsigned int qp_access_flags = IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_REMOTE_READ | IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_ATOMIC;
#endif // _RDMA_USE_ODP

ibv_qp_attr qpAttributes;
memset(&qpAttributes, 0, sizeof(qpAttributes));

qpAttributes.qp_state = IBV_QPS_INIT;
qpAttributes.pkey_index = 0;
qpAttributes.port_num = context->getDevicePort();
qpAttributes.qp_access_flags = IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_REMOTE_READ | IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_ATOMIC;
qpAttributes.qp_access_flags = qp_access_flags;

int32_t returnValue = ibv_modify_qp(this->ibvQueuePair, &(qpAttributes), IBV_QP_STATE | IBV_QP_PORT | IBV_QP_ACCESS_FLAGS | IBV_QP_PKEY_INDEX);

Expand Down
1 change: 1 addition & 0 deletions src/infinity/queues/QueuePairFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void QueuePairFactory::bindToPort(uint16_t port) {

char *ipAddressOfDevice = infinity::utils::Address::getIpAddressOfInterface(infinity::core::Configuration::DEFAULT_IB_DEVICE);
INFINITY_DEBUG("[INFINITY][QUEUES][FACTORY] Accepting connections on IP address %s and port %d.\n", ipAddressOfDevice, port);
INFINITY_DEBUG("[INFINITY][QUEUES][FACTORY] Accepting connections on interface %s, IP address %s and port %d.\n", interfaceNameToQuery, ipAddressOfDevice, port);
free(ipAddressOfDevice);

}
Expand Down