-
Notifications
You must be signed in to change notification settings - Fork 29
/
Directory.cpp
94 lines (70 loc) · 1.91 KB
/
Directory.cpp
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
#include "Directory.h"
#include "Common.h"
#include "Connection.h"
#include <gperftools/profiler.h>
GlobalAddress g_root_ptr = GlobalAddress::Null();
int g_root_level = -1;
bool enable_cache;
Directory::Directory(DirectoryConnection *dCon, RemoteConnection *remoteInfo,
uint32_t machineNR, uint16_t dirID, uint16_t nodeID)
: dCon(dCon), remoteInfo(remoteInfo), machineNR(machineNR), dirID(dirID),
nodeID(nodeID), dirTh(nullptr) {
{ // chunck alloctor
GlobalAddress dsm_start;
uint64_t per_directory_dsm_size = dCon->dsmSize / NR_DIRECTORY;
dsm_start.nodeID = nodeID;
dsm_start.offset = per_directory_dsm_size * dirID;
chunckAlloc = new GlobalAllocator(dsm_start, per_directory_dsm_size);
}
dirTh = new std::thread(&Directory::dirThread, this);
}
Directory::~Directory() { delete chunckAlloc; }
void Directory::dirThread() {
bindCore(23 - dirID);
Debug::notifyInfo("dir %d launch!\n", dirID);
while (true) {
struct ibv_wc wc;
pollWithCQ(dCon->cq, 1, &wc);
switch (int(wc.opcode)) {
case IBV_WC_RECV: // control message
{
auto *m = (RawMessage *)dCon->message->getMessage();
process_message(m);
break;
}
case IBV_WC_RDMA_WRITE: {
break;
}
case IBV_WC_RECV_RDMA_WITH_IMM: {
break;
}
default:
assert(false);
}
}
}
void Directory::process_message(const RawMessage *m) {
RawMessage *send = nullptr;
switch (m->type) {
case RpcType::MALLOC: {
send = (RawMessage *)dCon->message->getSendPool();
send->addr = chunckAlloc->alloc_chunck();
break;
}
case RpcType::NEW_ROOT: {
if (g_root_level < m->level) {
g_root_ptr = m->addr;
g_root_level = m->level;
if (g_root_level >= 3) {
enable_cache = true;
}
}
break;
}
default:
assert(false);
}
if (send) {
dCon->sendMessage2App(send, m->node_id, m->app_id);
}
}