Commit 12cca0cf authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

lib/proto: create base header with sync mode defines

parent 803110a8
......@@ -32,6 +32,7 @@
#include <simbricks/netif/netsim.h>
#include "lib/simbricks/netif/internal.h"
#include <simbricks/proto/base.h>
static uint64_t current_epoch = 0;
......@@ -144,11 +145,11 @@ int netsim_n2d_sync(struct netsim_interface *nsif, uint64_t timestamp,
return 0;
switch (sync_mode) {
case SYNC_MODES:
case SIMBRICKS_PROTO_SYNC_SIMBRICKS:
do_sync = nsif->n2d_timestamp == 0 ||
timestamp - nsif->n2d_timestamp >= sync_delay;
break;
case SYNC_BARRIER:
case SIMBRICKS_PROTO_SYNC_BARRIER:
do_sync = current_epoch == 0 || timestamp - current_epoch >= sync_delay;
break;
default:
......@@ -174,7 +175,7 @@ int netsim_n2d_sync(struct netsim_interface *nsif, uint64_t timestamp,
void netsim_advance_epoch(uint64_t timestamp, uint64_t sync_delay,
int sync_mode) {
if (sync_mode == SYNC_BARRIER) {
if (sync_mode == SIMBRICKS_PROTO_SYNC_BARRIER) {
if (timestamp - current_epoch >= sync_delay) {
current_epoch = timestamp;
}
......@@ -184,9 +185,9 @@ void netsim_advance_epoch(uint64_t timestamp, uint64_t sync_delay,
uint64_t netsim_advance_time(uint64_t timestamp, uint64_t sync_delay,
int sync_mode) {
switch (sync_mode) {
case SYNC_MODES:
case SIMBRICKS_PROTO_SYNC_SIMBRICKS:
return timestamp;
case SYNC_BARRIER:
case SIMBRICKS_PROTO_SYNC_BARRIER:
return timestamp < current_epoch + sync_delay
? timestamp
: current_epoch + sync_delay;
......
......@@ -30,9 +30,6 @@
#include <simbricks/proto/network.h>
#define SYNC_MODES 0
#define SYNC_BARRIER 1
struct netsim_interface {
uint8_t *d2n_queue;
size_t d2n_pos;
......
......@@ -35,6 +35,10 @@
#include <ctime>
#include <iostream>
extern "C" {
#include <simbricks/proto/base.h>
}
// #define DEBUG_NICBM 1
#define DMA_MAX_PENDING 64
......@@ -394,7 +398,7 @@ int Runner::runMain(int argc, char *argv[]) {
uint64_t sync_period = 100 * 1000ULL;
uint64_t pci_latency = 500 * 1000ULL;
uint64_t eth_latency = 500 * 1000ULL;
int sync_mode = SYNC_MODES;
int sync_mode = SIMBRICKS_PROTO_SYNC_SIMBRICKS;
if (argc < 4 && argc > 9) {
fprintf(stderr,
......@@ -428,7 +432,8 @@ int Runner::runMain(int argc, char *argv[]) {
nsparams.pci_latency = pci_latency;
nsparams.eth_latency = eth_latency;
nsparams.sync_delay = sync_period;
assert(sync_mode == SYNC_MODES || sync_mode == SYNC_BARRIER);
assert(sync_mode == SIMBRICKS_PROTO_SYNC_SIMBRICKS ||
sync_mode == SIMBRICKS_PROTO_SYNC_BARRIER);
nsparams.sync_mode = sync_mode;
if (nicsim_init(&nsparams, &dintro)) {
......
......@@ -32,6 +32,7 @@
#include <simbricks/nicif/nicsim.h>
#include "lib/simbricks/nicif/internal.h"
#include <simbricks/proto/base.h>
#define D2H_ELEN (9024 + 64)
#define D2H_ENUM 1024
......@@ -259,11 +260,11 @@ int nicsim_sync(struct nicsim_params *params, uint64_t timestamp) {
if (params->sync_pci) {
int sync;
switch (params->sync_mode) {
case SYNC_MODES:
case SIMBRICKS_PROTO_SYNC_SIMBRICKS:
sync = pci_last_tx_time == 0 ||
timestamp - pci_last_tx_time >= params->sync_delay;
break;
case SYNC_BARRIER:
case SIMBRICKS_PROTO_SYNC_BARRIER:
sync = current_epoch == 0 ||
timestamp - current_epoch >= params->sync_delay;
break;
......@@ -288,11 +289,11 @@ int nicsim_sync(struct nicsim_params *params, uint64_t timestamp) {
if (params->sync_eth) {
int sync;
switch (params->sync_mode) {
case SYNC_MODES:
case SIMBRICKS_PROTO_SYNC_SIMBRICKS:
sync = eth_last_tx_time == 0 ||
timestamp - eth_last_tx_time >= params->sync_delay;
break;
case SYNC_BARRIER:
case SIMBRICKS_PROTO_SYNC_BARRIER:
sync = current_epoch == 0 ||
timestamp - current_epoch >= params->sync_delay;
break;
......@@ -316,7 +317,7 @@ int nicsim_sync(struct nicsim_params *params, uint64_t timestamp) {
}
void nicsim_advance_epoch(struct nicsim_params *params, uint64_t timestamp) {
if (params->sync_mode == SYNC_BARRIER) {
if (params->sync_mode == SIMBRICKS_PROTO_SYNC_BARRIER) {
if ((params->sync_pci || params->sync_eth) &&
timestamp - current_epoch >= params->sync_delay) {
current_epoch = timestamp;
......@@ -326,9 +327,9 @@ void nicsim_advance_epoch(struct nicsim_params *params, uint64_t timestamp) {
uint64_t nicsim_advance_time(struct nicsim_params *params, uint64_t timestamp) {
switch (params->sync_mode) {
case SYNC_MODES:
case SIMBRICKS_PROTO_SYNC_SIMBRICKS:
return timestamp;
case SYNC_BARRIER:
case SIMBRICKS_PROTO_SYNC_BARRIER:
return timestamp < current_epoch + params->sync_delay
? timestamp
: current_epoch + params->sync_delay;
......
......@@ -28,9 +28,6 @@
#include <simbricks/proto/network.h>
#include <simbricks/proto/pcie.h>
#define SYNC_MODES 0 // ModES style synchronization
#define SYNC_BARRIER 1 // Global barrier style synchronization
struct nicsim_params {
const char *pci_socket_path;
const char *eth_socket_path;
......
/*
* Copyright 2021 Max Planck Institute for Software Systems, and
* National University of Singapore
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SIMBRICKS_PROTO_BASE_H_
#define SIMBRICKS_PROTO_BASE_H_
#define SIMBRICKS_PROTO_SYNC_SIMBRICKS 0
#define SIMBRICKS_PROTO_SYNC_BARRIER 1
#endif // SIMBRICKS_PROTO_BASE_H_
Subproject commit 3424c70bf8309fab93e8e4a76225452c9c967f58
Subproject commit 84aa4eeb7696741c355ca0b508c6760d90481710
Subproject commit a25e4b55426c5120acd204e4f293b1de7d7fe82b
Subproject commit 885a383bf495d94e9dcbf74557fc6cb1c0212090
......@@ -35,6 +35,7 @@
extern "C" {
#include <simbricks/netif/netsim.h>
#include <simbricks/proto/base.h>
};
static uint64_t sync_period = (500 * 1000ULL); // 500ns
......@@ -141,7 +142,7 @@ static void switch_pkt(struct netsim_interface *nsif, int iport) {
int main(int argc, char *argv[]) {
int c;
int bad_option = 0;
int sync_mode = SYNC_MODES;
int sync_mode = SIMBRICKS_PROTO_SYNC_SIMBRICKS;
// Parse command line argument
while ((c = getopt(argc, argv, "s:S:E:m:")) != -1 && !bad_option) {
......@@ -167,7 +168,8 @@ int main(int argc, char *argv[]) {
case 'm':
sync_mode = strtol(optarg, NULL, 0);
assert(sync_mode == SYNC_MODES || sync_mode == SYNC_BARRIER);
assert(sync_mode == SIMBRICKS_PROTO_SYNC_SIMBRICKS ||
sync_mode == SIMBRICKS_PROTO_SYNC_BARRIER);
break;
default:
......
......@@ -37,6 +37,7 @@
#include <unistd.h>
#include <simbricks/netif/netsim.h>
#include <simbricks/proto/base.h>
static uint64_t sync_period = (500 * 1000ULL); // 500ns
static uint64_t eth_latency = (500 * 1000ULL); // 500ns
......@@ -106,7 +107,7 @@ int main(int argc, char *argv[]) {
uint64_t ts_a, ts_b;
int sync_a, sync_b;
pcap_t *pc = NULL;
int sync_mode = SYNC_MODES;
int sync_mode = SIMBRICKS_PROTO_SYNC_SIMBRICKS;
if (argc < 3 && argc > 7) {
fprintf(stderr,
......@@ -139,7 +140,8 @@ int main(int argc, char *argv[]) {
dumpfile = pcap_dump_open(pc, argv[6]);
}
assert(sync_mode == SYNC_MODES || sync_mode == SYNC_BARRIER);
assert(sync_mode == SIMBRICKS_PROTO_SYNC_SIMBRICKS ||
sync_mode == SIMBRICKS_PROTO_SYNC_BARRIER);
sync_a = sync_b = 1;
if (netsim_init(&nsif_a, argv[1], &sync_a) != 0) {
......
......@@ -34,6 +34,7 @@
extern "C" {
#include <simbricks/nicif/nicsim.h>
#include <simbricks/proto/base.h>
#include <simbricks/proto/pcie.h>
}
......@@ -794,7 +795,7 @@ static void msi_step(Vinterface &top, PCICoordinator &coord) {
int main(int argc, char *argv[]) {
char *vargs[2] = {argv[0], NULL};
Verilated::commandArgs(1, vargs);
int sync_mode = SYNC_MODES;
int sync_mode = SIMBRICKS_PROTO_SYNC_SIMBRICKS;
#ifdef TRACE_ENABLED
Verilated::traceEverOn(true);
#endif
......@@ -840,7 +841,8 @@ int main(int argc, char *argv[]) {
nsparams.pci_latency = pci_latency;
nsparams.eth_latency = eth_latency;
nsparams.sync_delay = sync_period;
assert(sync_mode == SYNC_MODES || sync_mode == SYNC_BARRIER);
assert(sync_mode == SIMBRICKS_PROTO_SYNC_SIMBRICKS ||
sync_mode == SIMBRICKS_PROTO_SYNC_BARRIER);
nsparams.sync_mode = sync_mode;
if (nicsim_init(&nsparams, &di)) {
......
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