Commit 84ade6b5 authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

sims/tofino: new API refactor

parent 4d0690d1
...@@ -28,7 +28,7 @@ OBJS := $(d)tofino.o ...@@ -28,7 +28,7 @@ OBJS := $(d)tofino.o
$(OBJS): CPPFLAGS := $(CPPFLAGS) -I$(d)include/ $(OBJS): CPPFLAGS := $(CPPFLAGS) -I$(d)include/
$(bin_tofino): $(OBJS) $(lib_netif) $(bin_tofino): $(OBJS) $(lib_netif) $(lib_base)
CLEAN := $(bin_tofino) $(OBJS) CLEAN := $(bin_tofino) $(OBJS)
ALL := $(bin_tofino) ALL := $(bin_tofino)
......
...@@ -45,9 +45,9 @@ ...@@ -45,9 +45,9 @@
#include <vector> #include <vector>
#include <set> #include <set>
#include <simbricks/base/cxxatomicfix.h>
extern "C" { extern "C" {
#include <simbricks/netif/netif.h> #include <simbricks/network/if.h>
#include <simbricks/proto/base.h>
}; };
#include <utils/json.hpp> #include <utils/json.hpp>
...@@ -58,9 +58,6 @@ using json = nlohmann::json; ...@@ -58,9 +58,6 @@ using json = nlohmann::json;
typedef long long int ts_t; typedef long long int ts_t;
static const int log_wait_limit_ms = 10; // 10ms static const int log_wait_limit_ms = 10; // 10ms
static ts_t sync_period = (500 * 1000ULL);
static ts_t eth_latency = (500 * 1000ULL); // 500ns
static int sync_mode = SIMBRICKS_PROTO_SYNC_SIMBRICKS;
static ts_t cur_ts = 0; static ts_t cur_ts = 0;
static int exiting = 0; static int exiting = 0;
static std::vector<struct SimbricksNetIf> nsifs; static std::vector<struct SimbricksNetIf> nsifs;
...@@ -156,7 +153,7 @@ static std::vector<struct packet_info> get_tofino_output() { ...@@ -156,7 +153,7 @@ static std::vector<struct packet_info> get_tofino_output() {
static ts_t get_min_peer_time() { static ts_t get_min_peer_time() {
std::set<uint64_t> peer_times; std::set<uint64_t> peer_times;
for (auto &nsif : nsifs) { for (auto &nsif : nsifs) {
peer_times.insert(SimbricksNetIfD2NTimestamp(&nsif)); peer_times.insert(SimbricksNetIfInTimestamp(&nsif));
} }
return *peer_times.begin(); return *peer_times.begin();
} }
...@@ -164,7 +161,7 @@ static ts_t get_min_peer_time() { ...@@ -164,7 +161,7 @@ static ts_t get_min_peer_time() {
static void switch_to_dev(int port) { static void switch_to_dev(int port) {
static const int BUFFER_SIZE = 2048; static const int BUFFER_SIZE = 2048;
char buf[BUFFER_SIZE]; char buf[BUFFER_SIZE];
volatile union SimbricksProtoNetN2D *msg_to; volatile union SimbricksProtoNetMsg *msg_to;
struct sockaddr_ll addr; struct sockaddr_ll addr;
socklen_t addr_len; socklen_t addr_len;
ssize_t n; ssize_t n;
...@@ -179,17 +176,15 @@ static void switch_to_dev(int port) { ...@@ -179,17 +176,15 @@ static void switch_to_dev(int port) {
; ;
} }
msg_to = SimbricksNetIfN2DAlloc(&nsifs[port], cur_ts, eth_latency); msg_to = SimbricksNetIfOutAlloc(&nsifs[port], cur_ts);
if (msg_to != nullptr) { if (msg_to != nullptr) {
volatile struct SimbricksProtoNetN2DRecv *rx; volatile struct SimbricksProtoNetMsgPacket *rx;
rx = &msg_to->recv; rx = &msg_to->packet;
rx->len = n; rx->len = n;
rx->port = 0; rx->port = 0;
memcpy((void *)rx->data, (void *)buf, n); memcpy((void *)rx->data, (void *)buf, n);
// WMB(); SimbricksNetIfOutSend(&nsifs[port], msg_to, SIMBRICKS_PROTO_NET_MSG_PACKET);
rx->own_type =
SIMBRICKS_PROTO_NET_N2D_MSG_RECV | SIMBRICKS_PROTO_NET_N2D_OWN_DEV;
} else { } else {
fprintf(stderr, "switch_to_dev: dropping packet\n"); fprintf(stderr, "switch_to_dev: dropping packet\n");
} }
...@@ -209,7 +204,7 @@ static void process_event(const struct event &e) { ...@@ -209,7 +204,7 @@ static void process_event(const struct event &e) {
for (const auto &pkt : get_tofino_output()) { for (const auto &pkt : get_tofino_output()) {
if (pkt.port < nsifs.size()) { if (pkt.port < nsifs.size()) {
auto &nsif = nsifs.at(pkt.port); auto &nsif = nsifs.at(pkt.port);
if (nsif.sync) { if (SimbricksBaseIfSyncEnabled(&nsif.base)) {
struct event de; struct event de;
de.time = cur_ts + pkt.latency; de.time = cur_ts + pkt.latency;
de.to_switch = false; de.to_switch = false;
...@@ -231,22 +226,23 @@ static void process_event(const struct event &e) { ...@@ -231,22 +226,23 @@ static void process_event(const struct event &e) {
static void recv_from_peer(int port) { static void recv_from_peer(int port) {
struct SimbricksNetIf *nsif = &nsifs.at(port); struct SimbricksNetIf *nsif = &nsifs.at(port);
volatile union SimbricksProtoNetD2N *msg_from = volatile union SimbricksProtoNetMsg *msg_from =
SimbricksNetIfD2NPoll(nsif, cur_ts); SimbricksNetIfInPoll(nsif, cur_ts);
if (msg_from == nullptr) { if (msg_from == nullptr) {
return; return;
} }
uint8_t type = msg_from->dummy.own_type & SIMBRICKS_PROTO_NET_D2N_MSG_MASK; uint8_t type = SimbricksNetIfInType(nsif, msg_from);
if (type == SIMBRICKS_PROTO_NET_D2N_MSG_SEND) { if (type == SIMBRICKS_PROTO_NET_MSG_PACKET) {
struct event e; struct event e;
e.time = msg_from->send.timestamp; e.time = msg_from->packet.timestamp;
e.to_switch = true; e.to_switch = true;
e.port = port; e.port = port;
e.msg = std::string((const char *)msg_from->send.data, msg_from->send.len); e.msg = std::string((const char *)msg_from->packet.data,
msg_from->packet.len);
#ifdef DEBUG #ifdef DEBUG
printf("received packet from peer %u at time %llu\n", port, e.time); printf("received packet from peer %u at time %llu\n", port, e.time);
#endif #endif
if (nsif->sync) { if (SimbricksBaseIfSyncEnabled(&nsif->base)) {
event_queue.push(e); event_queue.push(e);
#ifdef DEBUG #ifdef DEBUG
printf("add to_switch event from peer %u at time %llu to queue\n", port, printf("add to_switch event from peer %u at time %llu to queue\n", port,
...@@ -255,12 +251,12 @@ static void recv_from_peer(int port) { ...@@ -255,12 +251,12 @@ static void recv_from_peer(int port) {
} else { } else {
process_event(e); process_event(e);
} }
} else if (type == SIMBRICKS_PROTO_NET_D2N_MSG_SYNC) { } else if (type == SIMBRICKS_PROTO_MSG_TYPE_SYNC) {
} else { } else {
fprintf(stderr, "tofino: unsupported type=%u\n", type); fprintf(stderr, "tofino: unsupported type=%u\n", type);
abort(); abort();
} }
SimbricksNetIfD2NDone(nsif, msg_from); SimbricksNetIfInDone(nsif, msg_from);
} }
static void process_event_queue() { static void process_event_queue() {
...@@ -280,13 +276,16 @@ int main(int argc, char *argv[]) { ...@@ -280,13 +276,16 @@ int main(int argc, char *argv[]) {
int bad_option = 0; int bad_option = 0;
int sync = 1; int sync = 1;
std::string tofino_log; std::string tofino_log;
struct SimbricksBaseIfParams params;
SimbricksNetIfDefaultParams(&params);
// Parse command line argument // Parse command line argument
while ((c = getopt(argc, argv, "s:S:E:m:t:u")) != -1 && !bad_option) { while ((c = getopt(argc, argv, "s:S:E:t:u")) != -1 && !bad_option) {
switch (c) { switch (c) {
case 's': case 's':
struct SimbricksNetIf nsif; struct SimbricksNetIf nsif;
if (SimbricksNetIfInit(&nsif, optarg, &sync) != 0) { if (SimbricksNetIfInit(&nsif, &params, optarg, &sync) != 0) {
fprintf(stderr, "connecting to %s failed\n", optarg); fprintf(stderr, "connecting to %s failed\n", optarg);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -294,17 +293,11 @@ int main(int argc, char *argv[]) { ...@@ -294,17 +293,11 @@ int main(int argc, char *argv[]) {
break; break;
case 'S': case 'S':
sync_period = strtoull(optarg, NULL, 0) * 1000ULL; params.sync_interval = strtoull(optarg, NULL, 0) * 1000ULL;
break; break;
case 'E': case 'E':
eth_latency = strtoull(optarg, NULL, 0) * 1000ULL; params.link_latency = strtoull(optarg, NULL, 0) * 1000ULL;
break;
case 'm':
sync_mode = strtol(optarg, NULL, 0);
assert(sync_mode == SIMBRICKS_PROTO_SYNC_SIMBRICKS ||
sync_mode == SIMBRICKS_PROTO_SYNC_BARRIER);
break; break;
case 't': case 't':
...@@ -322,12 +315,6 @@ int main(int argc, char *argv[]) { ...@@ -322,12 +315,6 @@ int main(int argc, char *argv[]) {
} }
} }
if (!sync) {
for (auto &nsif : nsifs) {
nsif.sync = 0;
}
}
if (nsifs.empty() || tofino_log.empty() || bad_option) { if (nsifs.empty() || tofino_log.empty() || bad_option) {
fprintf(stderr, fprintf(stderr,
"Usage: tofino [-S SYNC-PERIOD] [-E ETH-LATENCY] " "Usage: tofino [-S SYNC-PERIOD] [-E ETH-LATENCY] "
...@@ -392,13 +379,11 @@ int main(int argc, char *argv[]) { ...@@ -392,13 +379,11 @@ int main(int argc, char *argv[]) {
while (!exiting) { while (!exiting) {
// Sync all interfaces // Sync all interfaces
for (auto &nsif : nsifs) { for (auto &nsif : nsifs) {
if (SimbricksNetIfN2DSync(&nsif, cur_ts, eth_latency, sync_period, if (SimbricksNetIfOutSync(&nsif, cur_ts) != 0) {
sync_mode) != 0) {
fprintf(stderr, "SimbricksNetIfN2DSync failed\n"); fprintf(stderr, "SimbricksNetIfN2DSync failed\n");
abort(); abort();
} }
} }
SimbricksNetIfAdvanceEpoch(cur_ts, sync_period, sync_mode);
// Switch packets // Switch packets
ts_t min_ts = 0; ts_t min_ts = 0;
...@@ -410,7 +395,7 @@ int main(int argc, char *argv[]) { ...@@ -410,7 +395,7 @@ int main(int argc, char *argv[]) {
process_event_queue(); process_event_queue();
} }
if (min_ts > cur_ts) { if (min_ts > cur_ts) {
cur_ts = SimbricksNetIfAdvanceTime(min_ts, sync_period, sync_mode); cur_ts = min_ts;
} }
} }
......
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