Commit ab151b01 authored by Hejing Li's avatar Hejing Li
Browse files

net_switch: print stats

parent 71f62f2d
......@@ -43,11 +43,27 @@ extern "C" {
};
//#define NETSWITCH_DEBUG
#define NETSWITCH_STAT
static uint64_t sync_period = (500 * 1000ULL); // 500ns
static uint64_t eth_latency = (500 * 1000ULL); // 500ns
static pcap_dumper_t *dumpfile = nullptr;
#ifdef NETSWITCH_STAT
#endif
#ifdef NETSWITCH_STAT
static uint64_t d2n_poll_total = 0;
static uint64_t d2n_poll_suc = 0;
static uint64_t d2n_poll_sync = 0;
static uint64_t s_d2n_poll_total = 0;
static uint64_t s_d2n_poll_suc = 0;
static uint64_t s_d2n_poll_sync = 0;
static int stat_flag = 0;
#endif
/* MAC address type */
struct MAC {
const volatile uint8_t *data;
......@@ -89,6 +105,16 @@ static void sigint_handler(int dummy) {
exiting = 1;
}
static void sigusr1_handler(int dummy) {
fprintf(stderr, "main_time = %lu\n", cur_ts);
}
#ifdef NETSWITCH_STAT
static void sigusr2_handler(int dummy) {
stat_flag = 1;
}
#endif
static void forward_pkt(volatile struct SimbricksProtoNetD2NSend *tx,
size_t port) {
volatile union SimbricksProtoNetN2D *msg_to;
......@@ -148,10 +174,24 @@ static void forward_pkt(volatile struct SimbricksProtoNetD2NSend *tx,
static void switch_pkt(struct SimbricksNetIf *nsif, size_t iport) {
volatile union SimbricksProtoNetD2N *msg_from =
SimbricksNetIfD2NPoll(nsif, cur_ts);
#ifdef NETSWITCH_STAT
d2n_poll_total += 1;
if (stat_flag){
s_d2n_poll_total += 1;
}
#endif
if (msg_from == NULL) {
return;
}
#ifdef NETSWITCH_STAT
d2n_poll_suc += 1;
if (stat_flag){
s_d2n_poll_suc += 1;
}
#endif
uint8_t type = msg_from->dummy.own_type & SIMBRICKS_PROTO_NET_D2N_MSG_MASK;
if (type == SIMBRICKS_PROTO_NET_D2N_MSG_SEND) {
volatile struct SimbricksProtoNetD2NSend *tx;
......@@ -176,6 +216,12 @@ static void switch_pkt(struct SimbricksNetIf *nsif, size_t iport) {
}
}
} else if (type == SIMBRICKS_PROTO_NET_D2N_MSG_SYNC) {
#ifdef NETSWITCH_STAT
d2n_poll_sync += 1;
if (stat_flag){
s_d2n_poll_sync += 1;
}
#endif
} else {
fprintf(stderr, "switch_pkt: unsupported type=%u\n", type);
abort();
......@@ -244,6 +290,12 @@ int main(int argc, char *argv[]) {
signal(SIGINT, sigint_handler);
signal(SIGTERM, sigint_handler);
signal(SIGUSR1, sigusr1_handler);
#ifdef NETSWITCH_STAT
signal(SIGUSR2, sigusr2_handler);
#endif
printf("start polling\n");
while (!exiting) {
......@@ -277,5 +329,19 @@ int main(int argc, char *argv[]) {
}
}
#ifdef NETSWITCH_STAT
fprintf(stderr, "%20s: %22lu %20s: %22lu poll_suc_rate: %f\n",
"d2n_poll_total", d2n_poll_total, "d2n_poll_suc", d2n_poll_suc,
(double)d2n_poll_suc / d2n_poll_total);
fprintf(stderr, "%65s: %22lu sync_rate: %f\n", "d2n_poll_sync",
d2n_poll_sync, (double)d2n_poll_sync / d2n_poll_suc);
fprintf(stderr, "%20s: %22lu %20s: %22lu poll_suc_rate: %f\n",
"s_d2n_poll_total", s_d2n_poll_total, "s_d2n_poll_suc", s_d2n_poll_suc,
(double)s_d2n_poll_suc / s_d2n_poll_total);
fprintf(stderr, "%65s: %22lu sync_rate: %f\n", "s_d2n_poll_sync",
s_d2n_poll_sync, (double)s_d2n_poll_sync / s_d2n_poll_suc);
#endif
return 0;
}
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