Commit 42f5f7a6 authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

sims/net/menshen: new API refactor

parent 8fd5e8ed
...@@ -310,8 +310,11 @@ int main(int argc, char *argv[]) { ...@@ -310,8 +310,11 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
struct SimbricksBaseIfParams params;
SimbricksNetIfDefaultParams(&params);
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
NetPort *np = new NetPort(); NetPort *np = new NetPort(&params);
if (!np->Connect(argv[i], synchronized)) { if (!np->Connect(argv[i], synchronized)) {
std::cerr << "connecting to port " << argv[i] << " failed" << std::endl; std::cerr << "connecting to port " << argv[i] << " failed" << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
...@@ -332,8 +335,6 @@ int main(int argc, char *argv[]) { ...@@ -332,8 +335,6 @@ int main(int argc, char *argv[]) {
// Sync all interfaces // Sync all interfaces
for (auto port : ports) for (auto port : ports)
port->Sync(main_time); port->Sync(main_time);
for (auto port : ports)
port->AdvanceEpoch(main_time);
poll_ports(); poll_ports();
......
...@@ -3,10 +3,9 @@ ...@@ -3,10 +3,9 @@
#include <stdint.h> #include <stdint.h>
#include <simbricks/proto/base.h> #include <simbricks/base/cxxatomicfix.h>
#include <simbricks/proto/network.h>
extern "C" { extern "C" {
#include <simbricks/netif/netif.h> #include <simbricks/network/if.h>
} }
extern uint64_t sync_period; extern uint64_t sync_period;
...@@ -27,7 +26,6 @@ class Port { ...@@ -27,7 +26,6 @@ class Port {
virtual bool Connect(const char *path, int sync) = 0; virtual bool Connect(const char *path, int sync) = 0;
virtual bool IsSync() = 0; virtual bool IsSync() = 0;
virtual void Sync(uint64_t cur_ts) = 0; virtual void Sync(uint64_t cur_ts) = 0;
virtual void AdvanceEpoch(uint64_t cur_ts) = 0;
virtual uint64_t NextTimestamp() = 0; virtual uint64_t NextTimestamp() = 0;
virtual enum RxPollState RxPacket( virtual enum RxPollState RxPacket(
const void *& data, size_t &len, uint64_t cur_ts) = 0; const void *& data, size_t &len, uint64_t cur_ts) = 0;
...@@ -39,21 +37,24 @@ class Port { ...@@ -39,21 +37,24 @@ class Port {
/** Normal network switch port (conneting to a NIC) */ /** Normal network switch port (conneting to a NIC) */
class NetPort : public Port { class NetPort : public Port {
protected: protected:
struct SimbricksNetIf netif_; struct SimbricksBaseIfParams *params_;
volatile union SimbricksProtoNetD2N *rx_; struct SimbricksNetIf netifObj_;
struct SimbricksNetIf *netif_;
volatile union SimbricksProtoNetMsg *rx_;
int sync_; int sync_;
public: public:
NetPort() : rx_(nullptr), sync_(0) { NetPort(struct SimbricksBaseIfParams *params) : params_(params),
memset(&netif_, 0, sizeof(netif_)); netif_(&netifObj_), rx_(nullptr), sync_(0) {
memset(&netifObj_, 0, sizeof(netifObj_));
} }
NetPort(const NetPort &other) : netif_(other.netif_), rx_(other.rx_), NetPort(const NetPort &other) : netifObj_(other.netifObj_),
sync_(other.sync_) {} netif_(&netifObj_), rx_(other.rx_), sync_(other.sync_) {}
virtual bool Connect(const char *path, int sync) override { virtual bool Connect(const char *path, int sync) override {
sync_ = sync; sync_ = sync;
return SimbricksNetIfInit(&netif_, path, &sync_) == 0; return SimbricksNetIfInit(netif_, params_, path, &sync_) == 0;
} }
virtual bool IsSync() override { virtual bool IsSync() override {
...@@ -61,32 +62,27 @@ class NetPort : public Port { ...@@ -61,32 +62,27 @@ class NetPort : public Port {
} }
virtual void Sync(uint64_t cur_ts) override { virtual void Sync(uint64_t cur_ts) override {
while (SimbricksNetIfN2DSync(&netif_, cur_ts, eth_latency, sync_period, while (SimbricksNetIfOutSync(netif_, cur_ts));
sync_mode));
}
virtual void AdvanceEpoch(uint64_t cur_ts) override {
SimbricksNetIfAdvanceEpoch(cur_ts, sync_period, sync_mode);
} }
virtual uint64_t NextTimestamp() override { virtual uint64_t NextTimestamp() override {
return SimbricksNetIfD2NTimestamp(&netif_); return SimbricksNetIfInTimestamp(netif_);
} }
virtual enum RxPollState RxPacket( virtual enum RxPollState RxPacket(
const void *& data, size_t &len, uint64_t cur_ts) override { const void *& data, size_t &len, uint64_t cur_ts) override {
assert(rx_ == nullptr); assert(rx_ == nullptr);
rx_ = SimbricksNetIfD2NPoll(&netif_, cur_ts); rx_ = SimbricksNetIfInPoll(netif_, cur_ts);
if (!rx_) if (!rx_)
return kRxPollFail; return kRxPollFail;
uint8_t type = rx_->dummy.own_type & SIMBRICKS_PROTO_NET_D2N_MSG_MASK; uint8_t type = SimbricksNetIfInType(netif_, rx_);
if (type == SIMBRICKS_PROTO_NET_D2N_MSG_SEND) { if (type == SIMBRICKS_PROTO_NET_MSG_PACKET) {
data = (const void *)rx_->send.data; data = (const void *)rx_->packet.data;
len = rx_->send.len; len = rx_->packet.len;
return kRxPollSuccess; return kRxPollSuccess;
} else if (type == SIMBRICKS_PROTO_NET_D2N_MSG_SYNC) { } else if (type == SIMBRICKS_PROTO_MSG_TYPE_SYNC) {
return kRxPollSync; return kRxPollSync;
} else { } else {
fprintf(stderr, "switch_pkt: unsupported type=%u\n", type); fprintf(stderr, "switch_pkt: unsupported type=%u\n", type);
...@@ -97,29 +93,27 @@ class NetPort : public Port { ...@@ -97,29 +93,27 @@ class NetPort : public Port {
virtual void RxDone() override { virtual void RxDone() override {
assert(rx_ != nullptr); assert(rx_ != nullptr);
SimbricksNetIfD2NDone(&netif_, rx_); SimbricksNetIfInDone(netif_, rx_);
rx_ = nullptr; rx_ = nullptr;
} }
virtual bool TxPacket( virtual bool TxPacket(
const void *data, size_t len, uint64_t cur_ts) override { const void *data, size_t len, uint64_t cur_ts) override {
volatile union SimbricksProtoNetN2D *msg_to = volatile union SimbricksProtoNetMsg *msg_to =
SimbricksNetIfN2DAlloc(&netif_, cur_ts, eth_latency); SimbricksNetIfOutAlloc(netif_, cur_ts);
if (!msg_to && !sync_) { if (!msg_to && !sync_) {
return false; return false;
} else if (!msg_to && sync_) { } else if (!msg_to && sync_) {
while (!msg_to) while (!msg_to)
msg_to = SimbricksNetIfN2DAlloc(&netif_, cur_ts, eth_latency); msg_to = SimbricksNetIfOutAlloc(netif_, cur_ts);
} }
volatile struct SimbricksProtoNetN2DRecv *rx; volatile struct SimbricksProtoNetMsgPacket *rx;
rx = &msg_to->recv; rx = &msg_to->packet;
rx->len = len; rx->len = len;
rx->port = 0; rx->port = 0;
memcpy((void *)rx->data, data, len); memcpy((void *)rx->data, data, len);
// WMB(); SimbricksNetIfOutSend(netif_, msg_to, SIMBRICKS_PROTO_NET_MSG_PACKET);
rx->own_type =
SIMBRICKS_PROTO_NET_N2D_MSG_RECV | SIMBRICKS_PROTO_NET_N2D_OWN_DEV;
return true; return true;
} }
}; };
......
...@@ -42,7 +42,8 @@ $(verilator_src_menshen): $(vsrcs_menshen) ...@@ -42,7 +42,8 @@ $(verilator_src_menshen): $(vsrcs_menshen)
--Mdir $(verilator_dir_menshen) \ --Mdir $(verilator_dir_menshen) \
-y $(dir_menshen)rtl -y $(dir_menshen)rtl/extract \ -y $(dir_menshen)rtl -y $(dir_menshen)rtl/extract \
-y $(dir_menshen)rtl/action -y $(dir_menshen)rtl/lookup -y $(dir_menshen)lib \ -y $(dir_menshen)rtl/action -y $(dir_menshen)rtl/lookup -y $(dir_menshen)lib \
$(dir_menshen)rtl/rmt_wrapper.v --exe $(abspath $(srcs_menshen)) $(abspath $(lib_netif)) $(dir_menshen)rtl/rmt_wrapper.v --exe $(abspath $(srcs_menshen)) \
$(abspath $(lib_netif)) $(abspath $(lib_base))
$(verilator_bin_menshen): $(verilator_src_menshen) $(srcs_menshen) $(lib_netif) $(verilator_bin_menshen): $(verilator_src_menshen) $(srcs_menshen) $(lib_netif)
$(MAKE) -C $(verilator_dir_menshen) -f Vrmt_wrapper.mk $(MAKE) -C $(verilator_dir_menshen) -f Vrmt_wrapper.mk
......
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