Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[WIP] Parameterized NIC #20

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/scala/example/Configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class WithSimBlockDevice extends Config((site, here, up) => {
})

class WithLoopbackNIC extends Config((site, here, up) => {
case NICKey => NICConfig(inBufPackets = 10)
case NICKey => NICConfig(NET_IF_WIDTH_BITS = 64, inBufPackets = 10)
case BuildTop => (clock: Clock, reset: Bool, p: Parameters) => {
val top = Module(LazyModule(new ExampleTopWithIceNIC()(p)).module)
top.connectNicLoopback()
Expand All @@ -56,7 +56,7 @@ class WithLoopbackNIC extends Config((site, here, up) => {
})

class WithSimNetwork extends Config((site, here, up) => {
case NICKey => NICConfig(inBufPackets = 10)
case NICKey => NICConfig(NET_IF_WIDTH_BITS = 64, inBufPackets = 10)
case BuildTop => (clock: Clock, reset: Bool, p: Parameters) => {
val top = Module(LazyModule(new ExampleTopWithIceNIC()(p)).module)
top.connectSimNetwork(clock, reset)
Expand Down
146 changes: 81 additions & 65 deletions tests/nic-loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,81 +18,97 @@ uint64_t lengths[NPACKETS];

static inline void send_recv()
{
uint64_t send_packet, recv_addr;
int ncomps, send_comps_left = NPACKETS, recv_comps_left = NPACKETS;
int recv_idx = 0;

for (int i = 0; i < NPACKETS; i++) {
uint64_t pkt_size = TEST_LEN * sizeof(uint32_t);
uint64_t src_addr = (uint64_t) &src[i][TEST_OFFSET];
send_packet = (pkt_size << 48) | src_addr;
recv_addr = (uint64_t) dst[i];
reg_write64(SIMPLENIC_SEND_REQ, send_packet);
reg_write64(SIMPLENIC_RECV_REQ, recv_addr);
}

while (send_comps_left > 0 || recv_comps_left > 0) {
ncomps = nic_send_comp_avail();
asm volatile ("fence");
for (int i = 0; i < ncomps; i++)
reg_read16(SIMPLENIC_SEND_COMP);
send_comps_left -= ncomps;

ncomps = nic_recv_comp_avail();
asm volatile ("fence");
for (int i = 0; i < ncomps; i++) {
lengths[recv_idx] = reg_read16(SIMPLENIC_RECV_COMP);
recv_idx++;
}
recv_comps_left -= ncomps;
}
uint64_t send_packet, recv_addr;
int ncomps, send_comps_left = NPACKETS, recv_comps_left = NPACKETS;
int recv_idx = 0;

// send requests to NIC
for (int i = 0; i < NPACKETS; i++) {
uint64_t pkt_size = TEST_LEN * sizeof(uint32_t);
uint64_t src_addr = (uint64_t) &src[i][TEST_OFFSET];
send_packet = (pkt_size << 48) | src_addr;
recv_addr = (uint64_t) dst[i];
printf("send_packet: (pkt_size, src_addr)=(%lu, %p)\n", pkt_size, (uint64_t*)src_addr);
printf("recv_addr: (%p)\n", (uint64_t*)recv_addr);
reg_write64(SIMPLENIC_SEND_REQ, send_packet);
printf("write to send req q successfull\n");
reg_write64(SIMPLENIC_RECV_REQ, recv_addr);
printf("write to recv req q successfull\n");
}

while (send_comps_left > 0 || recv_comps_left > 0) {
ncomps = nic_send_comp_avail();
printf("ncomps(%d)\n", ncomps);
asm volatile ("fence");
for (int i = 0; i < ncomps; i++)
reg_read16(SIMPLENIC_SEND_COMP);
send_comps_left -= ncomps;
printf("sendCompsLeft(%d)\n", send_comps_left);

ncomps = nic_recv_comp_avail();
printf("ncomps(%d)\n", ncomps);
asm volatile ("fence");
for (int i = 0; i < ncomps; i++) {
lengths[recv_idx] = reg_read16(SIMPLENIC_RECV_COMP);
recv_idx++;
}
recv_comps_left -= ncomps;
printf("recvCompsLeft(%d)\n", recv_comps_left);
}
}

void run_test(void)
{
unsigned long start, end;
int i, j;

memset(dst, 0, sizeof(dst));
asm volatile ("fence");

start = rdcycle();
send_recv();
end = rdcycle();

printf("send/recv %lu cycles\n", end - start);

for (i = 0; i < NPACKETS; i++) {
if (lengths[i] != TEST_LEN * sizeof(uint32_t)) {
printf("recv got wrong # bytes\n");
exit(EXIT_FAILURE);
}

for (j = 0; j < TEST_LEN; j++) {
if (dst[i][j] != src[i][j + TEST_OFFSET]) {
printf("Data mismatch @ %d, %d: %x != %x\n",
i, j, dst[i][j], src[i][j + TEST_OFFSET]);
exit(EXIT_FAILURE);
}
}
}
unsigned long start, end;
int i, j, idx;

// clear destination buffer
memset(dst, 0, sizeof(dst));
asm volatile ("fence");

start = rdcycle();
send_recv();
end = rdcycle();

printf("send/recv %lu cycles\n", end - start);

for (i = 0; i < NPACKETS; i++) {
if (lengths[i] != TEST_LEN * sizeof(uint32_t)) {
printf("recv got wrong # bytes. expected %lu but got %lu on packet %d\n", TEST_LEN*sizeof(uint32_t), lengths[i], i);
exit(EXIT_FAILURE);
}

for (j = 0; j < TEST_LEN; j++) {
if (dst[i][j] != src[i][j + TEST_OFFSET]) {
// simple data dump for 32B
printf("Data mismatch @ %d, %d: 0x%x != 0x%x\n", i, j, dst[i][j], src[i][j + TEST_OFFSET]);
for(idx = 0; idx < 32; idx++) {
printf("recv[%d] = 0x%x src[%d] = 0x%x\n", idx, dst[i][idx], idx, src[i][idx + TEST_OFFSET]);
}
exit(EXIT_FAILURE);
}
}
}
}

int main(void)
{
int i, j;
int i, j;
printf("loopback test start:\n");

for (i = 0; i < NPACKETS; i++) {
for (j = 0; j < ARRAY_LEN; j++)
src[i][j] = i * ARRAY_LEN + j;
}
// setup data to be send over the network
for (i = 0; i < NPACKETS; i++) {
for (j = 0; j < ARRAY_LEN; j++)
src[i][j] = i * ARRAY_LEN + j;
}

for (i = 0; i < NTRIALS; i++) {
printf("Trial %d\n", i);
run_test();
}
// run the trials
for (i = 0; i < NTRIALS; i++) {
printf("Trial %d\n", i);
run_test();
}

printf("All correct\n");
printf("All correct\n");

return 0;
return 0;
}