Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
ab151b01
Commit
ab151b01
authored
Aug 05, 2021
by
Hejing Li
Browse files
net_switch: print stats
parent
71f62f2d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
sims/net/switch/net_switch.cc
sims/net/switch/net_switch.cc
+66
-0
No files found.
sims/net/switch/net_switch.cc
View file @
ab151b01
...
@@ -43,11 +43,27 @@ extern "C" {
...
@@ -43,11 +43,27 @@ extern "C" {
};
};
//#define NETSWITCH_DEBUG
//#define NETSWITCH_DEBUG
#define NETSWITCH_STAT
static
uint64_t
sync_period
=
(
500
*
1000ULL
);
// 500ns
static
uint64_t
sync_period
=
(
500
*
1000ULL
);
// 500ns
static
uint64_t
eth_latency
=
(
500
*
1000ULL
);
// 500ns
static
uint64_t
eth_latency
=
(
500
*
1000ULL
);
// 500ns
static
pcap_dumper_t
*
dumpfile
=
nullptr
;
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 */
/* MAC address type */
struct
MAC
{
struct
MAC
{
const
volatile
uint8_t
*
data
;
const
volatile
uint8_t
*
data
;
...
@@ -89,6 +105,16 @@ static void sigint_handler(int dummy) {
...
@@ -89,6 +105,16 @@ static void sigint_handler(int dummy) {
exiting
=
1
;
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
,
static
void
forward_pkt
(
volatile
struct
SimbricksProtoNetD2NSend
*
tx
,
size_t
port
)
{
size_t
port
)
{
volatile
union
SimbricksProtoNetN2D
*
msg_to
;
volatile
union
SimbricksProtoNetN2D
*
msg_to
;
...
@@ -148,10 +174,24 @@ static void forward_pkt(volatile struct SimbricksProtoNetD2NSend *tx,
...
@@ -148,10 +174,24 @@ static void forward_pkt(volatile struct SimbricksProtoNetD2NSend *tx,
static
void
switch_pkt
(
struct
SimbricksNetIf
*
nsif
,
size_t
iport
)
{
static
void
switch_pkt
(
struct
SimbricksNetIf
*
nsif
,
size_t
iport
)
{
volatile
union
SimbricksProtoNetD2N
*
msg_from
=
volatile
union
SimbricksProtoNetD2N
*
msg_from
=
SimbricksNetIfD2NPoll
(
nsif
,
cur_ts
);
SimbricksNetIfD2NPoll
(
nsif
,
cur_ts
);
#ifdef NETSWITCH_STAT
d2n_poll_total
+=
1
;
if
(
stat_flag
){
s_d2n_poll_total
+=
1
;
}
#endif
if
(
msg_from
==
NULL
)
{
if
(
msg_from
==
NULL
)
{
return
;
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
;
uint8_t
type
=
msg_from
->
dummy
.
own_type
&
SIMBRICKS_PROTO_NET_D2N_MSG_MASK
;
if
(
type
==
SIMBRICKS_PROTO_NET_D2N_MSG_SEND
)
{
if
(
type
==
SIMBRICKS_PROTO_NET_D2N_MSG_SEND
)
{
volatile
struct
SimbricksProtoNetD2NSend
*
tx
;
volatile
struct
SimbricksProtoNetD2NSend
*
tx
;
...
@@ -176,6 +216,12 @@ static void switch_pkt(struct SimbricksNetIf *nsif, size_t iport) {
...
@@ -176,6 +216,12 @@ static void switch_pkt(struct SimbricksNetIf *nsif, size_t iport) {
}
}
}
}
}
else
if
(
type
==
SIMBRICKS_PROTO_NET_D2N_MSG_SYNC
)
{
}
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
{
}
else
{
fprintf
(
stderr
,
"switch_pkt: unsupported type=%u
\n
"
,
type
);
fprintf
(
stderr
,
"switch_pkt: unsupported type=%u
\n
"
,
type
);
abort
();
abort
();
...
@@ -244,6 +290,12 @@ int main(int argc, char *argv[]) {
...
@@ -244,6 +290,12 @@ int main(int argc, char *argv[]) {
signal
(
SIGINT
,
sigint_handler
);
signal
(
SIGINT
,
sigint_handler
);
signal
(
SIGTERM
,
sigint_handler
);
signal
(
SIGTERM
,
sigint_handler
);
signal
(
SIGUSR1
,
sigusr1_handler
);
#ifdef NETSWITCH_STAT
signal
(
SIGUSR2
,
sigusr2_handler
);
#endif
printf
(
"start polling
\n
"
);
printf
(
"start polling
\n
"
);
while
(
!
exiting
)
{
while
(
!
exiting
)
{
...
@@ -277,5 +329,19 @@ int main(int argc, char *argv[]) {
...
@@ -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
;
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment