Commit f9a3a2e6 authored by Antoine Kaufmann's avatar Antoine Kaufmann Committed by Antoine Kaufmann
Browse files

reformat with clang-format

parent e51835d1
...@@ -101,7 +101,6 @@ bool BasePeerAdd(const char *path, bool listener) { ...@@ -101,7 +101,6 @@ bool BasePeerAdd(const char *path, bool listener) {
return true; return true;
} }
int BaseListen() { int BaseListen() {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Creating listening sockets\n"); fprintf(stderr, "Creating listening sockets\n");
...@@ -170,7 +169,7 @@ int BasePeerSetupQueues(struct Peer *peer) { ...@@ -170,7 +169,7 @@ int BasePeerSetupQueues(struct Peer *peer) {
} }
struct SimbricksProtoListenerIntro *li = struct SimbricksProtoListenerIntro *li =
(struct SimbricksProtoListenerIntro *) peer->intro_remote; (struct SimbricksProtoListenerIntro *)peer->intro_remote;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "PeerNetSetupQueues(%s)\n", peer->sock_path); fprintf(stderr, "PeerNetSetupQueues(%s)\n", peer->sock_path);
...@@ -189,12 +188,12 @@ int BasePeerSetupQueues(struct Peer *peer) { ...@@ -189,12 +188,12 @@ int BasePeerSetupQueues(struct Peer *peer) {
peer->shm_fd = shm_fd; peer->shm_fd = shm_fd;
peer->shm_base = shm_base; peer->shm_base = shm_base;
peer->local_base = (void *) ((uintptr_t) shm_base + li->c2l_offset); peer->local_base = (void *)((uintptr_t)shm_base + li->c2l_offset);
peer->local_offset = li->c2l_offset; peer->local_offset = li->c2l_offset;
peer->local_elen = li->c2l_elen; peer->local_elen = li->c2l_elen;
peer->local_enum = li->c2l_nentries; peer->local_enum = li->c2l_nentries;
peer->cleanup_base = (void *) ((uintptr_t) shm_base + li->l2c_offset); peer->cleanup_base = (void *)((uintptr_t)shm_base + li->l2c_offset);
peer->cleanup_offset = li->l2c_offset; peer->cleanup_offset = li->l2c_offset;
peer->cleanup_elen = li->l2c_elen; peer->cleanup_elen = li->l2c_elen;
peer->cleanup_enum = li->l2c_nentries; peer->cleanup_enum = li->l2c_nentries;
...@@ -212,7 +211,8 @@ int BasePeerSendIntro(struct Peer *peer) { ...@@ -212,7 +211,8 @@ int BasePeerSendIntro(struct Peer *peer) {
connection to the simulator is established. In this case we hold the connection to the simulator is established. In this case we hold the
message till the connection is established and send it then. */ message till the connection is established and send it then. */
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "PeerNetSetupQueues: socket not ready yet, delaying " fprintf(stderr,
"PeerNetSetupQueues: socket not ready yet, delaying "
"send\n"); "send\n");
#endif #endif
return 0; return 0;
...@@ -227,10 +227,10 @@ int BasePeerSendIntro(struct Peer *peer) { ...@@ -227,10 +227,10 @@ int BasePeerSendIntro(struct Peer *peer) {
return 0; return 0;
} }
int BasePeerReport(struct Peer *peer, uint32_t written_pos, uint32_t clean_pos) { int BasePeerReport(struct Peer *peer, uint32_t written_pos,
uint32_t clean_pos) {
uint32_t pos = peer->local_pos_cleaned; uint32_t pos = peer->local_pos_cleaned;
if (written_pos == peer->cleanup_pos_last && if (written_pos == peer->cleanup_pos_last && clean_pos == pos)
clean_pos == pos)
return 0; return 0;
#ifdef DEBUG #ifdef DEBUG
...@@ -243,9 +243,10 @@ int BasePeerReport(struct Peer *peer, uint32_t written_pos, uint32_t clean_pos) ...@@ -243,9 +243,10 @@ int BasePeerReport(struct Peer *peer, uint32_t written_pos, uint32_t clean_pos)
while (pos != clean_pos) { while (pos != clean_pos) {
void *entry = (peer->local_base + pos * peer->local_elen); void *entry = (peer->local_base + pos * peer->local_elen);
volatile union SimbricksProtoBaseMsg *msg = volatile union SimbricksProtoBaseMsg *msg =
(volatile union SimbricksProtoBaseMsg *) entry; (volatile union SimbricksProtoBaseMsg *)entry;
msg->header.own_type = (msg->header.own_type & msg->header.own_type =
(~SIMBRICKS_PROTO_MSG_OWN_MASK)) | SIMBRICKS_PROTO_MSG_OWN_PRO; (msg->header.own_type & (~SIMBRICKS_PROTO_MSG_OWN_MASK)) |
SIMBRICKS_PROTO_MSG_OWN_PRO;
pos += 1; pos += 1;
if (pos >= peer->local_enum) if (pos >= peer->local_enum)
...@@ -335,20 +336,19 @@ int BasePeerEvent(struct Peer *peer, uint32_t events) { ...@@ -335,20 +336,19 @@ int BasePeerEvent(struct Peer *peer, uint32_t events) {
return 1; return 1;
struct SimbricksProtoListenerIntro *li = struct SimbricksProtoListenerIntro *li =
(struct SimbricksProtoListenerIntro *) peer->intro_local; (struct SimbricksProtoListenerIntro *)peer->intro_local;
peer->local_base = (void *) ((uintptr_t) peer->shm_base + li->l2c_offset); peer->local_base = (void *)((uintptr_t)peer->shm_base + li->l2c_offset);
peer->local_offset = li->l2c_offset; peer->local_offset = li->l2c_offset;
peer->local_elen = li->l2c_elen; peer->local_elen = li->l2c_elen;
peer->local_enum = li->l2c_nentries; peer->local_enum = li->l2c_nentries;
peer->cleanup_base = (void *) ((uintptr_t) peer->shm_base + li->c2l_offset); peer->cleanup_base = (void *)((uintptr_t)peer->shm_base + li->c2l_offset);
peer->cleanup_offset = li->c2l_offset; peer->cleanup_offset = li->c2l_offset;
peer->cleanup_elen = li->c2l_elen; peer->cleanup_elen = li->c2l_elen;
peer->cleanup_enum = li->c2l_nentries; peer->cleanup_enum = li->c2l_nentries;
} else { } else {
/* as a listener, we use our local shm region, so no fd is sent to us */ /* as a listener, we use our local shm region, so no fd is sent to us */
ret = recv(peer->sock_fd, peer->intro_local, ret = recv(peer->sock_fd, peer->intro_local, sizeof(peer->intro_local), 0);
sizeof(peer->intro_local), 0);
if (ret <= 0) { if (ret <= 0) {
perror("PeerEvent: recv failed"); perror("PeerEvent: recv failed");
return 1; return 1;
...@@ -378,15 +378,15 @@ static inline void PollPeerTransfer(struct Peer *peer, bool *report) { ...@@ -378,15 +378,15 @@ static inline void PollPeerTransfer(struct Peer *peer, bool *report) {
if ((peer->local_pos + n + 1) % peer->local_enum == if ((peer->local_pos + n + 1) % peer->local_enum ==
peer->local_pos_cleaned) { peer->local_pos_cleaned) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "PollPeerTransfer: waiting for cleanup (%u %u)\n", fprintf(stderr, "PollPeerTransfer: waiting for cleanup (%u %u)\n", n,
n, peer->local_pos_cleaned); peer->local_pos_cleaned);
#endif #endif
break; break;
} }
void *entry = (peer->local_base + (peer->local_pos + n) * peer->local_elen); void *entry = (peer->local_base + (peer->local_pos + n) * peer->local_elen);
volatile union SimbricksProtoBaseMsg *msg = volatile union SimbricksProtoBaseMsg *msg =
(volatile union SimbricksProtoBaseMsg *) entry; (volatile union SimbricksProtoBaseMsg *)entry;
if ((msg->header.own_type & SIMBRICKS_PROTO_MSG_OWN_MASK) != if ((msg->header.own_type & SIMBRICKS_PROTO_MSG_OWN_MASK) !=
SIMBRICKS_PROTO_MSG_OWN_CON) SIMBRICKS_PROTO_MSG_OWN_CON)
break; break;
...@@ -400,12 +400,11 @@ static inline void PollPeerTransfer(struct Peer *peer, bool *report) { ...@@ -400,12 +400,11 @@ static inline void PollPeerTransfer(struct Peer *peer, bool *report) {
#endif #endif
BaseOpPassEntries(peer, peer->local_pos, n); BaseOpPassEntries(peer, peer->local_pos, n);
uint32_t newpos = peer->local_pos + n; uint32_t newpos = peer->local_pos + n;
peer->local_pos = (newpos < peer->local_enum ? peer->local_pos =
newpos : (newpos < peer->local_enum ? newpos : newpos - peer->local_enum);
newpos - peer->local_enum);
uint64_t unreported = (peer->local_pos - peer->local_pos_reported) % uint64_t unreported =
peer->local_enum; (peer->local_pos - peer->local_pos_reported) % peer->local_enum;
if (unreported >= kPollReportThreshold) if (unreported >= kPollReportThreshold)
*report = true; *report = true;
} }
...@@ -420,13 +419,13 @@ static inline void PollPeerCleanup(struct Peer *peer, bool *report) { ...@@ -420,13 +419,13 @@ static inline void PollPeerCleanup(struct Peer *peer, bool *report) {
void *entry = void *entry =
(peer->cleanup_base + peer->cleanup_pos_next * peer->cleanup_elen); (peer->cleanup_base + peer->cleanup_pos_next * peer->cleanup_elen);
volatile union SimbricksProtoBaseMsg *msg = volatile union SimbricksProtoBaseMsg *msg =
(volatile union SimbricksProtoBaseMsg *) entry; (volatile union SimbricksProtoBaseMsg *)entry;
if ((msg->header.own_type & SIMBRICKS_PROTO_MSG_OWN_MASK) != if ((msg->header.own_type & SIMBRICKS_PROTO_MSG_OWN_MASK) !=
SIMBRICKS_PROTO_MSG_OWN_PRO) SIMBRICKS_PROTO_MSG_OWN_PRO)
break; break;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "PollPeerCleanup: peer %s has clean entry at %u\n", fprintf(stderr, "PollPeerCleanup: peer %s has clean entry at %u\n",
peer->sock_path, peer->cleanup_pos_next); peer->sock_path, peer->cleanup_pos_next);
#endif #endif
...@@ -437,8 +436,9 @@ static inline void PollPeerCleanup(struct Peer *peer, bool *report) { ...@@ -437,8 +436,9 @@ static inline void PollPeerCleanup(struct Peer *peer, bool *report) {
peer->cleanup_pos_next != peer->cleanup_pos_last); peer->cleanup_pos_next != peer->cleanup_pos_last);
if (cnt > 0) { if (cnt > 0) {
uint64_t unreported = (peer->cleanup_pos_next - peer->cleanup_pos_reported) uint64_t unreported =
% peer->cleanup_enum; (peer->cleanup_pos_next - peer->cleanup_pos_reported) %
peer->cleanup_enum;
if (unreported >= kCleanReportThreshold) if (unreported >= kCleanReportThreshold)
*report = true; *report = true;
} }
...@@ -459,27 +459,26 @@ void BasePoll() { ...@@ -459,27 +459,26 @@ void BasePoll() {
BaseOpPassReport(); BaseOpPassReport();
} }
void BaseEntryReceived(struct Peer *peer, uint32_t pos, void *data) void BaseEntryReceived(struct Peer *peer, uint32_t pos, void *data) {
{
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "BaseEntryReceived: pos=%u (cpr=%u cpl=%u)\n", fprintf(stderr, "BaseEntryReceived: pos=%u (cpr=%u cpl=%u)\n", pos,
pos, peer->cleanup_pos_reported, peer->cleanup_pos_last); peer->cleanup_pos_reported, peer->cleanup_pos_last);
#endif #endif
uint64_t off = (uint64_t) pos * peer->cleanup_elen; uint64_t off = (uint64_t)pos * peer->cleanup_elen;
void *entry = peer->cleanup_base + off; void *entry = peer->cleanup_base + off;
volatile union SimbricksProtoBaseMsg *msg = volatile union SimbricksProtoBaseMsg *msg =
(volatile union SimbricksProtoBaseMsg *) entry; (volatile union SimbricksProtoBaseMsg *)entry;
// first copy data after header // first copy data after header
memcpy((void *) (msg + 1), (uint8_t *) data + sizeof(*msg), memcpy((void *)(msg + 1), (uint8_t *)data + sizeof(*msg),
peer->cleanup_elen - sizeof(*msg)); peer->cleanup_elen - sizeof(*msg));
// then copy header except for last byte // then copy header except for last byte
memcpy((void *) msg, data, sizeof(*msg) - 1); memcpy((void *)msg, data, sizeof(*msg) - 1);
// WMB() // WMB()
// now copy last byte // now copy last byte
volatile union SimbricksProtoBaseMsg *src_msg = volatile union SimbricksProtoBaseMsg *src_msg =
(volatile union SimbricksProtoBaseMsg *) data; (volatile union SimbricksProtoBaseMsg *)data;
asm volatile("sfence" ::: "memory"); asm volatile("sfence" ::: "memory");
msg->header.own_type = src_msg->header.own_type; msg->header.own_type = src_msg->header.own_type;
} }
\ No newline at end of file
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
struct Peer { struct Peer {
/* base address of the local queue we're polling. */ /* base address of the local queue we're polling. */
uint8_t *local_base; uint8_t *local_base;
...@@ -80,7 +79,6 @@ struct Peer { ...@@ -80,7 +79,6 @@ struct Peer {
// is our local peer a listener? // is our local peer a listener?
bool is_listener; bool is_listener;
// set true when the queue is ready for polling // set true when the queue is ready for polling
volatile bool ready; volatile bool ready;
......
...@@ -215,4 +215,3 @@ void *ShmMap(int shm_fd, size_t *psize) { ...@@ -215,4 +215,3 @@ void *ShmMap(int shm_fd, size_t *psize) {
*psize = statbuf.st_size; *psize = statbuf.st_size;
return p; return p;
} }
...@@ -53,7 +53,6 @@ bool ib_connect = false; ...@@ -53,7 +53,6 @@ bool ib_connect = false;
uint8_t ib_port = 1; uint8_t ib_port = 1;
int ib_sgid_idx = -1; int ib_sgid_idx = -1;
static void PrintUsage() { static void PrintUsage() {
fprintf(stderr, fprintf(stderr,
"Usage: net_rdma [OPTIONS] IP PORT\n" "Usage: net_rdma [OPTIONS] IP PORT\n"
......
...@@ -25,12 +25,11 @@ ...@@ -25,12 +25,11 @@
#ifndef DIST_NET_RDMA_H_ #ifndef DIST_NET_RDMA_H_
#define DIST_NET_RDMA_H_ #define DIST_NET_RDMA_H_
#include "dist/common/base.h"
#include <arpa/inet.h> #include <arpa/inet.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include "dist/common/base.h"
// configuration variables // configuration variables
extern size_t shm_size; extern size_t shm_size;
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
*/ */
#include "dist/rdma/rdma.h" #include "dist/rdma/rdma.h"
#include "dist/rdma/net_rdma.h"
#include <fcntl.h> #include <fcntl.h>
#include <infiniband/verbs.h> #include <infiniband/verbs.h>
...@@ -33,6 +32,8 @@ ...@@ -33,6 +32,8 @@
#include <sys/epoll.h> #include <sys/epoll.h>
#include <unistd.h> #include <unistd.h>
#include "dist/rdma/net_rdma.h"
#define SENDQ_LEN (8 * 1024) #define SENDQ_LEN (8 * 1024)
#define MSG_RXBUFS 512 #define MSG_RXBUFS 512
#define MSG_TXBUFS 512 #define MSG_TXBUFS 512
...@@ -73,7 +74,7 @@ static struct ibv_cq *cq; ...@@ -73,7 +74,7 @@ static struct ibv_cq *cq;
static struct ibv_comp_channel *comp_chan; static struct ibv_comp_channel *comp_chan;
static struct ibv_mr *mr_shm; static struct ibv_mr *mr_shm;
static struct ibv_mr *mr_msgs; static struct ibv_mr *mr_msgs;
static struct ibv_qp_init_attr qp_attr = { }; static struct ibv_qp_init_attr qp_attr = {};
static struct NetRdmaMsg msgs[MSG_RXBUFS + MSG_TXBUFS]; static struct NetRdmaMsg msgs[MSG_RXBUFS + MSG_TXBUFS];
pthread_spinlock_t freelist_spin; pthread_spinlock_t freelist_spin;
...@@ -98,12 +99,12 @@ static void RdmaMsgFree(struct NetRdmaMsg *msg) { ...@@ -98,12 +99,12 @@ static void RdmaMsgFree(struct NetRdmaMsg *msg) {
} }
static int RdmMsgRxEnqueue(struct NetRdmaMsg *msg) { static int RdmMsgRxEnqueue(struct NetRdmaMsg *msg) {
struct ibv_sge sge = { }; struct ibv_sge sge = {};
sge.addr = (uintptr_t) msg; sge.addr = (uintptr_t)msg;
sge.length = sizeof(*msg); sge.length = sizeof(*msg);
sge.lkey = mr_msgs->lkey; sge.lkey = mr_msgs->lkey;
struct ibv_recv_wr recv_wr = { }; struct ibv_recv_wr recv_wr = {};
recv_wr.wr_id = msg - msgs; recv_wr.wr_id = msg - msgs;
recv_wr.sg_list = &sge; recv_wr.sg_list = &sge;
recv_wr.num_sge = 1; recv_wr.num_sge = 1;
...@@ -209,14 +210,13 @@ int RdmaCommonInit(struct ibv_context *ctx) { ...@@ -209,14 +210,13 @@ int RdmaCommonInit(struct ibv_context *ctx) {
return 1; return 1;
} }
if (!(mr_shm = ibv_reg_mr(pd, shm_base, shm_size, if (!(mr_shm =
IBV_ACCESS_LOCAL_WRITE | ibv_reg_mr(pd, shm_base, shm_size,
IBV_ACCESS_REMOTE_WRITE))) { IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE))) {
perror("RdmaCommonInit: ibv_reg_mr shm failed"); perror("RdmaCommonInit: ibv_reg_mr shm failed");
return 1; return 1;
} }
if (!(mr_msgs = ibv_reg_mr(pd, msgs, sizeof(msgs), if (!(mr_msgs = ibv_reg_mr(pd, msgs, sizeof(msgs), IBV_ACCESS_LOCAL_WRITE))) {
IBV_ACCESS_LOCAL_WRITE))) {
perror("RdmaCommonInit: ibv_reg_mr msgs failed"); perror("RdmaCommonInit: ibv_reg_mr msgs failed");
return 1; return 1;
} }
...@@ -384,9 +384,9 @@ int BaseOpPassIntro(struct Peer *peer) { ...@@ -384,9 +384,9 @@ int BaseOpPassIntro(struct Peer *peer) {
// connecting peers have sent us an SHM region, need to register this an as MR // connecting peers have sent us an SHM region, need to register this an as MR
if (!peer->is_listener) { if (!peer->is_listener) {
if (!(peer->shm_opaque = ibv_reg_mr(pd, peer->shm_base, peer->shm_size, if (!(peer->shm_opaque =
IBV_ACCESS_LOCAL_WRITE | ibv_reg_mr(pd, peer->shm_base, peer->shm_size,
IBV_ACCESS_REMOTE_WRITE))) { IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE))) {
perror("BaseOpPassIntro: ibv_reg_mr shm failed"); perror("BaseOpPassIntro: ibv_reg_mr shm failed");
return 1; return 1;
} }
...@@ -407,7 +407,7 @@ int BaseOpPassIntro(struct Peer *peer) { ...@@ -407,7 +407,7 @@ int BaseOpPassIntro(struct Peer *peer) {
return 1; return 1;
msg->id = peer - peers; msg->id = peer - peers;
msg->base_addr = (uintptr_t) peer->shm_base; msg->base_addr = (uintptr_t)peer->shm_base;
struct ibv_mr *mr = peer->shm_opaque; struct ibv_mr *mr = peer->shm_opaque;
msg->rkey = mr->rkey; msg->rkey = mr->rkey;
msg->msg_type = kMsgIntro; msg->msg_type = kMsgIntro;
...@@ -420,11 +420,11 @@ int BaseOpPassIntro(struct Peer *peer) { ...@@ -420,11 +420,11 @@ int BaseOpPassIntro(struct Peer *peer) {
memcpy(msg->intro.data, peer->intro_local, peer->intro_local_len); memcpy(msg->intro.data, peer->intro_local, peer->intro_local_len);
struct ibv_sge sge; struct ibv_sge sge;
sge.addr = (uintptr_t) msg; sge.addr = (uintptr_t)msg;
sge.length = sizeof(*msg); sge.length = sizeof(*msg);
sge.lkey = mr_msgs->lkey; sge.lkey = mr_msgs->lkey;
struct ibv_send_wr send_wr = { }; struct ibv_send_wr send_wr = {};
send_wr.wr_id = msg - msgs; send_wr.wr_id = msg - msgs;
send_wr.opcode = IBV_WR_SEND; send_wr.opcode = IBV_WR_SEND;
send_wr.send_flags = IBV_SEND_SIGNALED; send_wr.send_flags = IBV_SEND_SIGNALED;
...@@ -445,8 +445,7 @@ int BaseOpPassIntro(struct Peer *peer) { ...@@ -445,8 +445,7 @@ int BaseOpPassIntro(struct Peer *peer) {
int BaseOpPassEntries(struct Peer *peer, uint32_t pos, uint32_t n) { int BaseOpPassEntries(struct Peer *peer, uint32_t pos, uint32_t n) {
#ifdef RDMA_DEBUG #ifdef RDMA_DEBUG
fprintf(stderr, "BaseOpPassEntries(%s,%u)\n", peer->sock_path, fprintf(stderr, "BaseOpPassEntries(%s,%u)\n", peer->sock_path, pos);
pos);
fprintf(stderr, " remote_base=%lx local_base=%p\n", peer->remote_base, fprintf(stderr, " remote_base=%lx local_base=%p\n", peer->remote_base,
peer->local_base); peer->local_base);
#endif #endif
...@@ -458,12 +457,12 @@ int BaseOpPassEntries(struct Peer *peer, uint32_t pos, uint32_t n) { ...@@ -458,12 +457,12 @@ int BaseOpPassEntries(struct Peer *peer, uint32_t pos, uint32_t n) {
while (1) { while (1) {
uint64_t abs_pos = pos * peer->local_elen; uint64_t abs_pos = pos * peer->local_elen;
struct ibv_sge sge; struct ibv_sge sge;
sge.addr = (uintptr_t) (peer->local_base + abs_pos); sge.addr = (uintptr_t)(peer->local_base + abs_pos);
sge.length = peer->local_elen * n; sge.length = peer->local_elen * n;
struct ibv_mr *mr = peer->shm_opaque; struct ibv_mr *mr = peer->shm_opaque;
sge.lkey = mr->lkey; sge.lkey = mr->lkey;
struct ibv_send_wr send_wr = { }; struct ibv_send_wr send_wr = {};
send_wr.wr_id = -1ULL; send_wr.wr_id = -1ULL;
send_wr.opcode = IBV_WR_RDMA_WRITE; send_wr.opcode = IBV_WR_RDMA_WRITE;
if (triggerSig) if (triggerSig)
...@@ -519,11 +518,11 @@ int BaseOpPassReport() { ...@@ -519,11 +518,11 @@ int BaseOpPassReport() {
while (1) { while (1) {
struct ibv_sge sge; struct ibv_sge sge;
sge.addr = (uintptr_t) msg; sge.addr = (uintptr_t)msg;
sge.length = sizeof(*msg); sge.length = sizeof(*msg);
sge.lkey = mr_msgs->lkey; sge.lkey = mr_msgs->lkey;
struct ibv_send_wr send_wr = { }; struct ibv_send_wr send_wr = {};
send_wr.wr_id = msg - msgs; send_wr.wr_id = msg - msgs;
send_wr.opcode = IBV_WR_SEND; send_wr.opcode = IBV_WR_SEND;
send_wr.send_flags = IBV_SEND_SIGNALED; send_wr.send_flags = IBV_SEND_SIGNALED;
......
...@@ -25,21 +25,18 @@ ...@@ -25,21 +25,18 @@
#ifndef DIST_RDMA_H_ #ifndef DIST_RDMA_H_
#define DIST_RDMA_H_ #define DIST_RDMA_H_
#include "dist/rdma/net_rdma.h"
#include <infiniband/verbs.h> #include <infiniband/verbs.h>
#include "dist/rdma/net_rdma.h"
int RdmaCommonInit(struct ibv_context *ctx); int RdmaCommonInit(struct ibv_context *ctx);
int RdmaCMListen(struct sockaddr_in *addr); int RdmaCMListen(struct sockaddr_in *addr);
int RdmaCMConnect(struct sockaddr_in *addr); int RdmaCMConnect(struct sockaddr_in *addr);
struct ibv_qp *RdmaCMCreateQP(struct ibv_pd *pd, struct ibv_qp *RdmaCMCreateQP(struct ibv_pd *pd, struct ibv_qp_init_attr *attr);
struct ibv_qp_init_attr *attr);
int RdmaIBListen(struct sockaddr_in *addr); int RdmaIBListen(struct sockaddr_in *addr);
int RdmaIBConnect(struct sockaddr_in *addr); int RdmaIBConnect(struct sockaddr_in *addr);
struct ibv_qp *RdmaIBCreateQP(struct ibv_pd *pd, struct ibv_qp *RdmaIBCreateQP(struct ibv_pd *pd, struct ibv_qp_init_attr *attr);
struct ibv_qp_init_attr *attr);
#endif // DIST_RDMA_H_ #endif // DIST_RDMA_H_
...@@ -22,15 +22,15 @@ ...@@ -22,15 +22,15 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include "dist/rdma/rdma.h"
#include "dist/rdma/net_rdma.h"
#include <rdma/rdma_cma.h> #include <rdma/rdma_cma.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "dist/rdma/net_rdma.h"
#include "dist/rdma/rdma.h"
static struct rdma_event_channel *cm_channel; static struct rdma_event_channel *cm_channel;
static struct rdma_conn_param conn_param = { }; static struct rdma_conn_param conn_param = {};
static struct rdma_cm_id *cm_id; static struct rdma_cm_id *cm_id;
int RdmaCMListen(struct sockaddr_in *addr) { int RdmaCMListen(struct sockaddr_in *addr) {
...@@ -45,7 +45,7 @@ int RdmaCMListen(struct sockaddr_in *addr) { ...@@ -45,7 +45,7 @@ int RdmaCMListen(struct sockaddr_in *addr) {
return 1; return 1;
} }
if (rdma_bind_addr(listen_id, (struct sockaddr *) addr)) { if (rdma_bind_addr(listen_id, (struct sockaddr *)addr)) {
perror("RdmaListen: rdma_bind_addr failed"); perror("RdmaListen: rdma_bind_addr failed");
return 1; return 1;
} }
...@@ -115,7 +115,7 @@ int RdmaCMConnect(struct sockaddr_in *addr) { ...@@ -115,7 +115,7 @@ int RdmaCMConnect(struct sockaddr_in *addr) {
return 1; return 1;
} }
if (rdma_resolve_addr(cm_id, NULL, (struct sockaddr *) addr, 5000)) { if (rdma_resolve_addr(cm_id, NULL, (struct sockaddr *)addr, 5000)) {
perror("RdmaConnect: rdma_resolve_addr failed"); perror("RdmaConnect: rdma_resolve_addr failed");
return 1; return 1;
} }
......
...@@ -22,14 +22,13 @@ ...@@ -22,14 +22,13 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include "dist/rdma/rdma.h"
#include "dist/rdma/net_rdma.h"
#include <rdma/rdma_cma.h> #include <rdma/rdma_cma.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "dist/rdma/net_rdma.h"
#include "dist/rdma/rdma.h"
struct RdmaIBInitMsg { struct RdmaIBInitMsg {
union ibv_gid gid; union ibv_gid gid;
...@@ -57,7 +56,7 @@ static int SockListen(struct sockaddr_in *addr) { ...@@ -57,7 +56,7 @@ static int SockListen(struct sockaddr_in *addr) {
return 1; return 1;
} }
if (bind(lfd, (struct sockaddr *) addr, sizeof(*addr))) { if (bind(lfd, (struct sockaddr *)addr, sizeof(*addr))) {
perror("RdmaIBListen: bind failed"); perror("RdmaIBListen: bind failed");
return 1; return 1;
} }
...@@ -81,7 +80,7 @@ static int SockConnect(struct sockaddr_in *addr) { ...@@ -81,7 +80,7 @@ static int SockConnect(struct sockaddr_in *addr) {
return 1; return 1;
} }
if (connect(sock_fd, (struct sockaddr *) addr, sizeof(*addr))) { if (connect(sock_fd, (struct sockaddr *)addr, sizeof(*addr))) {
perror("RdmaIBConnect: connect failed"); perror("RdmaIBConnect: connect failed");
} }
return 0; return 0;
...@@ -152,7 +151,6 @@ static int CommonInit() { ...@@ -152,7 +151,6 @@ static int CommonInit() {
out_msg.qpn = ib_qp->qp_num; out_msg.qpn = ib_qp->qp_num;
out_msg.psn = psn_local; out_msg.psn = psn_local;
if (write(sock_fd, &out_msg, sizeof(out_msg)) != sizeof(out_msg)) { if (write(sock_fd, &out_msg, sizeof(out_msg)) != sizeof(out_msg)) {
perror("CommonInit: write failed"); perror("CommonInit: write failed");
} }
...@@ -165,8 +163,8 @@ static int CommonInit() { ...@@ -165,8 +163,8 @@ static int CommonInit() {
#ifdef RDMA_DEBUG #ifdef RDMA_DEBUG
fprintf(stderr, "out: lid=%x qpn=%x psn=%x iid=%lx\n", out_msg.lid, fprintf(stderr, "out: lid=%x qpn=%x psn=%x iid=%lx\n", out_msg.lid,
out_msg.qpn, out_msg.psn, out_msg.gid.global.interface_id); out_msg.qpn, out_msg.psn, out_msg.gid.global.interface_id);
fprintf(stderr, "in: lid=%x qpn=%x psn=%x iid=%lx\n", in_msg.lid, fprintf(stderr, "in: lid=%x qpn=%x psn=%x iid=%lx\n", in_msg.lid, in_msg.qpn,
in_msg.qpn, in_msg.psn, in_msg.gid.global.interface_id); in_msg.psn, in_msg.gid.global.interface_id);
#endif #endif
// change queue pair to "ready to receive" // change queue pair to "ready to receive"
...@@ -191,13 +189,9 @@ static int CommonInit() { ...@@ -191,13 +189,9 @@ static int CommonInit() {
attr.ah_attr.grh.sgid_index = ib_sgid_idx; attr.ah_attr.grh.sgid_index = ib_sgid_idx;
} }
if (ibv_modify_qp(ib_qp, &attr, if (ibv_modify_qp(ib_qp, &attr,
IBV_QP_STATE | IBV_QP_STATE | IBV_QP_AV | IBV_QP_PATH_MTU |
IBV_QP_AV | IBV_QP_DEST_QPN | IBV_QP_RQ_PSN |
IBV_QP_PATH_MTU | IBV_QP_MAX_DEST_RD_ATOMIC | IBV_QP_MIN_RNR_TIMER)) {
IBV_QP_DEST_QPN |
IBV_QP_RQ_PSN |
IBV_QP_MAX_DEST_RD_ATOMIC |
IBV_QP_MIN_RNR_TIMER)) {
perror("CommonInit: Failed to modify QP to RTR"); perror("CommonInit: Failed to modify QP to RTR");
return 1; return 1;
} }
...@@ -210,11 +204,8 @@ static int CommonInit() { ...@@ -210,11 +204,8 @@ static int CommonInit() {
attr.sq_psn = psn_local; attr.sq_psn = psn_local;
attr.max_rd_atomic = 1; attr.max_rd_atomic = 1;
if (ibv_modify_qp(ib_qp, &attr, if (ibv_modify_qp(ib_qp, &attr,
IBV_QP_STATE | IBV_QP_STATE | IBV_QP_TIMEOUT | IBV_QP_RETRY_CNT |
IBV_QP_TIMEOUT | IBV_QP_RNR_RETRY | IBV_QP_SQ_PSN |
IBV_QP_RETRY_CNT |
IBV_QP_RNR_RETRY |
IBV_QP_SQ_PSN |
IBV_QP_MAX_QP_RD_ATOMIC)) { IBV_QP_MAX_QP_RD_ATOMIC)) {
perror("CommonInit: Failed to modify QP to RTS"); perror("CommonInit: Failed to modify QP to RTS");
return 1; return 1;
...@@ -246,16 +237,12 @@ struct ibv_qp *RdmaIBCreateQP(struct ibv_pd *pd, ...@@ -246,16 +237,12 @@ struct ibv_qp *RdmaIBCreateQP(struct ibv_pd *pd,
} }
// transition queue pair from reset to init state // transition queue pair from reset to init state
struct ibv_qp_attr attr_init = { struct ibv_qp_attr attr_init = {.qp_state = IBV_QPS_INIT,
.qp_state = IBV_QPS_INIT,
.pkey_index = 0, .pkey_index = 0,
.port_num = ib_port, .port_num = ib_port,
.qp_access_flags = 0 .qp_access_flags = 0};
};
if (ibv_modify_qp(ib_qp, &attr_init, if (ibv_modify_qp(ib_qp, &attr_init,
IBV_QP_STATE | IBV_QP_STATE | IBV_QP_PKEY_INDEX | IBV_QP_PORT |
IBV_QP_PKEY_INDEX |
IBV_QP_PORT |
IBV_QP_ACCESS_FLAGS)) { IBV_QP_ACCESS_FLAGS)) {
perror("RdmaIBCreateQP: ibv_modify_qp failed (reset -> init)"); perror("RdmaIBCreateQP: ibv_modify_qp failed (reset -> init)");
ibv_destroy_qp(ib_qp); ibv_destroy_qp(ib_qp);
......
...@@ -84,7 +84,6 @@ struct SockMsg { ...@@ -84,7 +84,6 @@ struct SockMsg {
}; };
} __attribute__((packed)); } __attribute__((packed));
const char *shm_path = NULL; const char *shm_path = NULL;
size_t shm_size = 256 * 1024 * 1024ULL; // 256MB size_t shm_size = 256 * 1024 * 1024ULL; // 256MB
...@@ -258,7 +257,7 @@ static int SockListen(struct sockaddr_in *addr) { ...@@ -258,7 +257,7 @@ static int SockListen(struct sockaddr_in *addr) {
return 1; return 1;
} }
if (bind(lfd, (struct sockaddr *) addr, sizeof(*addr))) { if (bind(lfd, (struct sockaddr *)addr, sizeof(*addr))) {
perror("RdmaIBListen: bind failed"); perror("RdmaIBListen: bind failed");
return 1; return 1;
} }
...@@ -283,7 +282,7 @@ static int SockConnect(struct sockaddr_in *addr) { ...@@ -283,7 +282,7 @@ static int SockConnect(struct sockaddr_in *addr) {
return 1; return 1;
} }
if (connect(sockfd, (struct sockaddr *) addr, sizeof(*addr))) { if (connect(sockfd, (struct sockaddr *)addr, sizeof(*addr))) {
perror("RdmaIBConnect: connect failed"); perror("RdmaIBConnect: connect failed");
} }
...@@ -312,7 +311,7 @@ static int SockMsgRxIntro(struct SockMsg *msg) { ...@@ -312,7 +311,7 @@ static int SockMsgRxIntro(struct SockMsg *msg) {
msg->id); msg->id);
abort(); abort();
} }
if (intro_msg->payload_len > (uint32_t) sizeof(peer->intro_remote)) { if (intro_msg->payload_len > (uint32_t)sizeof(peer->intro_remote)) {
fprintf(stderr, "SockMsgRxIntro: Intro longer than buffer\n"); fprintf(stderr, "SockMsgRxIntro: Intro longer than buffer\n");
abort(); abort();
} }
...@@ -423,7 +422,7 @@ static int SockEvent(uint32_t events) { ...@@ -423,7 +422,7 @@ static int SockEvent(uint32_t events) {
rx_buf_pos += ret; rx_buf_pos += ret;
struct SockMsg *msg = (struct SockMsg *) rx_buffer; struct SockMsg *msg = (struct SockMsg *)rx_buffer;
while (rx_buf_pos >= sizeof(*msg) && rx_buf_pos >= msg->msg_len) { while (rx_buf_pos >= sizeof(*msg) && rx_buf_pos >= msg->msg_len) {
if (SockMsgRx(msg)) if (SockMsgRx(msg))
return 1; return 1;
...@@ -451,7 +450,7 @@ static int SockSend(struct SockMsg *msg) { ...@@ -451,7 +450,7 @@ static int SockSend(struct SockMsg *msg) {
msg->msg_id = __sync_fetch_and_add(&msg_id, 1); msg->msg_id = __sync_fetch_and_add(&msg_id, 1);
size_t len = msg->msg_len; size_t len = msg->msg_len;
size_t pos = 0; size_t pos = 0;
uint8_t *buf = (uint8_t *) msg; uint8_t *buf = (uint8_t *)msg;
do { do {
ssize_t ret = write(sockfd, buf + pos, len - pos); ssize_t ret = write(sockfd, buf + pos, len - pos);
if (ret > 0) { if (ret > 0) {
......
...@@ -54,35 +54,34 @@ ...@@ -54,35 +54,34 @@
\ \
static inline volatile union msg_union *prefix##InPeek( \ static inline volatile union msg_union *prefix##InPeek( \
struct if_struct *base_if, uint64_t ts) { \ struct if_struct *base_if, uint64_t ts) { \
return (volatile union msg_union *) SimbricksBaseIfInPeek( \ return (volatile union msg_union *)SimbricksBaseIfInPeek(&base_if->base, \
&base_if->base, ts); \ ts); \
} \ } \
\ \
static inline volatile union msg_union *prefix##InPoll( \ static inline volatile union msg_union *prefix##InPoll( \
struct if_struct *base_if, uint64_t ts) { \ struct if_struct *base_if, uint64_t ts) { \
return (volatile union msg_union *) SimbricksBaseIfInPoll( \ return (volatile union msg_union *)SimbricksBaseIfInPoll(&base_if->base, \
&base_if->base, ts); \ ts); \
} \ } \
\ \
static inline uint8_t prefix##InType( \ static inline uint8_t prefix##InType(struct if_struct *base_if, \
struct if_struct *base_if, volatile union msg_union *msg) { \ volatile union msg_union *msg) { \
return SimbricksBaseIfInType(&base_if->base, &msg->base); \ return SimbricksBaseIfInType(&base_if->base, &msg->base); \
} \ } \
\ \
static inline void prefix##InDone( \ static inline void prefix##InDone(struct if_struct *base_if, \
struct if_struct *base_if, volatile union msg_union *msg) { \ volatile union msg_union *msg) { \
SimbricksBaseIfInDone(&base_if->base, &msg->base); \ SimbricksBaseIfInDone(&base_if->base, &msg->base); \
} \ } \
\ \
static inline uint64_t prefix##InTimestamp( struct if_struct *base_if) { \ static inline uint64_t prefix##InTimestamp(struct if_struct *base_if) { \
return SimbricksBaseIfInTimestamp(&base_if->base); \ return SimbricksBaseIfInTimestamp(&base_if->base); \
} \ } \
\ \
static inline volatile union msg_union *prefix##OutAlloc( \ static inline volatile union msg_union *prefix##OutAlloc( \
struct if_struct *base_if, \ struct if_struct *base_if, uint64_t timestamp) { \
uint64_t timestamp) { \ return (volatile union msg_union *)SimbricksBaseIfOutAlloc(&base_if->base, \
return (volatile union msg_union *) SimbricksBaseIfOutAlloc( \ timestamp); \
&base_if->base, timestamp); \
} \ } \
\ \
static inline void prefix##OutSend(struct if_struct *base_if, \ static inline void prefix##OutSend(struct if_struct *base_if, \
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/un.h> #include <sys/un.h>
...@@ -51,10 +50,8 @@ enum ConnState { ...@@ -51,10 +50,8 @@ enum ConnState {
kConnOpen, kConnOpen,
}; };
int SimbricksBaseIfSHMPoolCreate(struct SimbricksBaseIfSHMPool *pool, int SimbricksBaseIfSHMPoolCreate(struct SimbricksBaseIfSHMPool *pool,
const char *path, size_t pool_size) const char *path, size_t pool_size) {
{
pool->path = path; pool->path = path;
pool->size = pool_size; pool->size = pool_size;
pool->pos = 0; pool->pos = 0;
...@@ -81,8 +78,7 @@ int SimbricksBaseIfSHMPoolCreate(struct SimbricksBaseIfSHMPool *pool, ...@@ -81,8 +78,7 @@ int SimbricksBaseIfSHMPoolCreate(struct SimbricksBaseIfSHMPool *pool,
return 0; return 0;
} }
int SimbricksBaseIfSHMPoolMapFd(struct SimbricksBaseIfSHMPool *pool, int fd) int SimbricksBaseIfSHMPoolMapFd(struct SimbricksBaseIfSHMPool *pool, int fd) {
{
struct stat statbuf; struct stat statbuf;
if (fstat(fd, &statbuf) != 0) { if (fstat(fd, &statbuf) != 0) {
...@@ -91,8 +87,8 @@ int SimbricksBaseIfSHMPoolMapFd(struct SimbricksBaseIfSHMPool *pool, int fd) ...@@ -91,8 +87,8 @@ int SimbricksBaseIfSHMPoolMapFd(struct SimbricksBaseIfSHMPool *pool, int fd)
return -1; return -1;
} }
pool->base = mmap(NULL, statbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, pool->base =
fd, 0); mmap(NULL, statbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (pool->base == MAP_FAILED) { if (pool->base == MAP_FAILED) {
perror("SimbricksBaseIfSHMPoolMap: mmap failed"); perror("SimbricksBaseIfSHMPoolMap: mmap failed");
return -1; return -1;
...@@ -106,8 +102,7 @@ int SimbricksBaseIfSHMPoolMapFd(struct SimbricksBaseIfSHMPool *pool, int fd) ...@@ -106,8 +102,7 @@ int SimbricksBaseIfSHMPoolMapFd(struct SimbricksBaseIfSHMPool *pool, int fd)
} }
int SimbricksBaseIfSHMPoolMap(struct SimbricksBaseIfSHMPool *pool, int SimbricksBaseIfSHMPoolMap(struct SimbricksBaseIfSHMPool *pool,
const char *path) const char *path) {
{
int fd; int fd;
if ((fd = open(path, O_RDWR, 0666) == -1)) { if ((fd = open(path, O_RDWR, 0666) == -1)) {
...@@ -122,8 +117,7 @@ int SimbricksBaseIfSHMPoolMap(struct SimbricksBaseIfSHMPool *pool, ...@@ -122,8 +117,7 @@ int SimbricksBaseIfSHMPoolMap(struct SimbricksBaseIfSHMPool *pool,
return 0; return 0;
} }
int SimbricksBaseIfSHMPoolUnmap(struct SimbricksBaseIfSHMPool *pool) int SimbricksBaseIfSHMPoolUnmap(struct SimbricksBaseIfSHMPool *pool) {
{
if (munmap(pool->base, pool->size)) { if (munmap(pool->base, pool->size)) {
perror("SimbricksBaseIfSHMPoolUnmap: unmap failed"); perror("SimbricksBaseIfSHMPoolUnmap: unmap failed");
return -1; return -1;
...@@ -136,13 +130,11 @@ int SimbricksBaseIfSHMPoolUnmap(struct SimbricksBaseIfSHMPool *pool) ...@@ -136,13 +130,11 @@ int SimbricksBaseIfSHMPoolUnmap(struct SimbricksBaseIfSHMPool *pool)
return 0; return 0;
} }
int SimbricksBaseIfSHMPoolUnlink(struct SimbricksBaseIfSHMPool *pool) int SimbricksBaseIfSHMPoolUnlink(struct SimbricksBaseIfSHMPool *pool) {
{
return unlink(pool->path); return unlink(pool->path);
} }
void SimbricksBaseIfDefaultParams(struct SimbricksBaseIfParams *params) void SimbricksBaseIfDefaultParams(struct SimbricksBaseIfParams *params) {
{
params->link_latency = 500 * 1000; params->link_latency = 500 * 1000;
params->sync_interval = params->link_latency; params->sync_interval = params->link_latency;
params->sock_path = NULL; params->sock_path = NULL;
...@@ -153,22 +145,19 @@ void SimbricksBaseIfDefaultParams(struct SimbricksBaseIfParams *params) ...@@ -153,22 +145,19 @@ void SimbricksBaseIfDefaultParams(struct SimbricksBaseIfParams *params)
params->upper_layer_proto = SIMBRICKS_PROTO_ID_BASE; params->upper_layer_proto = SIMBRICKS_PROTO_ID_BASE;
} }
size_t SimbricksBaseIfSHMSize(struct SimbricksBaseIfParams *params) size_t SimbricksBaseIfSHMSize(struct SimbricksBaseIfParams *params) {
{
return params->in_num_entries * params->in_entries_size + return params->in_num_entries * params->in_entries_size +
params->out_num_entries * params->out_entries_size; params->out_num_entries * params->out_entries_size;
} }
int SimbricksBaseIfInit(struct SimbricksBaseIf *base_if, int SimbricksBaseIfInit(struct SimbricksBaseIf *base_if,
struct SimbricksBaseIfParams *params) struct SimbricksBaseIfParams *params) {
{
memset(base_if, 0, sizeof(*base_if)); memset(base_if, 0, sizeof(*base_if));
base_if->params = *params; base_if->params = *params;
return 0; return 0;
} }
static int AcceptOnBaseIf(struct SimbricksBaseIf *base_if) static int AcceptOnBaseIf(struct SimbricksBaseIf *base_if) {
{
int flags = (!base_if->params.blocking_conn ? SOCK_NONBLOCK : 0); int flags = (!base_if->params.blocking_conn ? SOCK_NONBLOCK : 0);
base_if->conn_fd = accept4(base_if->listen_fd, NULL, NULL, flags); base_if->conn_fd = accept4(base_if->listen_fd, NULL, NULL, flags);
if (base_if->conn_fd >= 0) { if (base_if->conn_fd >= 0) {
...@@ -188,8 +177,7 @@ static int AcceptOnBaseIf(struct SimbricksBaseIf *base_if) ...@@ -188,8 +177,7 @@ static int AcceptOnBaseIf(struct SimbricksBaseIf *base_if)
} }
int SimbricksBaseIfListen(struct SimbricksBaseIf *base_if, int SimbricksBaseIfListen(struct SimbricksBaseIf *base_if,
struct SimbricksBaseIfSHMPool *pool) struct SimbricksBaseIfSHMPool *pool) {
{
struct sockaddr_un saun; struct sockaddr_un saun;
int flags; int flags;
struct SimbricksBaseIfParams *params = &base_if->params; struct SimbricksBaseIfParams *params = &base_if->params;
...@@ -199,7 +187,8 @@ int SimbricksBaseIfListen(struct SimbricksBaseIf *base_if, ...@@ -199,7 +187,8 @@ int SimbricksBaseIfListen(struct SimbricksBaseIf *base_if,
size_t in_len = params->in_num_entries * params->in_entries_size; size_t in_len = params->in_num_entries * params->in_entries_size;
size_t out_len = params->out_num_entries * params->out_entries_size; size_t out_len = params->out_num_entries * params->out_entries_size;
if (pool->pos + in_len + out_len > pool->size) { if (pool->pos + in_len + out_len > pool->size) {
fprintf(stderr, "SimbricksBaseIfListen: not enough memory available in " fprintf(stderr,
"SimbricksBaseIfListen: not enough memory available in "
"pool"); "pool");
return -1; return -1;
} }
...@@ -256,8 +245,7 @@ out_error: ...@@ -256,8 +245,7 @@ out_error:
return -1; return -1;
} }
int SimbricksBaseIfConnect(struct SimbricksBaseIf *base_if) int SimbricksBaseIfConnect(struct SimbricksBaseIf *base_if) {
{
struct sockaddr_un saun; struct sockaddr_un saun;
int flags; int flags;
struct SimbricksBaseIfParams *params = &base_if->params; struct SimbricksBaseIfParams *params = &base_if->params;
...@@ -301,8 +289,7 @@ out_error: ...@@ -301,8 +289,7 @@ out_error:
return -1; return -1;
} }
int SimbricksBaseIfConnected(struct SimbricksBaseIf *base_if) int SimbricksBaseIfConnected(struct SimbricksBaseIf *base_if) {
{
switch (base_if->conn_state) { switch (base_if->conn_state) {
case kConnClosed: case kConnClosed:
return -1; return -1;
...@@ -329,8 +316,8 @@ int SimbricksBaseIfConnected(struct SimbricksBaseIf *base_if) ...@@ -329,8 +316,8 @@ int SimbricksBaseIfConnected(struct SimbricksBaseIf *base_if)
int status = 0; int status = 0;
socklen_t slen = sizeof(status); socklen_t slen = sizeof(status);
if (getsockopt(base_if->conn_fd, SOL_SOCKET, SO_ERROR, &status, &slen) if (getsockopt(base_if->conn_fd, SOL_SOCKET, SO_ERROR, &status, &slen) !=
!= 0) { 0) {
perror("SimbricksBaseIfConnected: getsockopt failed"); perror("SimbricksBaseIfConnected: getsockopt failed");
close(base_if->conn_fd); close(base_if->conn_fd);
base_if->conn_fd = -1; base_if->conn_fd = -1;
...@@ -364,8 +351,7 @@ int SimbricksBaseIfConnected(struct SimbricksBaseIf *base_if) ...@@ -364,8 +351,7 @@ int SimbricksBaseIfConnected(struct SimbricksBaseIf *base_if)
} }
} }
int SimbricksBaseIfConnFd(struct SimbricksBaseIf *base_if) int SimbricksBaseIfConnFd(struct SimbricksBaseIf *base_if) {
{
if (base_if->conn_state == kConnListening) { if (base_if->conn_state == kConnListening) {
return base_if->listen_fd; return base_if->listen_fd;
} else if (base_if->conn_state == kConnConnecting) { } else if (base_if->conn_state == kConnConnecting) {
...@@ -375,8 +361,7 @@ int SimbricksBaseIfConnFd(struct SimbricksBaseIf *base_if) ...@@ -375,8 +361,7 @@ int SimbricksBaseIfConnFd(struct SimbricksBaseIf *base_if)
} }
} }
int SimbricksBaseIfConnsWait(struct SimbricksBaseIf **base_ifs, unsigned n) int SimbricksBaseIfConnsWait(struct SimbricksBaseIf **base_ifs, unsigned n) {
{
unsigned i, n_wait; unsigned i, n_wait;
struct pollfd pfds[n]; struct pollfd pfds[n];
unsigned ids[n]; unsigned ids[n];
...@@ -447,11 +432,9 @@ int SimbricksBaseIfConnsWait(struct SimbricksBaseIf **base_ifs, unsigned n) ...@@ -447,11 +432,9 @@ int SimbricksBaseIfConnsWait(struct SimbricksBaseIf **base_ifs, unsigned n)
/** Send intro. */ /** Send intro. */
int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if, int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if,
const void *payload, size_t payload_len) const void *payload, size_t payload_len) {
{
if (base_if->conn_state != kConnAwaitHandshakeRxTx && if (base_if->conn_state != kConnAwaitHandshakeRxTx &&
base_if->conn_state != kConnAwaitHandshakeTx) base_if->conn_state != kConnAwaitHandshakeTx) {
{
return -1; return -1;
} }
...@@ -471,17 +454,20 @@ int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if, ...@@ -471,17 +454,20 @@ int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if,
}; };
/* fill in payload iov entry */ /* fill in payload iov entry */
iov[1].iov_base = (void *) payload; iov[1].iov_base = (void *)payload;
iov[1].iov_len = payload_len; iov[1].iov_len = payload_len;
struct SimbricksProtoListenerIntro l_intro; struct SimbricksProtoListenerIntro l_intro;
struct SimbricksProtoConnecterIntro c_intro; struct SimbricksProtoConnecterIntro c_intro;
if (base_if->listener) { if (base_if->listener) {
l_intro.version = SIMBRICKS_PROTO_VERSION; l_intro.version = SIMBRICKS_PROTO_VERSION;
l_intro.flags = (base_if->params.sync_mode == kSimbricksBaseIfSyncDisabled ? l_intro.flags =
0 : (SIMBRICKS_PROTO_FLAGS_LI_SYNC | (base_if->params.sync_mode == kSimbricksBaseIfSyncDisabled
(base_if->params.sync_mode == kSimbricksBaseIfSyncRequired ? ? 0
SIMBRICKS_PROTO_FLAGS_LI_SYNC_FORCE : 0))); : (SIMBRICKS_PROTO_FLAGS_LI_SYNC |
(base_if->params.sync_mode == kSimbricksBaseIfSyncRequired
? SIMBRICKS_PROTO_FLAGS_LI_SYNC_FORCE
: 0)));
l_intro.l2c_offset = base_if->out_queue - base_if->shm->base; l_intro.l2c_offset = base_if->out_queue - base_if->shm->base;
l_intro.l2c_elen = base_if->out_elen; l_intro.l2c_elen = base_if->out_elen;
...@@ -505,13 +491,16 @@ int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if, ...@@ -505,13 +491,16 @@ int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if,
cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(int)); cmsg->cmsg_len = CMSG_LEN(sizeof(int));
*(int *) CMSG_DATA(cmsg) = base_if->shm->fd; *(int *)CMSG_DATA(cmsg) = base_if->shm->fd;
} else { } else {
c_intro.version = SIMBRICKS_PROTO_VERSION; c_intro.version = SIMBRICKS_PROTO_VERSION;
c_intro.flags = (base_if->params.sync_mode == kSimbricksBaseIfSyncDisabled ? c_intro.flags =
0 : (SIMBRICKS_PROTO_FLAGS_CO_SYNC | (base_if->params.sync_mode == kSimbricksBaseIfSyncDisabled
(base_if->params.sync_mode == kSimbricksBaseIfSyncRequired ? ? 0
SIMBRICKS_PROTO_FLAGS_CO_SYNC_FORCE : 0))); : (SIMBRICKS_PROTO_FLAGS_CO_SYNC |
(base_if->params.sync_mode == kSimbricksBaseIfSyncRequired
? SIMBRICKS_PROTO_FLAGS_CO_SYNC_FORCE
: 0)));
c_intro.upper_layer_proto = base_if->params.upper_layer_proto; c_intro.upper_layer_proto = base_if->params.upper_layer_proto;
c_intro.upper_layer_intro_off = sizeof(c_intro); c_intro.upper_layer_intro_off = sizeof(c_intro);
...@@ -523,8 +512,9 @@ int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if, ...@@ -523,8 +512,9 @@ int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if,
if (ret < 0) { if (ret < 0) {
perror("SimbricksBaseIfIntroSend: sendmsg failed"); perror("SimbricksBaseIfIntroSend: sendmsg failed");
return -1; return -1;
} else if (ret != (ssize_t) (iov[0].iov_len + iov[1].iov_len)) { } else if (ret != (ssize_t)(iov[0].iov_len + iov[1].iov_len)) {
fprintf(stderr, "SimbricksBaseIfIntroSend: sendmsg was short, " fprintf(stderr,
"SimbricksBaseIfIntroSend: sendmsg was short, "
"currently unsupported\n"); "currently unsupported\n");
return -1; return -1;
} }
...@@ -534,7 +524,8 @@ int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if, ...@@ -534,7 +524,8 @@ int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if,
} else if (base_if->conn_state == kConnAwaitHandshakeRxTx) { } else if (base_if->conn_state == kConnAwaitHandshakeRxTx) {
base_if->conn_state = kConnAwaitHandshakeRx; base_if->conn_state = kConnAwaitHandshakeRx;
} else { } else {
fprintf(stderr, "SimbricksBaseIfIntroSend: connection in unexpected " fprintf(stderr,
"SimbricksBaseIfIntroSend: connection in unexpected "
"state at the end.\n"); "state at the end.\n");
abort(); abort();
} }
...@@ -543,12 +534,10 @@ int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if, ...@@ -543,12 +534,10 @@ int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if,
} }
/** Receive intro. */ /** Receive intro. */
int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if, int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if, void *payload,
void *payload, size_t *payload_len) size_t *payload_len) {
{
if (base_if->conn_state != kConnAwaitHandshakeRxTx && if (base_if->conn_state != kConnAwaitHandshakeRxTx &&
base_if->conn_state != kConnAwaitHandshakeRx) base_if->conn_state != kConnAwaitHandshakeRx) {
{
return -1; return -1;
} }
...@@ -594,7 +583,7 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if, ...@@ -594,7 +583,7 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if,
if (base_if->listener) { if (base_if->listener) {
struct SimbricksProtoConnecterIntro *c_intro = struct SimbricksProtoConnecterIntro *c_intro =
(struct SimbricksProtoConnecterIntro *) intro_buf; (struct SimbricksProtoConnecterIntro *)intro_buf;
sync = c_intro->flags & SIMBRICKS_PROTO_FLAGS_CO_SYNC; sync = c_intro->flags & SIMBRICKS_PROTO_FLAGS_CO_SYNC;
sync_force = c_intro->flags & SIMBRICKS_PROTO_FLAGS_CO_SYNC_FORCE; sync_force = c_intro->flags & SIMBRICKS_PROTO_FLAGS_CO_SYNC_FORCE;
version = c_intro->version; version = c_intro->version;
...@@ -602,7 +591,7 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if, ...@@ -602,7 +591,7 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if,
upper_off = c_intro->upper_layer_intro_off; upper_off = c_intro->upper_layer_intro_off;
} else { } else {
struct SimbricksProtoListenerIntro *l_intro = struct SimbricksProtoListenerIntro *l_intro =
(struct SimbricksProtoListenerIntro *) intro_buf; (struct SimbricksProtoListenerIntro *)intro_buf;
sync = l_intro->flags & SIMBRICKS_PROTO_FLAGS_LI_SYNC; sync = l_intro->flags & SIMBRICKS_PROTO_FLAGS_LI_SYNC;
sync_force = l_intro->flags & SIMBRICKS_PROTO_FLAGS_LI_SYNC_FORCE; sync_force = l_intro->flags & SIMBRICKS_PROTO_FLAGS_LI_SYNC_FORCE;
...@@ -618,19 +607,22 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if, ...@@ -618,19 +607,22 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if,
} }
if (upper_proto != base_if->params.upper_layer_proto) { if (upper_proto != base_if->params.upper_layer_proto) {
fprintf(stderr, "SimbricksBaseIfIntroRecv: peer's upper layer proto (%lx) " fprintf(stderr,
"SimbricksBaseIfIntroRecv: peer's upper layer proto (%lx) "
"does not match ours (%lx)\n", "does not match ours (%lx)\n",
upper_proto, base_if->params.upper_layer_proto); upper_proto, base_if->params.upper_layer_proto);
return -1; return -1;
} }
if (sync_force && base_if->params.sync_mode == kSimbricksBaseIfSyncDisabled) { if (sync_force && base_if->params.sync_mode == kSimbricksBaseIfSyncDisabled) {
fprintf(stderr, "SimbricksBaseIfIntroRecv: peer forced sync but we haved " fprintf(stderr,
"SimbricksBaseIfIntroRecv: peer forced sync but we haved "
"it disabled.\n"); "it disabled.\n");
return -1; return -1;
} else if (!sync && !sync_force && } else if (!sync && !sync_force &&
base_if->params.sync_mode == kSimbricksBaseIfSyncRequired) { base_if->params.sync_mode == kSimbricksBaseIfSyncRequired) {
fprintf(stderr, "SimbricksBaseIfIntroRecv: sync required locally, put peer " fprintf(stderr,
"SimbricksBaseIfIntroRecv: sync required locally, put peer "
"offers no sync.\n"); "offers no sync.\n");
return -1; return -1;
} else if (base_if->params.sync_mode == kSimbricksBaseIfSyncDisabled) { } else if (base_if->params.sync_mode == kSimbricksBaseIfSyncDisabled) {
...@@ -639,32 +631,31 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if, ...@@ -639,32 +631,31 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if,
base_if->sync = sync || sync_force; base_if->sync = sync || sync_force;
} }
size_t upper_layer_len = (size_t) ret - upper_off; size_t upper_layer_len = (size_t)ret - upper_off;
if (*payload_len < upper_layer_len) { if (*payload_len < upper_layer_len) {
fprintf(stderr, "SimbricksBaseIfIntroRecv: upper layer intro does not " fprintf(stderr,
"SimbricksBaseIfIntroRecv: upper layer intro does not "
"fit in provided buffer\n"); "fit in provided buffer\n");
return -1; return -1;
} }
memcpy(payload, intro_buf + upper_off, upper_layer_len); memcpy(payload, intro_buf + upper_off, upper_layer_len);
*payload_len = upper_layer_len; *payload_len = upper_layer_len;
if (!base_if->listener) { if (!base_if->listener) {
// handle shm setup // handle shm setup
struct SimbricksProtoListenerIntro *l_intro = struct SimbricksProtoListenerIntro *l_intro =
(struct SimbricksProtoListenerIntro *) intro_buf; (struct SimbricksProtoListenerIntro *)intro_buf;
cmsg = CMSG_FIRSTHDR(&msg); cmsg = CMSG_FIRSTHDR(&msg);
if (msg.msg_controllen <= 0 || if (msg.msg_controllen <= 0 || cmsg->cmsg_len != CMSG_LEN(sizeof(int))) {
cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
{
/* TODO fix error handling (leaking fds) */ /* TODO fix error handling (leaking fds) */
fprintf(stderr, "SimbricksBaseIfIntroRecv: getting shm fd failed (%zu) " fprintf(stderr,
"(%p != %zu)\n", msg.msg_controllen, cmsg, "SimbricksBaseIfIntroRecv: getting shm fd failed (%zu) "
CMSG_LEN(sizeof(int))); "(%p != %zu)\n",
msg.msg_controllen, cmsg, CMSG_LEN(sizeof(int)));
return -1; return -1;
} }
int shmfd = *(int *) CMSG_DATA(cmsg); int shmfd = *(int *)CMSG_DATA(cmsg);
if ((base_if->shm = calloc(1, sizeof(*base_if->shm))) == NULL) { if ((base_if->shm = calloc(1, sizeof(*base_if->shm))) == NULL) {
fprintf(stderr, "SimbricksBaseIfIntroRecv: getting shm fd failed\n"); fprintf(stderr, "SimbricksBaseIfIntroRecv: getting shm fd failed\n");
return -1; return -1;
...@@ -691,7 +682,8 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if, ...@@ -691,7 +682,8 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if,
} else if (base_if->conn_state == kConnAwaitHandshakeRxTx) { } else if (base_if->conn_state == kConnAwaitHandshakeRxTx) {
base_if->conn_state = kConnAwaitHandshakeTx; base_if->conn_state = kConnAwaitHandshakeTx;
} else { } else {
fprintf(stderr, "SimbricksBaseIfIntroRecv: connection in unexpected " fprintf(stderr,
"SimbricksBaseIfIntroRecv: connection in unexpected "
"state at the end.\n"); "state at the end.\n");
abort(); abort();
} }
...@@ -700,8 +692,7 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if, ...@@ -700,8 +692,7 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if,
} }
/** FD to wait on for intro events. */ /** FD to wait on for intro events. */
int SimbricksBaseIfIntroFd(struct SimbricksBaseIf *base_if) int SimbricksBaseIfIntroFd(struct SimbricksBaseIf *base_if) {
{
switch (base_if->conn_state) { switch (base_if->conn_state) {
case kConnAwaitHandshakeRxTx: /* FALLTRHOUGH */ case kConnAwaitHandshakeRxTx: /* FALLTRHOUGH */
case kConnAwaitHandshakeRx: /* FALLTRHOUGH */ case kConnAwaitHandshakeRx: /* FALLTRHOUGH */
...@@ -714,8 +705,7 @@ int SimbricksBaseIfIntroFd(struct SimbricksBaseIf *base_if) ...@@ -714,8 +705,7 @@ int SimbricksBaseIfIntroFd(struct SimbricksBaseIf *base_if)
} }
int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs, int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs,
size_t n) size_t n) {
{
struct pollfd pfds[n]; struct pollfd pfds[n];
unsigned n_pfd; unsigned n_pfd;
size_t established = 0; size_t established = 0;
...@@ -730,8 +720,10 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs, ...@@ -730,8 +720,10 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs,
// woops something went wrong on this connection // woops something went wrong on this connection
if (bif->conn_state == kConnClosed) { if (bif->conn_state == kConnClosed) {
fprintf(stderr, "SimBricksBaseIfEstablish: connection %zu is " fprintf(stderr,
"closed\n", i); "SimBricksBaseIfEstablish: connection %zu is "
"closed\n",
i);
return -1; return -1;
} }
...@@ -742,8 +734,8 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs, ...@@ -742,8 +734,8 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs,
return -1; return -1;
} else if (ret > 0) { } else if (ret > 0) {
pfds[n_pfd].fd = SimbricksBaseIfConnFd(bif); pfds[n_pfd].fd = SimbricksBaseIfConnFd(bif);
pfds[n_pfd].events = (bif->conn_state == kConnListening ? POLLIN : pfds[n_pfd].events =
POLLOUT); (bif->conn_state == kConnListening ? POLLIN : POLLOUT);
pfds[n_pfd].revents = 0; pfds[n_pfd].revents = 0;
n_pfd++; n_pfd++;
assert(n_pfd <= n); assert(n_pfd <= n);
...@@ -752,10 +744,12 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs, ...@@ -752,10 +744,12 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs,
// next check if we are now ready to send the handshake // next check if we are now ready to send the handshake
if ((bif->conn_state == kConnAwaitHandshakeTx || if ((bif->conn_state == kConnAwaitHandshakeTx ||
bif->conn_state == kConnAwaitHandshakeRxTx) && bif->conn_state == kConnAwaitHandshakeRxTx) &&
SimbricksBaseIfIntroSend(bif, ifs[i].tx_intro, ifs[i].tx_intro_len) SimbricksBaseIfIntroSend(bif, ifs[i].tx_intro, ifs[i].tx_intro_len) !=
!= 0) { 0) {
fprintf(stderr, "SimBricksBaseIfEstablish: Sending intro on %zu " fprintf(stderr,
"failed\n", i); "SimBricksBaseIfEstablish: Sending intro on %zu "
"failed\n",
i);
return -1; return -1;
} }
...@@ -764,8 +758,10 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs, ...@@ -764,8 +758,10 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs,
ret = SimbricksBaseIfIntroRecv(bif, ifs[i].rx_intro, ret = SimbricksBaseIfIntroRecv(bif, ifs[i].rx_intro,
&ifs[i].rx_intro_len); &ifs[i].rx_intro_len);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "SimBricksBaseIfEstablish: Receiving intro on %zu " fprintf(stderr,
"failed\n", i); "SimBricksBaseIfEstablish: Receiving intro on %zu "
"failed\n",
i);
return -1; return -1;
} else if (ret > 0) { } else if (ret > 0) {
pfds[n_pfd].fd = SimbricksBaseIfIntroFd(bif); pfds[n_pfd].fd = SimbricksBaseIfIntroFd(bif);
...@@ -782,7 +778,8 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs, ...@@ -782,7 +778,8 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs,
} }
if (n_pfd == 0 && established != n) { if (n_pfd == 0 && established != n) {
fprintf(stderr, "SimBricksBaseIfEstablish: no poll events to wait for " fprintf(stderr,
"SimBricksBaseIfEstablish: no poll events to wait for "
"but not all established (BUG)\n"); "but not all established (BUG)\n");
abort(); abort();
} else if (n_pfd > 0) { } else if (n_pfd > 0) {
...@@ -797,8 +794,7 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs, ...@@ -797,8 +794,7 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs,
return 0; return 0;
} }
void SimbricksBaseIfClose(struct SimbricksBaseIf *base_if) void SimbricksBaseIfClose(struct SimbricksBaseIf *base_if) {
{
if (base_if->conn_state == kConnListening) { if (base_if->conn_state == kConnListening) {
close(base_if->listen_fd); close(base_if->listen_fd);
base_if->listen_fd = -1; base_if->listen_fd = -1;
...@@ -811,7 +807,8 @@ void SimbricksBaseIfClose(struct SimbricksBaseIf *base_if) ...@@ -811,7 +807,8 @@ void SimbricksBaseIfClose(struct SimbricksBaseIf *base_if)
if (base_if->conn_state == kConnOpen) { if (base_if->conn_state == kConnOpen) {
// send out termination message // send out termination message
volatile union SimbricksProtoBaseMsg *msg; volatile union SimbricksProtoBaseMsg *msg;
while ((msg = SimbricksBaseIfOutAlloc(base_if, UINT64_MAX)) == NULL); while ((msg = SimbricksBaseIfOutAlloc(base_if, UINT64_MAX)) == NULL)
;
SimbricksBaseIfOutSend(base_if, msg, SIMBRICKS_PROTO_MSG_TYPE_TERMINATE); SimbricksBaseIfOutSend(base_if, msg, SIMBRICKS_PROTO_MSG_TYPE_TERMINATE);
} }
...@@ -822,7 +819,6 @@ void SimbricksBaseIfClose(struct SimbricksBaseIf *base_if) ...@@ -822,7 +819,6 @@ void SimbricksBaseIfClose(struct SimbricksBaseIf *base_if)
// TODO: if connecting end might need to unmap and free shm // TODO: if connecting end might need to unmap and free shm
} }
void SimbricksBaseIfUnlink(struct SimbricksBaseIf *base_if) void SimbricksBaseIfUnlink(struct SimbricksBaseIf *base_if) {
{
// TODO // TODO
} }
\ No newline at end of file
...@@ -32,9 +32,9 @@ ...@@ -32,9 +32,9 @@
#include <stdatomic.h> #include <stdatomic.h>
#endif #endif
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
#include <simbricks/base/proto.h> #include <simbricks/base/proto.h>
...@@ -117,13 +117,11 @@ struct SimBricksBaseIfEstablishData { ...@@ -117,13 +117,11 @@ struct SimBricksBaseIfEstablishData {
size_t rx_intro_len; size_t rx_intro_len;
}; };
/** Create and map a new shared memory pool with the specified path and size. */ /** Create and map a new shared memory pool with the specified path and size. */
int SimbricksBaseIfSHMPoolCreate(struct SimbricksBaseIfSHMPool *pool, int SimbricksBaseIfSHMPoolCreate(struct SimbricksBaseIfSHMPool *pool,
const char *path, size_t pool_size); const char *path, size_t pool_size);
/** Map existing shared memory pool by file descriptor. */ /** Map existing shared memory pool by file descriptor. */
int SimbricksBaseIfSHMPoolMapFd(struct SimbricksBaseIfSHMPool *pool, int SimbricksBaseIfSHMPoolMapFd(struct SimbricksBaseIfSHMPool *pool, int fd);
int fd);
/** Map existing shared memory pool by path. */ /** Map existing shared memory pool by path. */
int SimbricksBaseIfSHMPoolMap(struct SimbricksBaseIfSHMPool *pool, int SimbricksBaseIfSHMPoolMap(struct SimbricksBaseIfSHMPool *pool,
const char *path); const char *path);
...@@ -132,7 +130,6 @@ int SimbricksBaseIfSHMPoolUnmap(struct SimbricksBaseIfSHMPool *pool); ...@@ -132,7 +130,6 @@ int SimbricksBaseIfSHMPoolUnmap(struct SimbricksBaseIfSHMPool *pool);
/** Delete but don't unmap shared memory pool. */ /** Delete but don't unmap shared memory pool. */
int SimbricksBaseIfSHMPoolUnlink(struct SimbricksBaseIfSHMPool *pool); int SimbricksBaseIfSHMPoolUnlink(struct SimbricksBaseIfSHMPool *pool);
/** Initialize params struct with default values */ /** Initialize params struct with default values */
void SimbricksBaseIfDefaultParams(struct SimbricksBaseIfParams *params); void SimbricksBaseIfDefaultParams(struct SimbricksBaseIfParams *params);
...@@ -158,8 +155,8 @@ int SimbricksBaseIfConnsWait(struct SimbricksBaseIf **base_ifs, unsigned n); ...@@ -158,8 +155,8 @@ int SimbricksBaseIfConnsWait(struct SimbricksBaseIf **base_ifs, unsigned n);
int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if, int SimbricksBaseIfIntroSend(struct SimbricksBaseIf *base_if,
const void *payload, size_t payload_len); const void *payload, size_t payload_len);
/** Receive intro. */ /** Receive intro. */
int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if, int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if, void *payload,
void *payload, size_t *payload_len); size_t *payload_len);
/** FD to wait on for intro events. */ /** FD to wait on for intro events. */
int SimbricksBaseIfIntroFd(struct SimbricksBaseIf *base_if); int SimbricksBaseIfIntroFd(struct SimbricksBaseIf *base_if);
...@@ -190,7 +187,6 @@ static inline uint8_t SimbricksBaseIfInType( ...@@ -190,7 +187,6 @@ static inline uint8_t SimbricksBaseIfInType(
struct SimbricksBaseIf *base_if, struct SimbricksBaseIf *base_if,
volatile union SimbricksProtoBaseMsg *msg) { volatile union SimbricksProtoBaseMsg *msg) {
return (msg->header.own_type & ~SIMBRICKS_PROTO_MSG_OWN_MASK); return (msg->header.own_type & ~SIMBRICKS_PROTO_MSG_OWN_MASK);
} }
/** /**
...@@ -202,18 +198,17 @@ static inline uint8_t SimbricksBaseIfInType( ...@@ -202,18 +198,17 @@ static inline uint8_t SimbricksBaseIfInType(
* @return Pointer to the message struct if successful, NULL otherwise. * @return Pointer to the message struct if successful, NULL otherwise.
*/ */
static inline volatile union SimbricksProtoBaseMsg *SimbricksBaseIfInPeek( static inline volatile union SimbricksProtoBaseMsg *SimbricksBaseIfInPeek(
struct SimbricksBaseIf *base_if, struct SimbricksBaseIf *base_if, uint64_t timestamp) {
uint64_t timestamp) {
volatile union SimbricksProtoBaseMsg *msg = volatile union SimbricksProtoBaseMsg *msg =
(volatile union SimbricksProtoBaseMsg *) (void *) ( (volatile union SimbricksProtoBaseMsg *)(void *)((uint8_t *)
(uint8_t *) base_if->in_queue + base_if->in_pos * base_if->in_elen); base_if->in_queue +
base_if->in_pos *
base_if->in_elen);
uint8_t own_type = atomic_load_explicit( uint8_t own_type = atomic_load_explicit(
(volatile _Atomic(uint8_t) *) &msg->header.own_type, (volatile _Atomic(uint8_t) *)&msg->header.own_type, memory_order_acquire);
memory_order_acquire);
/* message not ready */ /* message not ready */
if ((own_type & SIMBRICKS_PROTO_MSG_OWN_MASK) != if ((own_type & SIMBRICKS_PROTO_MSG_OWN_MASK) != SIMBRICKS_PROTO_MSG_OWN_CON)
SIMBRICKS_PROTO_MSG_OWN_CON)
return NULL; return NULL;
/* if in sync mode, wait till message is ready */ /* if in sync mode, wait till message is ready */
...@@ -233,8 +228,7 @@ static inline volatile union SimbricksProtoBaseMsg *SimbricksBaseIfInPeek( ...@@ -233,8 +228,7 @@ static inline volatile union SimbricksProtoBaseMsg *SimbricksBaseIfInPeek(
* @return Pointer to the message struct if successful, NULL otherwise. * @return Pointer to the message struct if successful, NULL otherwise.
*/ */
static inline volatile union SimbricksProtoBaseMsg *SimbricksBaseIfInPoll( static inline volatile union SimbricksProtoBaseMsg *SimbricksBaseIfInPoll(
struct SimbricksBaseIf *base_if, struct SimbricksBaseIf *base_if, uint64_t timestamp) {
uint64_t timestamp) {
volatile union SimbricksProtoBaseMsg *msg = volatile union SimbricksProtoBaseMsg *msg =
SimbricksBaseIfInPeek(base_if, timestamp); SimbricksBaseIfInPeek(base_if, timestamp);
...@@ -263,8 +257,8 @@ static inline void SimbricksBaseIfInDone( ...@@ -263,8 +257,8 @@ static inline void SimbricksBaseIfInDone(
struct SimbricksBaseIf *base_if, struct SimbricksBaseIf *base_if,
volatile union SimbricksProtoBaseMsg *msg) { volatile union SimbricksProtoBaseMsg *msg) {
atomic_store_explicit( atomic_store_explicit(
(volatile _Atomic(uint8_t) *) &msg->header.own_type, (volatile _Atomic(uint8_t) *)&msg->header.own_type,
(uint8_t) ((msg->header.own_type & ~SIMBRICKS_PROTO_MSG_OWN_MASK) | (uint8_t)((msg->header.own_type & ~SIMBRICKS_PROTO_MSG_OWN_MASK) |
SIMBRICKS_PROTO_MSG_OWN_PRO), SIMBRICKS_PROTO_MSG_OWN_PRO),
memory_order_release); memory_order_release);
} }
...@@ -286,8 +280,7 @@ static inline uint64_t SimbricksBaseIfInTimestamp( ...@@ -286,8 +280,7 @@ static inline uint64_t SimbricksBaseIfInTimestamp(
* *
* @param base_if Base interface handle (connected). * @param base_if Base interface handle (connected).
*/ */
static inline int SimbricksBaseIfInTerminated( static inline int SimbricksBaseIfInTerminated(struct SimbricksBaseIf *base_if) {
struct SimbricksBaseIf *base_if) {
return base_if->in_terminated; return base_if->in_terminated;
} }
...@@ -300,15 +293,15 @@ static inline int SimbricksBaseIfInTerminated( ...@@ -300,15 +293,15 @@ static inline int SimbricksBaseIfInTerminated(
* @return Pointer to the message struct if successful, NULL otherwise. * @return Pointer to the message struct if successful, NULL otherwise.
*/ */
static inline volatile union SimbricksProtoBaseMsg *SimbricksBaseIfOutAlloc( static inline volatile union SimbricksProtoBaseMsg *SimbricksBaseIfOutAlloc(
struct SimbricksBaseIf *base_if, struct SimbricksBaseIf *base_if, uint64_t timestamp) {
uint64_t timestamp) {
volatile union SimbricksProtoBaseMsg *msg = volatile union SimbricksProtoBaseMsg *msg =
(volatile union SimbricksProtoBaseMsg *) (void *) ( (volatile union SimbricksProtoBaseMsg *)(void *)((uint8_t *)
(uint8_t *) base_if->out_queue + base_if->out_pos * base_if->out_elen); base_if->out_queue +
base_if->out_pos *
base_if->out_elen);
uint8_t own_type = atomic_load_explicit( uint8_t own_type = atomic_load_explicit(
(volatile _Atomic(uint8_t) *) &msg->header.own_type, (volatile _Atomic(uint8_t) *)&msg->header.own_type, memory_order_acquire);
memory_order_acquire);
if ((own_type & SIMBRICKS_PROTO_MSG_OWN_MASK) != if ((own_type & SIMBRICKS_PROTO_MSG_OWN_MASK) !=
SIMBRICKS_PROTO_MSG_OWN_PRO) { SIMBRICKS_PROTO_MSG_OWN_PRO) {
return NULL; return NULL;
...@@ -334,8 +327,8 @@ static inline volatile union SimbricksProtoBaseMsg *SimbricksBaseIfOutAlloc( ...@@ -334,8 +327,8 @@ static inline volatile union SimbricksProtoBaseMsg *SimbricksBaseIfOutAlloc(
static inline void SimbricksBaseIfOutSend( static inline void SimbricksBaseIfOutSend(
struct SimbricksBaseIf *base_if, volatile union SimbricksProtoBaseMsg *msg, struct SimbricksBaseIf *base_if, volatile union SimbricksProtoBaseMsg *msg,
uint8_t msg_type) { uint8_t msg_type) {
atomic_store_explicit((volatile _Atomic(uint8_t) *) &msg->header.own_type, atomic_store_explicit((volatile _Atomic(uint8_t) *)&msg->header.own_type,
(uint8_t) (msg_type | SIMBRICKS_PROTO_MSG_OWN_CON), (uint8_t)(msg_type | SIMBRICKS_PROTO_MSG_OWN_CON),
memory_order_release); memory_order_release);
} }
...@@ -349,9 +342,9 @@ static inline void SimbricksBaseIfOutSend( ...@@ -349,9 +342,9 @@ static inline void SimbricksBaseIfOutSend(
*/ */
static inline int SimbricksBaseIfOutSync(struct SimbricksBaseIf *base_if, static inline int SimbricksBaseIfOutSync(struct SimbricksBaseIf *base_if,
uint64_t timestamp) { uint64_t timestamp) {
if (!base_if->sync || (base_if->out_timestamp > 0 && if (!base_if->sync ||
timestamp - base_if->out_timestamp < (base_if->out_timestamp > 0 &&
base_if->params.sync_interval)) timestamp - base_if->out_timestamp < base_if->params.sync_interval))
return 0; return 0;
volatile union SimbricksProtoBaseMsg *msg = volatile union SimbricksProtoBaseMsg *msg =
...@@ -370,8 +363,7 @@ static inline int SimbricksBaseIfOutSync(struct SimbricksBaseIf *base_if, ...@@ -370,8 +363,7 @@ static inline int SimbricksBaseIfOutSync(struct SimbricksBaseIf *base_if,
* @return Timestamp. Undefined if synchronization is disabled. * @return Timestamp. Undefined if synchronization is disabled.
*/ */
static inline uint64_t SimbricksBaseIfOutNextSync( static inline uint64_t SimbricksBaseIfOutNextSync(
struct SimbricksBaseIf *base_if) struct SimbricksBaseIf *base_if) {
{
if (base_if->out_timestamp == UINT64_MAX) if (base_if->out_timestamp == UINT64_MAX)
return UINT64_MAX; return UINT64_MAX;
return base_if->out_timestamp + base_if->params.sync_interval; return base_if->out_timestamp + base_if->params.sync_interval;
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
#include <assert.h> #include <assert.h>
#include <stdint.h> #include <stdint.h>
#define SIMBRICKS_PROTO_MSG_SZCHECK(s) static_assert(sizeof(s) == 64, \ #define SIMBRICKS_PROTO_MSG_SZCHECK(s) \
"SimBrick message size check failed") static_assert(sizeof(s) == 64, "SimBrick message size check failed")
#define SIMBRICKS_PROTO_VERSION 1 #define SIMBRICKS_PROTO_VERSION 1
...@@ -76,7 +76,6 @@ struct SimbricksProtoListenerIntro { ...@@ -76,7 +76,6 @@ struct SimbricksProtoListenerIntro {
uint64_t upper_layer_intro_off; uint64_t upper_layer_intro_off;
} __attribute__((packed)); } __attribute__((packed));
/** Connecter has synchronization enabled */ /** Connecter has synchronization enabled */
#define SIMBRICKS_PROTO_FLAGS_CO_SYNC (1 << 0) #define SIMBRICKS_PROTO_FLAGS_CO_SYNC (1 << 0)
/** Connecter forces synchronization */ /** Connecter forces synchronization */
...@@ -95,7 +94,6 @@ struct SimbricksProtoConnecterIntro { ...@@ -95,7 +94,6 @@ struct SimbricksProtoConnecterIntro {
uint64_t upper_layer_intro_off; uint64_t upper_layer_intro_off;
} __attribute__((packed)); } __attribute__((packed));
/** Mask for ownership bit in own_type field */ /** Mask for ownership bit in own_type field */
#define SIMBRICKS_PROTO_MSG_OWN_MASK 0x80 #define SIMBRICKS_PROTO_MSG_OWN_MASK 0x80
/** Message is owned by producer */ /** Message is owned by producer */
......
...@@ -28,8 +28,7 @@ ...@@ -28,8 +28,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
void SimbricksNetIfDefaultParams(struct SimbricksBaseIfParams *params) void SimbricksNetIfDefaultParams(struct SimbricksBaseIfParams *params) {
{
SimbricksBaseIfDefaultParams(params); SimbricksBaseIfDefaultParams(params);
params->in_entries_size = params->out_entries_size = 1536 + 64; params->in_entries_size = params->out_entries_size = 1536 + 64;
params->upper_layer_proto = SIMBRICKS_PROTO_ID_NET; params->upper_layer_proto = SIMBRICKS_PROTO_ID_NET;
...@@ -37,9 +36,7 @@ void SimbricksNetIfDefaultParams(struct SimbricksBaseIfParams *params) ...@@ -37,9 +36,7 @@ void SimbricksNetIfDefaultParams(struct SimbricksBaseIfParams *params)
int SimbricksNetIfInit(struct SimbricksNetIf *nsif, int SimbricksNetIfInit(struct SimbricksNetIf *nsif,
struct SimbricksBaseIfParams *params, struct SimbricksBaseIfParams *params,
const char *eth_socket_path, const char *eth_socket_path, int *sync_eth) {
int *sync_eth)
{
// some threaded code using this interface // some threaded code using this interface
struct SimbricksBaseIfParams params_ = *params; struct SimbricksBaseIfParams params_ = *params;
struct SimbricksBaseIf *bif = &nsif->base; struct SimbricksBaseIf *bif = &nsif->base;
......
...@@ -28,9 +28,8 @@ ...@@ -28,9 +28,8 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <simbricks/network/proto.h>
#include <simbricks/base/generic.h> #include <simbricks/base/generic.h>
#include <simbricks/network/proto.h>
struct SimbricksNetIf { struct SimbricksNetIf {
struct SimbricksBaseIf base; struct SimbricksBaseIf base;
...@@ -39,8 +38,7 @@ struct SimbricksNetIf { ...@@ -39,8 +38,7 @@ struct SimbricksNetIf {
void SimbricksNetIfDefaultParams(struct SimbricksBaseIfParams *params); void SimbricksNetIfDefaultParams(struct SimbricksBaseIfParams *params);
int SimbricksNetIfInit(struct SimbricksNetIf *nsif, int SimbricksNetIfInit(struct SimbricksNetIf *nsif,
struct SimbricksBaseIfParams *params, struct SimbricksBaseIfParams *params,
const char *eth_socket_path, const char *eth_socket_path, int *sync_eth);
int *sync_eth);
/** Generate queue access functions */ /** Generate queue access functions */
SIMBRICKS_BASEIF_GENERIC(SimbricksNetIf, SimbricksProtoNetMsg, SimbricksNetIf); SIMBRICKS_BASEIF_GENERIC(SimbricksNetIf, SimbricksProtoNetMsg, SimbricksNetIf);
......
...@@ -25,11 +25,11 @@ ...@@ -25,11 +25,11 @@
#include "lib/simbricks/nicbm/multinic.h" #include "lib/simbricks/nicbm/multinic.h"
#include <string.h> #include <string.h>
#include <thread>
#include <vector>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/fiber/all.hpp> #include <boost/fiber/all.hpp>
#include <thread>
#include <vector>
namespace nicbm { namespace nicbm {
...@@ -42,7 +42,7 @@ int MultiNicRunner::CompRunner::NicIfInit() { ...@@ -42,7 +42,7 @@ int MultiNicRunner::CompRunner::NicIfInit() {
volatile int result = 0; volatile int result = 0;
// NicIfInit will block, so run it in a separate thread and then wait for it // NicIfInit will block, so run it in a separate thread and then wait for it
std::thread t([this, &ready, &result](){ std::thread t([this, &ready, &result]() {
result = Runner::NicIfInit(); result = Runner::NicIfInit();
ready = true; ready = true;
}); });
...@@ -57,7 +57,6 @@ MultiNicRunner::CompRunner::CompRunner(Device &dev) : Runner(dev) { ...@@ -57,7 +57,6 @@ MultiNicRunner::CompRunner::CompRunner(Device &dev) : Runner(dev) {
} }
MultiNicRunner::MultiNicRunner(DeviceFactory &factory) : factory_(factory) { MultiNicRunner::MultiNicRunner(DeviceFactory &factory) : factory_(factory) {
} }
int MultiNicRunner::RunMain(int argc, char *argv[]) { int MultiNicRunner::RunMain(int argc, char *argv[]) {
...@@ -66,7 +65,8 @@ int MultiNicRunner::RunMain(int argc, char *argv[]) { ...@@ -66,7 +65,8 @@ int MultiNicRunner::RunMain(int argc, char *argv[]) {
std::vector<boost::fibers::fiber *> fibers; std::vector<boost::fibers::fiber *> fibers;
do { do {
int end; int end;
for (end = start + 1; end < argc && strcmp(argv[end], "--"); end++); for (end = start + 1; end < argc && strcmp(argv[end], "--"); end++)
;
argv[start] = argv[0]; argv[start] = argv[0];
CompRunner *r = new CompRunner(factory_.create()); CompRunner *r = new CompRunner(factory_.create());
...@@ -80,9 +80,9 @@ int MultiNicRunner::RunMain(int argc, char *argv[]) { ...@@ -80,9 +80,9 @@ int MultiNicRunner::RunMain(int argc, char *argv[]) {
start = end; start = end;
} while (start < argc); } while (start < argc);
for (auto f: fibers) { for (auto f : fibers) {
f->join(); f->join();
delete(f); delete (f);
} }
return 0; return 0;
} }
......
...@@ -55,7 +55,7 @@ static std::vector<Runner *> runners; ...@@ -55,7 +55,7 @@ static std::vector<Runner *> runners;
static uint64_t h2d_poll_total = 0; static uint64_t h2d_poll_total = 0;
static uint64_t h2d_poll_suc = 0; static uint64_t h2d_poll_suc = 0;
static uint64_t h2d_poll_sync = 0; static uint64_t h2d_poll_sync = 0;
//count from signal USR2 // count from signal USR2
static uint64_t s_h2d_poll_total = 0; static uint64_t s_h2d_poll_total = 0;
static uint64_t s_h2d_poll_suc = 0; static uint64_t s_h2d_poll_suc = 0;
static uint64_t s_h2d_poll_sync = 0; static uint64_t s_h2d_poll_sync = 0;
...@@ -63,7 +63,7 @@ static uint64_t s_h2d_poll_sync = 0; ...@@ -63,7 +63,7 @@ static uint64_t s_h2d_poll_sync = 0;
static uint64_t n2d_poll_total = 0; static uint64_t n2d_poll_total = 0;
static uint64_t n2d_poll_suc = 0; static uint64_t n2d_poll_suc = 0;
static uint64_t n2d_poll_sync = 0; static uint64_t n2d_poll_sync = 0;
//count from signal USR2 // count from signal USR2
static uint64_t s_n2d_poll_total = 0; static uint64_t s_n2d_poll_total = 0;
static uint64_t s_n2d_poll_suc = 0; static uint64_t s_n2d_poll_suc = 0;
static uint64_t s_n2d_poll_sync = 0; static uint64_t s_n2d_poll_sync = 0;
...@@ -75,7 +75,7 @@ static void sigint_handler(int dummy) { ...@@ -75,7 +75,7 @@ static void sigint_handler(int dummy) {
} }
static void sigusr1_handler(int dummy) { static void sigusr1_handler(int dummy) {
for (Runner *r: runners) for (Runner *r : runners)
fprintf(stderr, "[%p] main_time = %lu\n", r, r->TimePs()); fprintf(stderr, "[%p] main_time = %lu\n", r, r->TimePs());
} }
...@@ -130,14 +130,18 @@ void Runner::IssueDma(DMAOp &op) { ...@@ -130,14 +130,18 @@ void Runner::IssueDma(DMAOp &op) {
if (dma_pending_ < DMA_MAX_PENDING) { if (dma_pending_ < DMA_MAX_PENDING) {
// can directly issue // can directly issue
#ifdef DEBUG_NICBM #ifdef DEBUG_NICBM
printf("main_time = %lu: nicbm: issuing dma op %p addr %lx len %zu pending %zu\n",main_time_, &op, printf(
op.dma_addr_, op.len_, dma_pending_); "main_time = %lu: nicbm: issuing dma op %p addr %lx len %zu pending "
"%zu\n",
main_time_, &op, op.dma_addr_, op.len_, dma_pending_);
#endif #endif
DmaDo(op); DmaDo(op);
} else { } else {
#ifdef DEBUG_NICBM #ifdef DEBUG_NICBM
printf("main_time = %lu: nicbm: enqueuing dma op %p addr %lx len %zu pending %zu\n", main_time_, &op, printf(
op.dma_addr_, op.len_, dma_pending_); "main_time = %lu: nicbm: enqueuing dma op %p addr %lx len %zu pending "
"%zu\n",
main_time_, &op, op.dma_addr_, op.len_, dma_pending_);
#endif #endif
dma_queue_.push_back(&op); dma_queue_.push_back(&op);
} }
...@@ -160,8 +164,10 @@ void Runner::DmaDo(DMAOp &op) { ...@@ -160,8 +164,10 @@ void Runner::DmaDo(DMAOp &op) {
volatile union SimbricksProtoPcieD2H *msg = D2HAlloc(); volatile union SimbricksProtoPcieD2H *msg = D2HAlloc();
dma_pending_++; dma_pending_++;
#ifdef DEBUG_NICBM #ifdef DEBUG_NICBM
printf("main_time = %lu: nicbm: executing dma op %p addr %lx len %zu pending %zu\n",main_time_, &op, printf(
op.dma_addr_, op.len_, dma_pending_); "main_time = %lu: nicbm: executing dma op %p addr %lx len %zu pending "
"%zu\n",
main_time_, &op, op.dma_addr_, op.len_, dma_pending_);
#endif #endif
size_t maxlen = SimbricksBaseIfOutMsgLen(&nicif_.pcie.base); size_t maxlen = SimbricksBaseIfOutMsgLen(&nicif_.pcie.base);
...@@ -181,13 +187,12 @@ void Runner::DmaDo(DMAOp &op) { ...@@ -181,13 +187,12 @@ void Runner::DmaDo(DMAOp &op) {
memcpy((void *)write->data, (void *)op.data_, op.len_); memcpy((void *)write->data, (void *)op.data_, op.len_);
#ifdef DEBUG_NICBM #ifdef DEBUG_NICBM
uint8_t *tmp = (uint8_t*)op.data_; uint8_t *tmp = (uint8_t *)op.data_;
int d; int d;
printf("main_time = %lu: nicbm: dma write data: \n", main_time_); printf("main_time = %lu: nicbm: dma write data: \n", main_time_);
for (d = 0; d < op.len_; d++){ for (d = 0; d < op.len_; d++) {
printf("%02X ", *tmp); printf("%02X ", *tmp);
tmp++; tmp++;
} }
#endif #endif
SimbricksPcieIfD2HOutSend(&nicif_.pcie, msg, SimbricksPcieIfD2HOutSend(&nicif_.pcie, msg,
...@@ -198,8 +203,7 @@ void Runner::DmaDo(DMAOp &op) { ...@@ -198,8 +203,7 @@ void Runner::DmaDo(DMAOp &op) {
fprintf(stderr, fprintf(stderr,
"issue_dma: write too big (%zu), can only fit up " "issue_dma: write too big (%zu), can only fit up "
"to (%zu)\n", "to (%zu)\n",
op.len_, op.len_, maxlen - sizeof(struct SimbricksProtoPcieH2DReadcomp));
maxlen - sizeof(struct SimbricksProtoPcieH2DReadcomp));
abort(); abort();
} }
...@@ -217,7 +221,8 @@ void Runner::MsiIssue(uint8_t vec) { ...@@ -217,7 +221,8 @@ void Runner::MsiIssue(uint8_t vec) {
volatile union SimbricksProtoPcieD2H *msg = D2HAlloc(); volatile union SimbricksProtoPcieD2H *msg = D2HAlloc();
#ifdef DEBUG_NICBM #ifdef DEBUG_NICBM
printf("main_time = %lu: nicbm: issue MSI interrupt vec %u\n", main_time_, vec); printf("main_time = %lu: nicbm: issue MSI interrupt vec %u\n", main_time_,
vec);
#endif #endif
volatile struct SimbricksProtoPcieD2HInterrupt *intr = &msg->interrupt; volatile struct SimbricksProtoPcieD2HInterrupt *intr = &msg->interrupt;
intr->vector = vec; intr->vector = vec;
...@@ -233,7 +238,8 @@ void Runner::MsiXIssue(uint8_t vec) { ...@@ -233,7 +238,8 @@ void Runner::MsiXIssue(uint8_t vec) {
volatile union SimbricksProtoPcieD2H *msg = D2HAlloc(); volatile union SimbricksProtoPcieD2H *msg = D2HAlloc();
#ifdef DEBUG_NICBM #ifdef DEBUG_NICBM
printf("main_time = %lu: nicbm: issue MSI-X interrupt vec %u\n", main_time_, vec); printf("main_time = %lu: nicbm: issue MSI-X interrupt vec %u\n", main_time_,
vec);
#endif #endif
volatile struct SimbricksProtoPcieD2HInterrupt *intr = &msg->interrupt; volatile struct SimbricksProtoPcieD2HInterrupt *intr = &msg->interrupt;
intr->vector = vec; intr->vector = vec;
...@@ -281,8 +287,8 @@ void Runner::H2DRead(volatile struct SimbricksProtoPcieH2DRead *read) { ...@@ -281,8 +287,8 @@ void Runner::H2DRead(volatile struct SimbricksProtoPcieH2DRead *read) {
#ifdef DEBUG_NICBM #ifdef DEBUG_NICBM
uint64_t dbg_val = 0; uint64_t dbg_val = 0;
memcpy(&dbg_val, (const void *)rc->data, read->len <= 8 ? read->len : 8); memcpy(&dbg_val, (const void *)rc->data, read->len <= 8 ? read->len : 8);
printf("main_time = %lu: nicbm: read(off=0x%lx, len=%u, val=0x%lx)\n", main_time_, read->offset, read->len, printf("main_time = %lu: nicbm: read(off=0x%lx, len=%u, val=0x%lx)\n",
dbg_val); main_time_, read->offset, read->len, dbg_val);
#endif #endif
SimbricksPcieIfD2HOutSend(&nicif_.pcie, msg, SimbricksPcieIfD2HOutSend(&nicif_.pcie, msg,
...@@ -299,8 +305,8 @@ void Runner::H2DWrite(volatile struct SimbricksProtoPcieH2DWrite *write) { ...@@ -299,8 +305,8 @@ void Runner::H2DWrite(volatile struct SimbricksProtoPcieH2DWrite *write) {
#ifdef DEBUG_NICBM #ifdef DEBUG_NICBM
uint64_t dbg_val = 0; uint64_t dbg_val = 0;
memcpy(&dbg_val, (const void *)write->data, write->len <= 8 ? write->len : 8); memcpy(&dbg_val, (const void *)write->data, write->len <= 8 ? write->len : 8);
printf("main_time = %lu: nicbm: write(off=0x%lx, len=%u, val=0x%lx)\n", main_time_, write->offset, printf("main_time = %lu: nicbm: write(off=0x%lx, len=%u, val=0x%lx)\n",
write->len, dbg_val); main_time_, write->offset, write->len, dbg_val);
#endif #endif
dev_.RegWrite(write->bar, write->offset, (void *)write->data, write->len); dev_.RegWrite(write->bar, write->offset, (void *)write->data, write->len);
wc->req_id = write->req_id; wc->req_id = write->req_id;
...@@ -313,8 +319,8 @@ void Runner::H2DReadcomp(volatile struct SimbricksProtoPcieH2DReadcomp *rc) { ...@@ -313,8 +319,8 @@ void Runner::H2DReadcomp(volatile struct SimbricksProtoPcieH2DReadcomp *rc) {
DMAOp *op = (DMAOp *)(uintptr_t)rc->req_id; DMAOp *op = (DMAOp *)(uintptr_t)rc->req_id;
#ifdef DEBUG_NICBM #ifdef DEBUG_NICBM
printf("main_time = %lu: nicbm: completed dma read op %p addr %lx len %zu\n", main_time_, op, op->dma_addr_, printf("main_time = %lu: nicbm: completed dma read op %p addr %lx len %zu\n",
op->len_); main_time_, op, op->dma_addr_, op->len_);
#endif #endif
memcpy(op->data_, (void *)rc->data, op->len_); memcpy(op->data_, (void *)rc->data, op->len_);
...@@ -328,8 +334,8 @@ void Runner::H2DWritecomp(volatile struct SimbricksProtoPcieH2DWritecomp *wc) { ...@@ -328,8 +334,8 @@ void Runner::H2DWritecomp(volatile struct SimbricksProtoPcieH2DWritecomp *wc) {
DMAOp *op = (DMAOp *)(uintptr_t)wc->req_id; DMAOp *op = (DMAOp *)(uintptr_t)wc->req_id;
#ifdef DEBUG_NICBM #ifdef DEBUG_NICBM
printf("main_time = %lu: nicbm: completed dma write op %p addr %lx len %zu\n", main_time_, op, printf("main_time = %lu: nicbm: completed dma write op %p addr %lx len %zu\n",
op->dma_addr_, op->len_); main_time_, op, op->dma_addr_, op->len_);
#endif #endif
dev_.DmaComplete(*op); dev_.DmaComplete(*op);
...@@ -344,7 +350,8 @@ void Runner::H2DDevctrl(volatile struct SimbricksProtoPcieH2DDevctrl *dc) { ...@@ -344,7 +350,8 @@ void Runner::H2DDevctrl(volatile struct SimbricksProtoPcieH2DDevctrl *dc) {
void Runner::EthRecv(volatile struct SimbricksProtoNetMsgPacket *packet) { void Runner::EthRecv(volatile struct SimbricksProtoNetMsgPacket *packet) {
#ifdef DEBUG_NICBM #ifdef DEBUG_NICBM
printf("main_time = %lu: nicbm: eth rx: port %u len %u\n", main_time_, packet->port, packet->len); printf("main_time = %lu: nicbm: eth rx: port %u len %u\n", main_time_,
packet->port, packet->len);
#endif #endif
dev_.EthRx(packet->port, (void *)packet->data, packet->len); dev_.EthRx(packet->port, (void *)packet->data, packet->len);
...@@ -360,8 +367,7 @@ void Runner::EthSend(const void *data, size_t len) { ...@@ -360,8 +367,7 @@ void Runner::EthSend(const void *data, size_t len) {
packet->port = 0; // single port packet->port = 0; // single port
packet->len = len; packet->len = len;
memcpy((void *)packet->data, data, len); memcpy((void *)packet->data, data, len);
SimbricksNetIfOutSend(&nicif_.net, msg, SimbricksNetIfOutSend(&nicif_.net, msg, SIMBRICKS_PROTO_NET_MSG_PACKET);
SIMBRICKS_PROTO_NET_MSG_PACKET);
} }
void Runner::PollH2D() { void Runner::PollH2D() {
...@@ -371,7 +377,7 @@ void Runner::PollH2D() { ...@@ -371,7 +377,7 @@ void Runner::PollH2D() {
#ifdef STAT_NICBM #ifdef STAT_NICBM
h2d_poll_total += 1; h2d_poll_total += 1;
if (stat_flag){ if (stat_flag) {
s_h2d_poll_total += 1; s_h2d_poll_total += 1;
} }
#endif #endif
...@@ -381,7 +387,7 @@ void Runner::PollH2D() { ...@@ -381,7 +387,7 @@ void Runner::PollH2D() {
#ifdef STAT_NICBM #ifdef STAT_NICBM
h2d_poll_suc += 1; h2d_poll_suc += 1;
if (stat_flag){ if (stat_flag) {
s_h2d_poll_suc += 1; s_h2d_poll_suc += 1;
} }
#endif #endif
...@@ -411,7 +417,7 @@ void Runner::PollH2D() { ...@@ -411,7 +417,7 @@ void Runner::PollH2D() {
case SIMBRICKS_PROTO_MSG_TYPE_SYNC: case SIMBRICKS_PROTO_MSG_TYPE_SYNC:
#ifdef STAT_NICBM #ifdef STAT_NICBM
h2d_poll_sync += 1; h2d_poll_sync += 1;
if (stat_flag){ if (stat_flag) {
s_h2d_poll_sync += 1; s_h2d_poll_sync += 1;
} }
#endif #endif
...@@ -435,7 +441,7 @@ void Runner::PollN2D() { ...@@ -435,7 +441,7 @@ void Runner::PollN2D() {
#ifdef STAT_NICBM #ifdef STAT_NICBM
n2d_poll_total += 1; n2d_poll_total += 1;
if (stat_flag){ if (stat_flag) {
s_n2d_poll_total += 1; s_n2d_poll_total += 1;
} }
#endif #endif
...@@ -445,7 +451,7 @@ void Runner::PollN2D() { ...@@ -445,7 +451,7 @@ void Runner::PollN2D() {
#ifdef STAT_NICBM #ifdef STAT_NICBM
n2d_poll_suc += 1; n2d_poll_suc += 1;
if (stat_flag){ if (stat_flag) {
s_n2d_poll_suc += 1; s_n2d_poll_suc += 1;
} }
#endif #endif
...@@ -459,7 +465,7 @@ void Runner::PollN2D() { ...@@ -459,7 +465,7 @@ void Runner::PollN2D() {
case SIMBRICKS_PROTO_MSG_TYPE_SYNC: case SIMBRICKS_PROTO_MSG_TYPE_SYNC:
#ifdef STAT_NICBM #ifdef STAT_NICBM
n2d_poll_sync += 1; n2d_poll_sync += 1;
if (stat_flag){ if (stat_flag) {
s_n2d_poll_sync += 1; s_n2d_poll_sync += 1;
} }
#endif #endif
...@@ -637,23 +643,24 @@ int Runner::RunMain() { ...@@ -637,23 +643,24 @@ int Runner::RunMain() {
(double)(h2d_poll_sync + n2d_poll_sync) / (h2d_poll_suc + n2d_poll_suc)); (double)(h2d_poll_sync + n2d_poll_sync) / (h2d_poll_suc + n2d_poll_suc));
fprintf(stderr, "%20s: %22lu %20s: %22lu poll_suc_rate: %f\n", fprintf(stderr, "%20s: %22lu %20s: %22lu poll_suc_rate: %f\n",
"s_h2d_poll_total", s_h2d_poll_total, "s_h2d_poll_suc", s_h2d_poll_suc, "s_h2d_poll_total", s_h2d_poll_total, "s_h2d_poll_suc",
(double)s_h2d_poll_suc / s_h2d_poll_total); s_h2d_poll_suc, (double)s_h2d_poll_suc / s_h2d_poll_total);
fprintf(stderr, "%65s: %22lu sync_rate: %f\n", "s_h2d_poll_sync", fprintf(stderr, "%65s: %22lu sync_rate: %f\n", "s_h2d_poll_sync",
s_h2d_poll_sync, (double)s_h2d_poll_sync / s_h2d_poll_suc); s_h2d_poll_sync, (double)s_h2d_poll_sync / s_h2d_poll_suc);
fprintf(stderr, "%20s: %22lu %20s: %22lu poll_suc_rate: %f\n", fprintf(stderr, "%20s: %22lu %20s: %22lu poll_suc_rate: %f\n",
"s_n2d_poll_total", s_n2d_poll_total, "s_n2d_poll_suc", s_n2d_poll_suc, "s_n2d_poll_total", s_n2d_poll_total, "s_n2d_poll_suc",
(double)s_n2d_poll_suc / s_n2d_poll_total); s_n2d_poll_suc, (double)s_n2d_poll_suc / s_n2d_poll_total);
fprintf(stderr, "%65s: %22lu sync_rate: %f\n", "s_n2d_poll_sync", fprintf(stderr, "%65s: %22lu sync_rate: %f\n", "s_n2d_poll_sync",
s_n2d_poll_sync, (double)s_n2d_poll_sync / s_n2d_poll_suc); s_n2d_poll_sync, (double)s_n2d_poll_sync / s_n2d_poll_suc);
fprintf( fprintf(stderr, "%20s: %22lu %20s: %22lu sync_rate: %f\n", "s_recv_total",
stderr, "%20s: %22lu %20s: %22lu sync_rate: %f\n", "s_recv_total", s_h2d_poll_suc + s_n2d_poll_suc, "s_recv_sync",
s_h2d_poll_suc + s_n2d_poll_suc, "s_recv_sync", s_h2d_poll_sync + s_n2d_poll_sync, s_h2d_poll_sync + s_n2d_poll_sync,
(double)(s_h2d_poll_sync + s_n2d_poll_sync) / (s_h2d_poll_suc + s_n2d_poll_suc)); (double)(s_h2d_poll_sync + s_n2d_poll_sync) /
(s_h2d_poll_suc + s_n2d_poll_suc));
#endif #endif
SimbricksNicIfCleanup(&nicif_); SimbricksNicIfCleanup(&nicif_);
......
...@@ -50,7 +50,8 @@ class DMAOp { ...@@ -50,7 +50,8 @@ class DMAOp {
class TimedEvent { class TimedEvent {
public: public:
TimedEvent() : time_(0), priority_(0) {} TimedEvent() : time_(0), priority_(0) {
}
virtual ~TimedEvent() = default; virtual ~TimedEvent() = default;
uint64_t time_; uint64_t time_;
int priority_; int priority_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment