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
f9a3a2e6
Commit
f9a3a2e6
authored
Jun 24, 2022
by
Antoine Kaufmann
Committed by
Antoine Kaufmann
Jul 08, 2022
Browse files
reformat with clang-format
parent
e51835d1
Changes
38
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
227 additions
and
239 deletions
+227
-239
lib/simbricks/nicif/nicif.c
lib/simbricks/nicif/nicif.c
+3
-6
lib/simbricks/nicif/nicif.h
lib/simbricks/nicif/nicif.h
+7
-8
lib/simbricks/pcie/if.c
lib/simbricks/pcie/if.c
+1
-2
lib/simbricks/pcie/if.h
lib/simbricks/pcie/if.h
+3
-3
lib/simbricks/pcie/proto.h
lib/simbricks/pcie/proto.h
+0
-1
sims/net/menshen/menshen_hw.cc
sims/net/menshen/menshen_hw.cc
+19
-24
sims/net/pktgen/pktgen.cc
sims/net/pktgen/pktgen.cc
+72
-80
sims/net/switch/net_switch.cc
sims/net/switch/net_switch.cc
+48
-49
sims/net/tofino/tofino.cc
sims/net/tofino/tofino.cc
+5
-4
sims/net/wire/net_wire.c
sims/net/wire/net_wire.c
+0
-1
sims/nic/corundum/corundum_verilator.cc
sims/nic/corundum/corundum_verilator.cc
+22
-20
sims/nic/corundum_bm/corundum_bm.cc
sims/nic/corundum_bm/corundum_bm.cc
+14
-7
sims/nic/i40e_bm/i40e_bm.cc
sims/nic/i40e_bm/i40e_bm.cc
+4
-4
sims/nic/i40e_bm/i40e_lan.cc
sims/nic/i40e_bm/i40e_lan.cc
+3
-1
sims/nic/i40e_bm/logger.cc
sims/nic/i40e_bm/logger.cc
+2
-2
trace/events.h
trace/events.h
+2
-3
trace/log_parser.cc
trace/log_parser.cc
+5
-6
trace/process.cc
trace/process.cc
+17
-18
No files found.
lib/simbricks/nicif/nicif.c
View file @
f9a3a2e6
...
...
@@ -28,12 +28,10 @@
#include <stdio.h>
#include <string.h>
int
SimbricksNicIfInit
(
struct
SimbricksNicIf
*
nicif
,
const
char
*
shm_path
,
int
SimbricksNicIfInit
(
struct
SimbricksNicIf
*
nicif
,
const
char
*
shm_path
,
struct
SimbricksBaseIfParams
*
netParams
,
struct
SimbricksBaseIfParams
*
pcieParams
,
struct
SimbricksProtoPcieDevIntro
*
di
)
{
struct
SimbricksProtoPcieDevIntro
*
di
)
{
struct
SimbricksBaseIf
*
netif
=
&
nicif
->
net
.
base
;
struct
SimbricksBaseIf
*
pcieif
=
&
nicif
->
pcie
.
base
;
...
...
@@ -97,8 +95,7 @@ int SimbricksNicIfInit(struct SimbricksNicIf *nicif,
return
SimBricksBaseIfEstablish
(
ests
,
n_bifs
);
}
int
SimbricksNicIfCleanup
(
struct
SimbricksNicIf
*
nicif
)
{
int
SimbricksNicIfCleanup
(
struct
SimbricksNicIf
*
nicif
)
{
SimbricksBaseIfClose
(
&
nicif
->
pcie
.
base
);
SimbricksBaseIfClose
(
&
nicif
->
net
.
base
);
/* TODO: unlink? */
...
...
lib/simbricks/nicif/nicif.h
View file @
f9a3a2e6
...
...
@@ -37,9 +37,7 @@ struct SimbricksNicIf {
struct
SimbricksPcieIf
pcie
;
};
int
SimbricksNicIfInit
(
struct
SimbricksNicIf
*
nicif
,
const
char
*
shmPath
,
int
SimbricksNicIfInit
(
struct
SimbricksNicIf
*
nicif
,
const
char
*
shmPath
,
struct
SimbricksBaseIfParams
*
netParams
,
struct
SimbricksBaseIfParams
*
pcieParams
,
struct
SimbricksProtoPcieDevIntro
*
di
);
...
...
@@ -47,14 +45,15 @@ int SimbricksNicIfInit(struct SimbricksNicIf *nicif,
int
SimbricksNicIfCleanup
(
struct
SimbricksNicIf
*
nicif
);
static
inline
int
SimbricksNicIfSync
(
struct
SimbricksNicIf
*
nicif
,
uint64_t
cur_ts
)
{
uint64_t
cur_ts
)
{
return
((
SimbricksNetIfOutSync
(
&
nicif
->
net
,
cur_ts
)
==
0
&&
SimbricksPcieIfD2HOutSync
(
&
nicif
->
pcie
,
cur_ts
)
==
0
)
?
0
:
-
1
);
SimbricksPcieIfD2HOutSync
(
&
nicif
->
pcie
,
cur_ts
)
==
0
)
?
0
:
-
1
);
}
static
inline
uint64_t
SimbricksNicIfNextTimestamp
(
struct
SimbricksNicIf
*
nicif
)
{
static
inline
uint64_t
SimbricksNicIfNextTimestamp
(
struct
SimbricksNicIf
*
nicif
)
{
uint64_t
net_in
=
SimbricksNetIfInTimestamp
(
&
nicif
->
net
);
uint64_t
net_out
=
SimbricksNetIfOutNextSync
(
&
nicif
->
net
);
uint64_t
net
=
(
net_in
<=
net_out
?
net_in
:
net_out
);
...
...
lib/simbricks/pcie/if.c
View file @
f9a3a2e6
...
...
@@ -24,8 +24,7 @@
#include "lib/simbricks/pcie/if.h"
void
SimbricksPcieIfDefaultParams
(
struct
SimbricksBaseIfParams
*
params
)
{
void
SimbricksPcieIfDefaultParams
(
struct
SimbricksBaseIfParams
*
params
)
{
SimbricksBaseIfDefaultParams
(
params
);
params
->
upper_layer_proto
=
SIMBRICKS_PROTO_ID_PCIE
;
params
->
in_entries_size
=
params
->
out_entries_size
=
9024
+
64
;
...
...
lib/simbricks/pcie/if.h
View file @
f9a3a2e6
...
...
@@ -28,8 +28,8 @@
#include <stddef.h>
#include <stdint.h>
#include <simbricks/base/if.h>
#include <simbricks/base/generic.h>
#include <simbricks/base/if.h>
#include <simbricks/pcie/proto.h>
void
SimbricksPcieIfDefaultParams
(
struct
SimbricksBaseIfParams
*
params
);
...
...
@@ -40,8 +40,8 @@ struct SimbricksPcieIf {
/** Generate queue access functions for both directions */
SIMBRICKS_BASEIF_GENERIC
(
SimbricksPcieIfH2D
,
SimbricksProtoPcieH2D
,
SimbricksPcieIf
);
SimbricksPcieIf
);
SIMBRICKS_BASEIF_GENERIC
(
SimbricksPcieIfD2H
,
SimbricksProtoPcieD2H
,
SimbricksPcieIf
);
SimbricksPcieIf
);
#endif // SIMBRICKS_PCIE_IF_H_
lib/simbricks/pcie/proto.h
View file @
f9a3a2e6
...
...
@@ -89,7 +89,6 @@ struct SimbricksProtoPcieDevIntro {
uint16_t
psi_msix_cap_offset
;
}
__attribute__
((
packed
));
/** welcome message sent by host to device */
struct
SimbricksProtoPcieHostIntro
{
uint32_t
dummy
;
/* not used, but need to avoid empty struct for standard C */
...
...
sims/net/menshen/menshen_hw.cc
View file @
f9a3a2e6
#include <signal.h>
#include <verilated.h>
#include <verilated_fst_c.h>
#include <iostream>
#include <signal.h>
#include <vector>
#include "sims/net/menshen/obj_dir/Vrmt_wrapper.h"
...
...
@@ -21,7 +21,7 @@ int synchronized = 0;
uint64_t
sync_period
=
(
500
*
1000ULL
);
// 500ns
uint64_t
eth_latency
=
(
500
*
1000ULL
);
// 500ns
int
sync_mode
=
SIMBRICKS_PROTO_SYNC_SIMBRICKS
;
static
uint64_t
clock_period
=
4
*
1000ULL
;
// 4ns -> 250MHz
static
uint64_t
clock_period
=
4
*
1000ULL
;
// 4ns -> 250MHz
uint64_t
main_time
=
0
;
int
exiting
=
0
;
EthernetTx
*
txMAC
;
...
...
@@ -61,19 +61,16 @@ static void dump_if(Vrmt_wrapper *top) {
std
::
cout
<<
" vlan_drop_flags = "
<<
top
->
vlan_drop_flags
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
" s_axis_tdata = { "
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
top
->
s_axis_tdata
)
/
sizeof
(
top
->
s_axis_tdata
[
0
]);
i
++
)
{
i
<
sizeof
(
top
->
s_axis_tdata
)
/
sizeof
(
top
->
s_axis_tdata
[
0
]);
i
++
)
{
std
::
cout
<<
top
->
s_axis_tdata
[
i
]
<<
" "
;
}
std
::
cout
<<
"}"
<<
std
::
endl
;
std
::
cout
<<
" s_axis_tkeep = "
<<
top
->
s_axis_tkeep
<<
std
::
endl
;
std
::
cout
<<
" s_axis_tuser = { "
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
top
->
s_axis_tuser
)
/
sizeof
(
top
->
s_axis_tuser
[
0
]);
i
++
)
{
i
<
sizeof
(
top
->
s_axis_tuser
)
/
sizeof
(
top
->
s_axis_tuser
[
0
]);
i
++
)
{
std
::
cout
<<
top
->
s_axis_tuser
[
i
]
<<
" "
;
}
std
::
cout
<<
"}"
<<
std
::
endl
;
...
...
@@ -82,19 +79,16 @@ static void dump_if(Vrmt_wrapper *top) {
std
::
cout
<<
" s_axis_tlast = "
<<
top
->
s_axis_tlast
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
" m_axis_tdata = { "
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
top
->
m_axis_tdata
)
/
sizeof
(
top
->
m_axis_tdata
[
0
]);
i
++
)
{
i
<
sizeof
(
top
->
m_axis_tdata
)
/
sizeof
(
top
->
m_axis_tdata
[
0
]);
i
++
)
{
std
::
cout
<<
top
->
m_axis_tdata
[
i
]
<<
" "
;
}
std
::
cout
<<
"}"
<<
std
::
endl
;
std
::
cout
<<
" m_axis_tkeep = "
<<
top
->
m_axis_tkeep
<<
std
::
endl
;
std
::
cout
<<
" m_axis_tuser = { "
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
top
->
m_axis_tuser
)
/
sizeof
(
top
->
m_axis_tuser
[
0
]);
i
++
)
{
i
<
sizeof
(
top
->
m_axis_tuser
)
/
sizeof
(
top
->
m_axis_tuser
[
0
]);
i
++
)
{
std
::
cout
<<
top
->
m_axis_tuser
[
i
]
<<
" "
;
}
std
::
cout
<<
"}"
<<
std
::
endl
;
...
...
@@ -116,7 +110,8 @@ class EthernetTx {
void
packet_done
(
uint16_t
port_id
)
{
if
(
port_id
>=
ports
.
size
())
{
#ifdef ETH_DEBUG
std
::
cerr
<<
"EthernetTx: invalid port set ("
<<
port_id
<<
"), setting to 0"
<<
std
::
endl
;
std
::
cerr
<<
"EthernetTx: invalid port set ("
<<
port_id
<<
"), setting to 0"
<<
std
::
endl
;
#endif
port_id
=
0
;
}
...
...
@@ -138,7 +133,7 @@ class EthernetTx {
if
(
top
.
m_axis_tvalid
)
{
/* iterate over all bytes on the bus */
uint8_t
*
txbus
=
(
uint8_t
*
)
&
top
.
m_axis_tdata
;
uint8_t
*
txbus
=
(
uint8_t
*
)
&
top
.
m_axis_tdata
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
top
.
m_axis_tdata
);
i
++
)
{
if
((
top
.
m_axis_tkeep
&
(
1ULL
<<
i
))
!=
0
)
{
assert
(
packet_len
<
2048
);
...
...
@@ -205,7 +200,8 @@ class EthernetRx {
if
(
packet_off
!=
0
&&
!
top
.
s_axis_tready
)
{
// no ready signal, can't advance
#ifdef ETH_DEBUG
std
::
cerr
<<
"eth rx: no ready "
<<
fifo_pos_rd
<<
" "
<<
packet_off
<<
std
::
endl
;
std
::
cerr
<<
"eth rx: no ready "
<<
fifo_pos_rd
<<
" "
<<
packet_off
<<
std
::
endl
;
#endif
}
else
if
(
packet_off
==
fifo_lens
[
fifo_pos_rd
])
{
// done with packet
...
...
@@ -228,7 +224,7 @@ class EthernetRx {
std
::
cout
<<
"rx from "
<<
fifo_pos_rd
<<
std
::
endl
;
#endif
top
.
s_axis_tkeep
=
0
;
uint8_t
*
rdata
=
(
uint8_t
*
)
&
top
.
s_axis_tdata
;
uint8_t
*
rdata
=
(
uint8_t
*
)
&
top
.
s_axis_tdata
;
size_t
i
;
/*if (packet_off == 0) {
...
...
@@ -236,13 +232,14 @@ class EthernetRx {
}*/
if
(
packet_off
==
0
)
top
.
s_axis_tuser
[
0
]
=
fifo_lens
[
fifo_pos_rd
]
|
(((
uint64_t
)
fifo_ports
[
fifo_pos_rd
])
<<
16
)
|
(((
uint64_t
)
fifo_ports
[
fifo_pos_rd
])
<<
24
);
(((
uint64_t
)
fifo_ports
[
fifo_pos_rd
])
<<
16
)
|
(((
uint64_t
)
fifo_ports
[
fifo_pos_rd
])
<<
24
);
else
top
.
s_axis_tuser
[
0
]
=
0
;
for
(
i
=
0
;
i
<
sizeof
(
top
.
s_axis_tdata
)
&&
packet_off
<
fifo_lens
[
fifo_pos_rd
];
i
++
)
{
packet_off
<
fifo_lens
[
fifo_pos_rd
];
i
++
)
{
rdata
[
i
]
=
fifo_bufs
[
fifo_pos_rd
][
packet_off
];
top
.
s_axis_tkeep
|=
(
1ULL
<<
i
);
packet_off
++
;
...
...
@@ -298,8 +295,8 @@ int main(int argc, char *argv[]) {
reset_inputs
(
top
);
top
->
aresetn
=
0
;
for
(
int
i
=
0
;
i
<
16
;
i
++
)
{
top
->
eval
();
top
->
clk
=
!
top
->
clk
;
top
->
eval
();
top
->
clk
=
!
top
->
clk
;
}
top
->
aresetn
=
1
;
...
...
@@ -321,7 +318,7 @@ int main(int argc, char *argv[]) {
}
ports
.
push_back
(
np
);
}
txMAC
=
new
EthernetTx
(
*
top
);
rxMAC
=
new
EthernetRx
(
*
top
);
...
...
@@ -363,7 +360,5 @@ int main(int argc, char *argv[]) {
#endif
dump_if
(
top
);
return
0
;
}
sims/net/pktgen/pktgen.cc
View file @
f9a3a2e6
...
...
@@ -22,11 +22,11 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <pcap/pcap.h>
#include <linux/ip.h>
#include <linux/if_ether.h>
#include <arpa/inet.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <pcap/pcap.h>
#include <unistd.h>
#include <cassert>
#include <climits>
...
...
@@ -49,15 +49,15 @@ extern "C" {
struct
SimbricksBaseIfParams
netParams
;
static
pcap_dumper_t
*
dumpfile
=
nullptr
;
#define PKT_LEN 1500 //byte
static
uint64_t
bit_rate
=
100
*
1000ULL
*
1000ULL
*
1000ULL
;
// 100 Gbps
static
uint64_t
target_tick
=
1
*
1000ULL
*
1000ULL
*
1000ULL
*
1000ULL
;
// 1s
#define PKT_LEN 1500
//
byte
static
uint64_t
bit_rate
=
100
*
1000ULL
*
1000ULL
*
1000ULL
;
// 100 Gbps
static
uint64_t
target_tick
=
1
*
1000ULL
*
1000ULL
*
1000ULL
*
1000ULL
;
// 1s
static
uint64_t
last_pkt_sent
=
0
;
static
uint64_t
pkt_recv_num
=
0
;
static
uint64_t
pkt_recv_byte
=
0
;
static
uint64_t
pkt_tx_num
=
0
;
static
uint64_t
pkt_tx_byte
=
0
;
static
uint64_t
period
=
(
1E12
*
8
*
PKT_LEN
)
/
bit_rate
;
// per packet
static
uint64_t
period
=
(
1E12
*
8
*
PKT_LEN
)
/
bit_rate
;
// per packet
static
uint8_t
packet
[
PKT_LEN
];
#ifdef NETSWITCH_STAT
...
...
@@ -92,7 +92,7 @@ struct MAC {
}
};
struct
mac_addr
{
struct
mac_addr
{
uint8_t
addr
[
6
];
};
...
...
@@ -109,7 +109,6 @@ struct hash<MAC> {
};
}
// namespace std
/** Abstract base switch port */
class
Port
{
public:
...
...
@@ -128,13 +127,12 @@ class Port {
virtual
bool
IsSync
()
=
0
;
virtual
void
Sync
(
uint64_t
cur_ts
)
=
0
;
virtual
uint64_t
NextTimestamp
()
=
0
;
virtual
enum
RxPollState
RxPacket
(
const
void
*&
data
,
size_t
&
len
,
uint64_t
cur_ts
)
=
0
;
virtual
enum
RxPollState
RxPacket
(
const
void
*&
data
,
size_t
&
len
,
uint64_t
cur_ts
)
=
0
;
virtual
void
RxDone
()
=
0
;
virtual
bool
TxPacket
(
const
void
*
data
,
size_t
len
,
uint64_t
cur_ts
)
=
0
;
};
/** Normal network switch port (conneting to a NIC) */
class
NetPort
:
public
Port
{
protected:
...
...
@@ -150,8 +148,12 @@ class NetPort : public Port {
memset
(
&
dest_mac
,
0
,
sizeof
(
dest_mac
));
}
NetPort
(
const
NetPort
&
other
)
:
netifObj_
(
other
.
netifObj_
),
netif_
(
&
netifObj_
),
rx_
(
other
.
rx_
),
sync_
(
other
.
sync_
)
{}
NetPort
(
const
NetPort
&
other
)
:
netifObj_
(
other
.
netifObj_
),
netif_
(
&
netifObj_
),
rx_
(
other
.
rx_
),
sync_
(
other
.
sync_
)
{
}
virtual
bool
Connect
(
const
char
*
path
,
int
sync
)
override
{
sync_
=
sync
;
...
...
@@ -163,15 +165,16 @@ class NetPort : public Port {
}
virtual
void
Sync
(
uint64_t
cur_ts
)
override
{
while
(
SimbricksNetIfOutSync
(
netif_
,
cur_ts
));
while
(
SimbricksNetIfOutSync
(
netif_
,
cur_ts
))
;
}
virtual
uint64_t
NextTimestamp
()
override
{
return
SimbricksNetIfInTimestamp
(
netif_
);
}
virtual
enum
RxPollState
RxPacket
(
const
void
*&
data
,
size_t
&
len
,
uint64_t
cur_ts
)
override
{
virtual
enum
RxPollState
RxPacket
(
const
void
*&
data
,
size_t
&
len
,
uint64_t
cur_ts
)
override
{
assert
(
rx_
==
nullptr
);
rx_
=
SimbricksNetIfInPoll
(
netif_
,
cur_ts
);
...
...
@@ -198,10 +201,10 @@ class NetPort : public Port {
rx_
=
nullptr
;
}
virtual
bool
TxPacket
(
const
void
*
data
,
size_t
len
,
uint64_t
cur_ts
)
override
{
virtual
bool
TxPacket
(
const
void
*
data
,
size_t
len
,
uint64_t
cur_ts
)
override
{
volatile
union
SimbricksProtoNetMsg
*
msg_to
=
SimbricksNetIfOutAlloc
(
netif_
,
cur_ts
);
SimbricksNetIfOutAlloc
(
netif_
,
cur_ts
);
if
(
!
msg_to
&&
!
sync_
)
{
return
false
;
}
else
if
(
!
msg_to
&&
sync_
)
{
...
...
@@ -219,7 +222,6 @@ class NetPort : public Port {
}
};
/** Hosting network switch port (connected to another network) */
class
NetHostPort
:
public
NetPort
{
protected:
...
...
@@ -244,7 +246,7 @@ class NetHostPort : public NetPort {
if
(
!
sync
)
params
.
sync_mode
=
kSimbricksBaseIfSyncDisabled
;
int
ret
=
SimbricksNicIfInit
(
&
nicif_
,
shm_path
.
c_str
(),
&
params
,
nullptr
,
nullptr
);
nullptr
);
sync_
=
SimbricksBaseIfSyncEnabled
(
&
netif_
->
base
);
return
ret
==
0
;
}
...
...
@@ -254,7 +256,6 @@ class NetHostPort : public NetPort {
}
};
/* Global variables */
static
uint64_t
cur_ts
=
0
;
static
int
exiting
=
0
;
...
...
@@ -283,12 +284,12 @@ static void forward_pkt(const void *pkt_data, size_t pkt_len, size_t port_id) {
// log to pcap file if initialized
if
(
dumpfile
)
{
memset
(
&
ph
,
0
,
sizeof
(
ph
));
ph
.
ts
.
tv_sec
=
cur_ts
/
1000000000000ULL
;
ph
.
ts
.
tv_usec
=
(
cur_ts
%
1000000000000ULL
)
/
1000ULL
;
ph
.
caplen
=
pkt_len
;
ph
.
len
=
pkt_len
;
pcap_dump
((
unsigned
char
*
)
dumpfile
,
&
ph
,
(
unsigned
char
*
)
pkt_data
);
memset
(
&
ph
,
0
,
sizeof
(
ph
));
ph
.
ts
.
tv_sec
=
cur_ts
/
1000000000000ULL
;
ph
.
ts
.
tv_usec
=
(
cur_ts
%
1000000000000ULL
)
/
1000ULL
;
ph
.
caplen
=
pkt_len
;
ph
.
len
=
pkt_len
;
pcap_dump
((
unsigned
char
*
)
dumpfile
,
&
ph
,
(
unsigned
char
*
)
pkt_data
);
}
// print sending tick: [packet type] source_IP -> dest_IP len:
...
...
@@ -296,22 +297,21 @@ static void forward_pkt(const void *pkt_data, size_t pkt_len, size_t port_id) {
uint16_t
eth_proto
;
struct
ethhdr
*
hdr
;
struct
iphdr
*
iph
;
hdr
=
(
struct
ethhdr
*
)
pkt_data
;
hdr
=
(
struct
ethhdr
*
)
pkt_data
;
eth_proto
=
ntohs
(
hdr
->
h_proto
);
iph
=
(
struct
iphdr
*
)(
hdr
+
1
);
fprintf
(
stderr
,
"%20lu: "
,
cur_ts
);
if
(
eth_proto
==
ETH_P_IP
){
if
(
eth_proto
==
ETH_P_IP
)
{
fprintf
(
stderr
,
"[ IP] "
);
}
else
if
(
eth_proto
==
ETH_P_ARP
){
}
else
if
(
eth_proto
==
ETH_P_ARP
)
{
fprintf
(
stderr
,
"[ARP] "
);
}
else
{
}
else
{
fprintf
(
stderr
,
"unkwon eth type
\n
"
);
}
fprintf
(
stderr
,
"%8X -> %8X len: %lu
\n
"
,
iph
->
saddr
,
iph
->
daddr
,
iph
->
tot_len
+
sizeof
(
struct
ethhdr
));
fprintf
(
stderr
,
"%8X -> %8X len: %lu
\n
"
,
iph
->
saddr
,
iph
->
daddr
,
iph
->
tot_len
+
sizeof
(
struct
ethhdr
));
#endif
if
(
!
dest_port
.
TxPacket
(
pkt_data
,
pkt_len
,
cur_ts
))
...
...
@@ -326,26 +326,25 @@ static void pollq(Port &port, size_t iport) {
#ifdef NETSWITCH_STAT
d2n_poll_total
+=
1
;
if
(
stat_flag
){
if
(
stat_flag
)
{
s_d2n_poll_total
+=
1
;
}
#endif
#ifdef NETSWITCH_STAT
d2n_poll_suc
+=
1
;
if
(
stat_flag
){
s_d2n_poll_suc
+=
1
;
}
d2n_poll_suc
+=
1
;
if
(
stat_flag
)
{
s_d2n_poll_suc
+=
1
;
}
#endif
enum
Port
::
RxPollState
poll
=
port
.
RxPacket
(
pkt_data
,
pkt_len
,
cur_ts
);
if
(
poll
==
Port
::
kRxPollFail
)
{
return
;
// do nothing
return
;
// do nothing
}
if
(
poll
==
Port
::
kRxPollSuccess
)
{
//stat received bytes
if
(
poll
==
Port
::
kRxPollSuccess
)
{
// stat received bytes
pkt_recv_num
++
;
pkt_recv_byte
+=
pkt_len
;
...
...
@@ -372,7 +371,7 @@ static void pollq(Port &port, size_t iport) {
}
else
if
(
poll
==
Port
::
kRxPollSync
)
{
#ifdef NETSWITCH_STAT
d2n_poll_sync
+=
1
;
if
(
stat_flag
){
if
(
stat_flag
)
{
s_d2n_poll_sync
+=
1
;
}
#endif
...
...
@@ -381,31 +380,26 @@ static void pollq(Port &port, size_t iport) {
abort
();
}
port
.
RxDone
();
}
static
void
sendq
(
Port
&
port
,
size_t
iport
){
//then send
if
(
port
.
IsSync
()){
while
((
last_pkt_sent
+
period
)
<=
cur_ts
){
static
void
sendq
(
Port
&
port
,
size_t
iport
)
{
// then send
if
(
port
.
IsSync
())
{
while
((
last_pkt_sent
+
period
)
<=
cur_ts
)
{
port
.
TxPacket
(
packet
,
PKT_LEN
,
last_pkt_sent
+
period
);
last_pkt_sent
+=
period
;
pkt_tx_num
++
;
pkt_tx_byte
+=
PKT_LEN
;
}
}
else
{
}
else
{
port
.
TxPacket
(
packet
,
PKT_LEN
,
last_pkt_sent
+
period
);
}
// if not sync: send packet
// else: send packet periodically until allowed time
// while(allowed_timestamp){ since_last_send + period = to_send_time <= curtick
// while(allowed_timestamp){ since_last_send + period = to_send_time <=
// curtick
// txpacket(todest)
// }
}
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -459,8 +453,8 @@ int main(int argc, char *argv[]) {
pc
=
pcap_open_dead_with_tstamp_precision
(
DLT_EN10MB
,
65535
,
PCAP_TSTAMP_PRECISION_NANO
);
if
(
pc
==
nullptr
)
{
perror
(
"pcap_open_dead failed"
);
return
EXIT_FAILURE
;
perror
(
"pcap_open_dead failed"
);
return
EXIT_FAILURE
;
}
dumpfile
=
pcap_dump_open
(
pc
,
optarg
);
...
...
@@ -474,13 +468,12 @@ int main(int argc, char *argv[]) {
case
'b'
:
brate
=
strtol
(
optarg
,
NULL
,
0
);
fprintf
(
stderr
,
"bit rate set to: %d Gbps
\n
"
,
brate
);
if
(
brate
==
0
){
if
(
brate
==
0
)
{
period
=
ULLONG_MAX
;
}
else
{
bit_rate
=
brate
*
1000ULL
*
1000ULL
*
1000ULL
;
period
=
(
1E12
*
8
*
PKT_LEN
)
/
bit_rate
;
// per packet
}
else
{
bit_rate
=
brate
*
1000ULL
*
1000ULL
*
1000ULL
;
period
=
(
1E12
*
8
*
PKT_LEN
)
/
bit_rate
;
// per packet
}
assert
(
brate
<
200
);
break
;
...
...
@@ -498,22 +491,20 @@ int main(int argc, char *argv[]) {
return
EXIT_FAILURE
;
}
Port
*
pkt_port
=
ports
.
front
();
pkt_port
->
my_mac
.
addr
[
5
]
=
my_num
;
if
(
my_num
%
2
)
{
// odd num
if
(
my_num
%
2
)
{
// odd num
pkt_port
->
dest_mac
.
addr
[
5
]
=
my_num
-
1
;
}
else
{
// even number
}
else
{
// even number
pkt_port
->
dest_mac
.
addr
[
5
]
=
my_num
+
1
;
}
struct
mac_addr
*
mac_tmp
=
(
struct
mac_addr
*
)(
&
packet
[
0
]);
mac_tmp
->
addr
[
5
]
=
pkt_port
->
dest_mac
.
addr
[
5
];
//dest mac
mac_tmp
=
(
struct
mac_addr
*
)(
&
packet
[
6
]);
mac_tmp
->
addr
[
5
]
=
pkt_port
->
my_mac
.
addr
[
5
];
//source mac
struct
mac_addr
*
mac_tmp
=
(
struct
mac_addr
*
)(
&
packet
[
0
]);
mac_tmp
->
addr
[
5
]
=
pkt_port
->
dest_mac
.
addr
[
5
];
//
dest mac
mac_tmp
=
(
struct
mac_addr
*
)(
&
packet
[
6
]);
mac_tmp
->
addr
[
5
]
=
pkt_port
->
my_mac
.
addr
[
5
];
//
source mac
int
kk
;
for
(
kk
=
12
;
kk
<
PKT_LEN
-
12
;
kk
++
){
for
(
kk
=
12
;
kk
<
PKT_LEN
-
12
;
kk
++
)
{
packet
[
kk
]
=
0xFF
;
}
...
...
@@ -525,7 +516,6 @@ int main(int argc, char *argv[]) {
signal
(
SIGUSR2
,
sigusr2_handler
);
#endif
printf
(
"start polling
\n
"
);
while
(
!
exiting
)
{
// Sync all interfaces
...
...
@@ -551,7 +541,7 @@ int main(int argc, char *argv[]) {
if
(
min_ts
<
ULLONG_MAX
)
{
// a bit broken but should probably do
cur_ts
=
min_ts
;
if
(
cur_ts
>=
target_tick
){
if
(
cur_ts
>=
target_tick
)
{
printf
(
"run to %lu tics
\n
"
,
cur_ts
);
exiting
=
1
;
}
...
...
@@ -559,8 +549,10 @@ int main(int argc, char *argv[]) {
}
#ifdef NETSWITCH_STAT
fprintf
(
stderr
,
"sent packet: %20lu [%20lu Byte]
\n
"
,
pkt_tx_num
,
pkt_tx_byte
);
fprintf
(
stderr
,
"recv packet: %20lu [%20lu Byte]
\n
"
,
pkt_recv_num
,
pkt_recv_byte
);
fprintf
(
stderr
,
"sent packet: %20lu [%20lu Byte]
\n
"
,
pkt_tx_num
,
pkt_tx_byte
);
fprintf
(
stderr
,
"recv packet: %20lu [%20lu Byte]
\n
"
,
pkt_recv_num
,
pkt_recv_byte
);
#endif
...
...
sims/net/switch/net_switch.cc
View file @
f9a3a2e6
...
...
@@ -22,11 +22,11 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <pcap/pcap.h>
#include <linux/ip.h>
#include <linux/if_ether.h>
#include <arpa/inet.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <pcap/pcap.h>
#include <unistd.h>
#include <cassert>
#include <climits>
...
...
@@ -94,7 +94,6 @@ struct hash<MAC> {
};
}
// namespace std
/** Normal network switch port (conneting to a NIC) */
class
NetPort
{
public:
...
...
@@ -112,8 +111,8 @@ class NetPort {
bool
Init
()
{
struct
SimbricksBaseIfParams
params
=
netParams
;
params
.
sync_mode
=
(
sync_
?
kSimbricksBaseIfSyncOptional
:
kSimbricksBaseIfSyncDisabled
);
params
.
sync_mode
=
(
sync_
?
kSimbricksBaseIfSyncOptional
:
kSimbricksBaseIfSyncDisabled
);
params
.
sock_path
=
path_
;
params
.
blocking_conn
=
false
;
...
...
@@ -130,8 +129,12 @@ class NetPort {
memset
(
&
netif_
,
0
,
sizeof
(
netif_
));
}
NetPort
(
const
NetPort
&
other
)
:
netif_
(
other
.
netif_
),
rx_
(
other
.
rx_
),
sync_
(
other
.
sync_
),
path_
(
other
.
path_
)
{}
NetPort
(
const
NetPort
&
other
)
:
netif_
(
other
.
netif_
),
rx_
(
other
.
rx_
),
sync_
(
other
.
sync_
),
path_
(
other
.
path_
)
{
}
virtual
bool
Prepare
()
{
if
(
!
Init
())
...
...
@@ -154,15 +157,15 @@ class NetPort {
}
void
Sync
(
uint64_t
cur_ts
)
{
while
(
SimbricksNetIfOutSync
(
&
netif_
,
cur_ts
));
while
(
SimbricksNetIfOutSync
(
&
netif_
,
cur_ts
))
;
}
uint64_t
NextTimestamp
()
{
return
SimbricksNetIfInTimestamp
(
&
netif_
);
}
enum
RxPollState
RxPacket
(
const
void
*&
data
,
size_t
&
len
,
uint64_t
cur_ts
)
{
enum
RxPollState
RxPacket
(
const
void
*&
data
,
size_t
&
len
,
uint64_t
cur_ts
)
{
assert
(
rx_
==
nullptr
);
rx_
=
SimbricksNetIfInPoll
(
&
netif_
,
cur_ts
);
...
...
@@ -189,10 +192,9 @@ class NetPort {
rx_
=
nullptr
;
}
bool
TxPacket
(
const
void
*
data
,
size_t
len
,
uint64_t
cur_ts
)
{
bool
TxPacket
(
const
void
*
data
,
size_t
len
,
uint64_t
cur_ts
)
{
volatile
union
SimbricksProtoNetMsg
*
msg_to
=
SimbricksNetIfOutAlloc
(
&
netif_
,
cur_ts
);
SimbricksNetIfOutAlloc
(
&
netif_
,
cur_ts
);
if
(
!
msg_to
&&
!
sync_
)
{
return
false
;
}
else
if
(
!
msg_to
&&
sync_
)
{
...
...
@@ -210,7 +212,6 @@ class NetPort {
}
};
/** Listening switch port (connected to by another network) */
class
NetListenPort
:
public
NetPort
{
protected:
...
...
@@ -221,8 +222,8 @@ class NetListenPort : public NetPort {
memset
(
&
pool_
,
0
,
sizeof
(
pool_
));
}
NetListenPort
(
const
NetListenPort
&
other
)
:
NetPort
(
other
),
pool_
(
other
.
pool_
)
{
NetListenPort
(
const
NetListenPort
&
other
)
:
NetPort
(
other
),
pool_
(
other
.
pool_
)
{
}
virtual
bool
Prepare
()
override
{
...
...
@@ -232,8 +233,9 @@ class NetListenPort : public NetPort {
std
::
string
shm_path
=
path_
;
shm_path
+=
"-shm"
;
if
(
SimbricksBaseIfSHMPoolCreate
(
&
pool_
,
shm_path
.
c_str
(),
SimbricksBaseIfSHMSize
(
&
netif_
.
base
.
params
))
!=
0
)
{
if
(
SimbricksBaseIfSHMPoolCreate
(
&
pool_
,
shm_path
.
c_str
(),
SimbricksBaseIfSHMSize
(
&
netif_
.
base
.
params
))
!=
0
)
{
perror
(
"Prepare: SimbricksBaseIfSHMPoolCreate failed"
);
return
false
;
}
...
...
@@ -247,8 +249,7 @@ class NetListenPort : public NetPort {
}
};
static
bool
ConnectAll
(
std
::
vector
<
NetPort
*>
ports
)
{
static
bool
ConnectAll
(
std
::
vector
<
NetPort
*>
ports
)
{
size_t
n
=
ports
.
size
();
struct
SimBricksBaseIfEstablishData
ests
[
n
];
struct
SimbricksProtoNetIntro
intro
;
...
...
@@ -266,10 +267,10 @@ static bool ConnectAll(std::vector<NetPort *> ports)
return
false
;
}
if
(
SimBricksBaseIfEstablish
(
ests
,
n
))
{
fprintf
(
stderr
,
"ConnectAll: SimBricksBaseIfEstablish failed
\n
"
);
return
false
;
}
if
(
SimBricksBaseIfEstablish
(
ests
,
n
))
{
fprintf
(
stderr
,
"ConnectAll: SimBricksBaseIfEstablish failed
\n
"
);
return
false
;
}
printf
(
"done connecting
\n
"
);
return
true
;
...
...
@@ -304,12 +305,12 @@ static void forward_pkt(const void *pkt_data, size_t pkt_len, size_t port_id,
// log to pcap file if initialized
if
(
dumpfile
)
{
memset
(
&
ph
,
0
,
sizeof
(
ph
));
ph
.
ts
.
tv_sec
=
cur_ts
/
1000000000000ULL
;
ph
.
ts
.
tv_usec
=
(
cur_ts
%
1000000000000ULL
)
/
1000ULL
;
ph
.
caplen
=
pkt_len
;
ph
.
len
=
pkt_len
;
pcap_dump
((
unsigned
char
*
)
dumpfile
,
&
ph
,
(
unsigned
char
*
)
pkt_data
);
memset
(
&
ph
,
0
,
sizeof
(
ph
));
ph
.
ts
.
tv_sec
=
cur_ts
/
1000000000000ULL
;
ph
.
ts
.
tv_usec
=
(
cur_ts
%
1000000000000ULL
)
/
1000ULL
;
ph
.
caplen
=
pkt_len
;
ph
.
len
=
pkt_len
;
pcap_dump
((
unsigned
char
*
)
dumpfile
,
&
ph
,
(
unsigned
char
*
)
pkt_data
);
}
// print sending tick: [packet type] source_IP -> dest_IP len:
...
...
@@ -317,24 +318,22 @@ static void forward_pkt(const void *pkt_data, size_t pkt_len, size_t port_id,
uint16_t
eth_proto
;
struct
ethhdr
*
hdr
;
struct
iphdr
*
iph
;
hdr
=
(
struct
ethhdr
*
)
pkt_data
;
hdr
=
(
struct
ethhdr
*
)
pkt_data
;
eth_proto
=
ntohs
(
hdr
->
h_proto
);
iph
=
(
struct
iphdr
*
)(
hdr
+
1
);
uint64_t
dmac
=
(
*
(
uint64_t
*
)
hdr
->
h_dest
)
&
0xFFFFFFFFFFULL
;
uint64_t
smac
=
(
*
(
uint64_t
*
)
hdr
->
h_source
)
&
0xFFFFFFFFFFULL
;
uint64_t
dmac
=
(
*
(
uint64_t
*
)
hdr
->
h_dest
)
&
0xFFFFFFFFFFULL
;
uint64_t
smac
=
(
*
(
uint64_t
*
)
hdr
->
h_source
)
&
0xFFFFFFFFFFULL
;
fprintf
(
stderr
,
"%20lu: [P %zu -> %zu] %lx -> %lx "
,
cur_ts
,
iport_id
,
port_id
,
smac
,
dmac
);
if
(
eth_proto
==
ETH_P_IP
){
if
(
eth_proto
==
ETH_P_IP
)
{
fprintf
(
stderr
,
"[ IP] "
);
fprintf
(
stderr
,
"%8X -> %8X len: %lu
\n
"
,
iph
->
saddr
,
iph
->
daddr
,
ntohs
(
iph
->
tot_len
)
+
sizeof
(
struct
ethhdr
));
}
else
if
(
eth_proto
==
ETH_P_ARP
){
}
else
if
(
eth_proto
==
ETH_P_ARP
)
{
fprintf
(
stderr
,
"[ARP] %8X -> %8X
\n
"
,
*
(
uint32_t
*
)
((
uint8_t
*
)
pkt_data
+
28
),
*
(
uint32_t
*
)
((
uint8_t
*
)
pkt_data
+
38
)
);
}
else
{
*
(
uint32_t
*
)((
uint8_t
*
)
pkt_data
+
28
),
*
(
uint32_t
*
)((
uint8_t
*
)
pkt_data
+
38
));
}
else
{
fprintf
(
stderr
,
"unknown eth type
\n
"
);
}
#endif
...
...
@@ -349,7 +348,7 @@ static void switch_pkt(NetPort &port, size_t iport) {
#ifdef NETSWITCH_STAT
d2n_poll_total
+=
1
;
if
(
stat_flag
){
if
(
stat_flag
)
{
s_d2n_poll_total
+=
1
;
}
#endif
...
...
@@ -361,7 +360,7 @@ static void switch_pkt(NetPort &port, size_t iport) {
#ifdef NETSWITCH_STAT
d2n_poll_suc
+=
1
;
if
(
stat_flag
){
if
(
stat_flag
)
{
s_d2n_poll_suc
+=
1
;
}
#endif
...
...
@@ -391,7 +390,7 @@ static void switch_pkt(NetPort &port, size_t iport) {
}
else
if
(
poll
==
NetPort
::
kRxPollSync
)
{
#ifdef NETSWITCH_STAT
d2n_poll_sync
+=
1
;
if
(
stat_flag
){
if
(
stat_flag
)
{
s_d2n_poll_sync
+=
1
;
}
#endif
...
...
@@ -443,8 +442,8 @@ int main(int argc, char *argv[]) {
pc
=
pcap_open_dead_with_tstamp_precision
(
DLT_EN10MB
,
65535
,
PCAP_TSTAMP_PRECISION_NANO
);
if
(
pc
==
nullptr
)
{
perror
(
"pcap_open_dead failed"
);
return
EXIT_FAILURE
;
perror
(
"pcap_open_dead failed"
);
return
EXIT_FAILURE
;
}
dumpfile
=
pcap_dump_open
(
pc
,
optarg
);
...
...
@@ -509,8 +508,8 @@ int main(int argc, char *argv[]) {
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
);
"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
...
...
sims/net/tofino/tofino.cc
View file @
f9a3a2e6
...
...
@@ -41,9 +41,9 @@
#include <fstream>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <set>
#include <simbricks/base/cxxatomicfix.h>
extern
"C"
{
...
...
@@ -87,7 +87,8 @@ struct classcomp {
return
lhs
.
time
>
rhs
.
time
;
}
};
std
::
priority_queue
<
struct
event
,
std
::
vector
<
struct
event
>
,
classcomp
>
event_queue
;
std
::
priority_queue
<
struct
event
,
std
::
vector
<
struct
event
>
,
classcomp
>
event_queue
;
static
bool
get_tofino_log_line
(
int
limit_ms
)
{
using
std
::
chrono
::
system_clock
;
...
...
@@ -237,8 +238,8 @@ static void recv_from_peer(int port) {
e
.
time
=
msg_from
->
packet
.
timestamp
;
e
.
to_switch
=
true
;
e
.
port
=
port
;
e
.
msg
=
std
::
string
((
const
char
*
)
msg_from
->
packet
.
data
,
msg_from
->
packet
.
len
);
e
.
msg
=
std
::
string
((
const
char
*
)
msg_from
->
packet
.
data
,
msg_from
->
packet
.
len
);
#ifdef DEBUG
printf
(
"received packet from peer %u at time %llu
\n
"
,
port
,
e
.
time
);
#endif
...
...
sims/net/wire/net_wire.c
View file @
f9a3a2e6
...
...
@@ -116,7 +116,6 @@ int main(int argc, char *argv[]) {
signal
(
SIGTERM
,
sigint_handler
);
signal
(
SIGUSR1
,
sigusr1_handler
);
if
(
argc
>=
5
)
params
.
sync_interval
=
strtoull
(
argv
[
4
],
NULL
,
0
)
*
1000ULL
;
...
...
sims/nic/corundum/corundum_verilator.cc
View file @
f9a3a2e6
...
...
@@ -46,7 +46,7 @@ extern "C" {
struct
DMAOp
;
static
uint64_t
clock_period
=
4
*
1000ULL
;
// 4ns -> 250MHz
static
uint64_t
clock_period
=
4
*
1000ULL
;
// 4ns -> 250MHz
static
volatile
int
exiting
=
0
;
uint64_t
main_time
=
0
;
...
...
@@ -373,14 +373,14 @@ void pci_rwcomp_issue(MMIOOp *op) {
wc
->
req_id
=
op
->
id
;
SimbricksPcieIfD2HOutSend
(
&
nicif
.
pcie
,
msg
,
SIMBRICKS_PROTO_PCIE_D2H_MSG_WRITECOMP
);
SIMBRICKS_PROTO_PCIE_D2H_MSG_WRITECOMP
);
}
else
{
rc
=
&
msg
->
readcomp
;
memcpy
((
void
*
)
rc
->
data
,
&
op
->
value
,
op
->
len
);
rc
->
req_id
=
op
->
id
;
SimbricksPcieIfD2HOutSend
(
&
nicif
.
pcie
,
msg
,
SIMBRICKS_PROTO_PCIE_D2H_MSG_READCOMP
);
SIMBRICKS_PROTO_PCIE_D2H_MSG_READCOMP
);
}
delete
op
;
...
...
@@ -409,7 +409,7 @@ void pci_dma_issue(DMAOp *op) {
memcpy
((
void
*
)
write
->
data
,
op
->
data
,
op
->
len
);
SimbricksPcieIfD2HOutSend
(
&
nicif
.
pcie
,
msg
,
SIMBRICKS_PROTO_PCIE_D2H_MSG_WRITE
);
SIMBRICKS_PROTO_PCIE_D2H_MSG_WRITE
);
}
else
{
volatile
struct
SimbricksProtoPcieD2HRead
*
read
=
&
msg
->
read
;
read
->
req_id
=
(
uintptr_t
)
op
;
...
...
@@ -417,7 +417,7 @@ void pci_dma_issue(DMAOp *op) {
read
->
len
=
op
->
len
;
SimbricksPcieIfD2HOutSend
(
&
nicif
.
pcie
,
msg
,
SIMBRICKS_PROTO_PCIE_D2H_MSG_READ
);
SIMBRICKS_PROTO_PCIE_D2H_MSG_READ
);
}
pci_dma_pending
.
insert
(
op
);
...
...
@@ -500,7 +500,7 @@ static void h2d_read(MMIOInterface &mmio,
rc
->
req_id
=
read
->
req_id
;
SimbricksPcieIfD2HOutSend
(
&
nicif
.
pcie
,
msg
,
SIMBRICKS_PROTO_PCIE_D2H_MSG_READCOMP
);
SIMBRICKS_PROTO_PCIE_D2H_MSG_READCOMP
);
}
else
{
/*printf("read(bar=%u, off=%lu, len=%u) = %lu\n", read->bar, read->offset,
read->len, val);*/
...
...
@@ -529,7 +529,7 @@ static void h2d_write(MMIOInterface &mmio,
wc
->
req_id
=
write
->
req_id
;
SimbricksPcieIfD2HOutSend
(
&
nicif
.
pcie
,
msg
,
SIMBRICKS_PROTO_PCIE_D2H_MSG_WRITECOMP
);
SIMBRICKS_PROTO_PCIE_D2H_MSG_WRITECOMP
);
}
else
{
mmio
.
issueWrite
(
write
->
req_id
,
write
->
offset
,
write
->
len
,
val
);
}
...
...
@@ -624,7 +624,7 @@ class EthernetTx {
if
(
top
.
tx_axis_tvalid
)
{
/* iterate over all bytes on the bus */
uint8_t
*
txbus
=
(
uint8_t
*
)
&
top
.
tx_axis_tdata
;
uint8_t
*
txbus
=
(
uint8_t
*
)
&
top
.
tx_axis_tdata
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
top
.
tx_axis_tdata
);
i
++
)
{
if
((
top
.
tx_axis_tkeep
&
(
1ULL
<<
i
))
!=
0
)
{
assert
(
packet_len
<
2048
);
...
...
@@ -689,7 +689,8 @@ class EthernetRx {
if
(
packet_off
!=
0
&&
!
top
.
rx_axis_tready
)
{
// no ready signal, can't advance
#ifdef ETH_DEBUG
std
::
cerr
<<
"eth rx: no ready "
<<
fifo_pos_rd
<<
" "
<<
packet_off
<<
std
::
endl
;
std
::
cerr
<<
"eth rx: no ready "
<<
fifo_pos_rd
<<
" "
<<
packet_off
<<
std
::
endl
;
#endif
}
else
if
(
packet_off
==
fifo_lens
[
fifo_pos_rd
])
{
// done with packet
...
...
@@ -711,10 +712,11 @@ class EthernetRx {
std
::
cout
<<
"rx from "
<<
fifo_pos_rd
<<
std
::
endl
;
#endif
top
.
rx_axis_tkeep
=
0
;
uint8_t
*
rdata
=
(
uint8_t
*
)
&
top
.
rx_axis_tdata
;
uint8_t
*
rdata
=
(
uint8_t
*
)
&
top
.
rx_axis_tdata
;
size_t
i
;
for
(
i
=
0
;
i
<
sizeof
(
top
.
rx_axis_tdata
)
&&
packet_off
<
fifo_lens
[
fifo_pos_rd
];
i
++
)
{
packet_off
<
fifo_lens
[
fifo_pos_rd
];
i
++
)
{
rdata
[
i
]
=
fifo_bufs
[
fifo_pos_rd
][
packet_off
];
top
.
rx_axis_tkeep
|=
(
1ULL
<<
i
);
packet_off
++
;
...
...
@@ -776,7 +778,7 @@ void pci_msi_issue(uint8_t vec) {
intr
->
inttype
=
SIMBRICKS_PROTO_PCIE_INT_MSI
;
SimbricksPcieIfD2HOutSend
(
&
nicif
.
pcie
,
msg
,
SIMBRICKS_PROTO_PCIE_D2H_MSG_INTERRUPT
);
SIMBRICKS_PROTO_PCIE_D2H_MSG_INTERRUPT
);
}
static
void
msi_step
(
Vinterface
&
top
,
PCICoordinator
&
coord
)
{
...
...
@@ -822,7 +824,7 @@ int main(int argc, char *argv[]) {
if
(
argc
>=
8
)
pcieParams
.
link_latency
=
strtoull
(
argv
[
7
],
NULL
,
0
)
*
1000ULL
;
if
(
argc
>=
9
)
netParams
.
link_latency
=
strtoull
(
argv
[
8
],
NULL
,
0
)
*
1000ULL
;
netParams
.
link_latency
=
strtoull
(
argv
[
8
],
NULL
,
0
)
*
1000ULL
;
if
(
argc
>=
10
)
clock_period
=
1000000ULL
/
strtoull
(
argv
[
9
],
NULL
,
0
);
...
...
@@ -957,12 +959,12 @@ int main(int argc, char *argv[]) {
done
=
1
;
if
(
SimbricksPcieIfD2HOutSync
(
&
nicif
.
pcie
,
main_time
)
<
0
)
{
std
::
cerr
<<
"warn: SimbricksPcieIfD2HOutSync failed (t="
<<
main_time
<<
")"
<<
std
::
endl
;
<<
")"
<<
std
::
endl
;
done
=
0
;
}
if
(
SimbricksNetIfOutSync
(
&
nicif
.
net
,
main_time
)
<
0
)
{
std
::
cerr
<<
"warn: SimbricksNetIfOutSync failed (t="
<<
main_time
<<
")"
<<
std
::
endl
;
<<
")"
<<
std
::
endl
;
done
=
0
;
}
}
while
(
!
done
);
...
...
@@ -970,11 +972,11 @@ int main(int argc, char *argv[]) {
do
{
poll_h2d
(
mmio
);
poll_n2d
(
rx
);
}
while
(
!
exiting
&&
((
sync_pci
&&
SimbricksPcieIfH2DInTimestamp
(
&
nicif
.
pcie
)
<=
main_time
)
||
(
sync_eth
&&
SimbricksNetIfInTimestamp
(
&
nicif
.
net
)
<=
main_time
)));
}
while
(
!
exiting
&&
((
sync_pci
&&
SimbricksPcieIfH2DInTimestamp
(
&
nicif
.
pcie
)
<=
main_time
)
||
(
sync_eth
&&
SimbricksNetIfInTimestamp
(
&
nicif
.
net
)
<=
main_time
)));
/* falling edge */
top
->
clk
=
!
top
->
clk
;
...
...
sims/nic/corundum_bm/corundum_bm.cc
View file @
f9a3a2e6
...
...
@@ -193,7 +193,8 @@ void EventRing::issueEvent(unsigned type, unsigned source) {
event
->
type
=
type
;
event
->
source
=
source
;
#ifdef DEBUG
printf
(
"corundum_bm: event ring issue dma addr %lx index %lu len %lu
\n
"
,
op
->
dma_addr_
,
op
->
tag
,
op
->
len_
);
printf
(
"corundum_bm: event ring issue dma addr %lx index %lu len %lu
\n
"
,
op
->
dma_addr_
,
op
->
tag
,
op
->
len_
);
#endif
runner
->
IssueDma
(
*
op
);
this
->
_currHead
++
;
...
...
@@ -279,7 +280,8 @@ void TxRing::setHeadPtr(ptr_t ptr) {
op
->
tag
=
this
->
_currTail
;
op
->
write_
=
false
;
#ifdef DEBUG
printf
(
"corundum_bm: tx issue dma addr %lx index %lu len %lu
\n
"
,
op
->
dma_addr_
,
op
->
tag
,
op
->
len_
);
printf
(
"corundum_bm: tx issue dma addr %lx index %lu len %lu
\n
"
,
op
->
dma_addr_
,
op
->
tag
,
op
->
len_
);
#endif
runner
->
IssueDma
(
*
op
);
this
->
_currTail
++
;
...
...
@@ -292,7 +294,8 @@ void TxRing::dmaDone(DMAOp *op) {
assert
(
!
op
->
write_
);
Desc
*
desc
=
(
Desc
*
)
op
->
data_
;
#ifdef DEBUG
printf
(
"corundum_bm: tx dma desc done addr %lx index %lu len %u
\n
"
,
desc
->
addr
,
op
->
tag
,
desc
->
len
);
printf
(
"corundum_bm: tx dma desc done addr %lx index %lu len %u
\n
"
,
desc
->
addr
,
op
->
tag
,
desc
->
len
);
#endif
op
->
type
=
DMA_TYPE_MEM
;
op
->
dma_addr_
=
desc
->
addr
;
...
...
@@ -304,7 +307,8 @@ void TxRing::dmaDone(DMAOp *op) {
case
DMA_TYPE_MEM
:
assert
(
!
op
->
write_
);
#ifdef DEBUG
printf
(
"corundum_bm: tx dma memory done index %lu len %lu
\n
"
,
op
->
tag
,
op
->
len_
);
printf
(
"corundum_bm: tx dma memory done index %lu len %lu
\n
"
,
op
->
tag
,
op
->
len_
);
#endif
runner
->
EthSend
(
op
->
data_
,
op
->
len_
);
updatePtr
((
ptr_t
)
op
->
tag
,
false
);
...
...
@@ -329,7 +333,8 @@ void RxRing::dmaDone(DMAOp *op) {
assert
(
!
op
->
write_
);
Desc
*
desc
=
(
Desc
*
)
op
->
data_
;
#ifdef DEBUG
printf
(
"corundum_bm: rx dma desc done addr %lx index %lu len %lu
\n
"
,
desc
->
addr
,
op
->
tag
,
op
->
rx_data
->
len
);
printf
(
"corundum_bm: rx dma desc done addr %lx index %lu len %lu
\n
"
,
desc
->
addr
,
op
->
tag
,
op
->
rx_data
->
len
);
#endif
op
->
type
=
DMA_TYPE_MEM
;
op
->
dma_addr_
=
desc
->
addr
;
...
...
@@ -343,7 +348,8 @@ void RxRing::dmaDone(DMAOp *op) {
case
DMA_TYPE_MEM
:
assert
(
op
->
write_
);
#ifdef DEBUG
printf
(
"corundum_bm: rx dma memory done index %lu len %lu
\n
"
,
op
->
tag
,
op
->
len_
);
printf
(
"corundum_bm: rx dma memory done index %lu len %lu
\n
"
,
op
->
tag
,
op
->
len_
);
#endif
updatePtr
((
ptr_t
)
op
->
tag
,
false
);
this
->
rxCplRing
->
complete
(
op
->
tag
,
op
->
len_
,
false
);
...
...
@@ -372,7 +378,8 @@ void RxRing::rx(RxData *rx_data) {
op
->
tag
=
this
->
_currTail
;
op
->
write_
=
false
;
#ifdef DEBUG
printf
(
"corundum_bm: rx issue dma addr %lx index %lu len %lu
\n
"
,
op
->
dma_addr_
,
op
->
tag
,
op
->
len_
);
printf
(
"corundum_bm: rx issue dma addr %lx index %lu len %lu
\n
"
,
op
->
dma_addr_
,
op
->
tag
,
op
->
len_
);
#endif
runner
->
IssueDma
(
*
op
);
this
->
_currTail
++
;
...
...
sims/nic/i40e_bm/i40e_bm.cc
View file @
f9a3a2e6
...
...
@@ -826,10 +826,10 @@ int_ev::int_ev() {
}
// namespace i40e
class
i40e_factory
:
public
nicbm
::
MultiNicRunner
::
DeviceFactory
{
public:
virtual
nicbm
::
Runner
::
Device
&
create
()
override
{
return
*
new
i40e
::
i40e_bm
;
}
public:
virtual
nicbm
::
Runner
::
Device
&
create
()
override
{
return
*
new
i40e
::
i40e_bm
;
}
};
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
sims/nic/i40e_bm/i40e_lan.cc
View file @
f9a3a2e6
...
...
@@ -36,7 +36,9 @@
namespace
i40e
{
lan
::
lan
(
i40e_bm
&
dev_
,
size_t
num_qs_
)
:
dev
(
dev_
),
log
(
"lan"
,
dev_
.
runner_
),
rss_kc
(
dev_
.
regs
.
pfqf_hkey
),
:
dev
(
dev_
),
log
(
"lan"
,
dev_
.
runner_
),
rss_kc
(
dev_
.
regs
.
pfqf_hkey
),
num_qs
(
num_qs_
)
{
rxqs
=
new
lan_queue_rx
*
[
num_qs
];
txqs
=
new
lan_queue_tx
*
[
num_qs
];
...
...
sims/nic/i40e_bm/logger.cc
View file @
f9a3a2e6
...
...
@@ -28,8 +28,8 @@
namespace
i40e
{
logger
::
logger
(
const
std
::
string
&
label_
,
nicbm
::
Runner
*
runner_
)
:
label
(
label_
),
runner
(
runner_
)
{
logger
::
logger
(
const
std
::
string
&
label_
,
nicbm
::
Runner
*
runner_
)
:
label
(
label_
),
runner
(
runner_
)
{
ss
<<
std
::
hex
;
}
...
...
trace/events.h
View file @
f9a3a2e6
...
...
@@ -48,8 +48,8 @@ class EHostInstr : public event {
bool
fMemR
;
bool
fMemW
;
EHostInstr
(
uint64_t
ts_
,
uint64_t
pc_
)
:
event
(
ts_
),
pc
(
pc_
),
fMemR
(
false
),
fMemW
(
false
)
{
EHostInstr
(
uint64_t
ts_
,
uint64_t
pc_
)
:
event
(
ts_
),
pc
(
pc_
),
fMemR
(
false
),
fMemW
(
false
)
{
}
virtual
~
EHostInstr
()
{
...
...
@@ -64,7 +64,6 @@ class EHostHalt : public event {
public:
uint64_t
pc
;
EHostHalt
(
uint64_t
ts_
,
uint64_t
pc_
)
:
event
(
ts_
),
pc
(
pc_
)
{
}
...
...
trace/log_parser.cc
View file @
f9a3a2e6
...
...
@@ -33,9 +33,8 @@
namespace
bio
=
boost
::
iostreams
;
log_parser
::
log_parser
()
:
inf
(
nullptr
),
gz_file
(
nullptr
),
gz_in
(
nullptr
),
buf_len
(
0
),
buf_pos
(
0
)
{
log_parser
::
log_parser
()
:
inf
(
nullptr
),
gz_file
(
nullptr
),
gz_in
(
nullptr
),
buf_len
(
0
),
buf_pos
(
0
)
{
buf
=
new
char
[
block_size
];
}
...
...
@@ -125,11 +124,11 @@ bool log_parser::next_event() {
void
log_parser
::
read_coro
(
coro_t
::
push_type
&
sink_
)
{
sink
=
&
sink_
;
while
(
next_event
());
while
(
next_event
())
;
}
void
log_parser
::
yield
(
std
::
shared_ptr
<
event
>
ev
)
{
void
log_parser
::
yield
(
std
::
shared_ptr
<
event
>
ev
)
{
got_event
=
true
;
ev
->
source
=
this
;
(
*
sink
)(
ev
);
...
...
trace/process.cc
View file @
f9a3a2e6
...
...
@@ -80,14 +80,13 @@ void MergeEvents(coro_t::push_type &sink,
void
Printer
(
coro_t
::
pull_type
&
source
)
{
uint64_t
ts_off
=
0
;
for
(
auto
ev
:
source
)
{
for
(
auto
ev
:
source
)
{
std
::
shared_ptr
<
EHostCall
>
hc
;
std
::
shared_ptr
<
EHostInstr
>
hi
;
if
((
hi
=
std
::
dynamic_pointer_cast
<
EHostInstr
>
(
ev
)))
{
continue
;
}
else
if
((
hc
=
std
::
dynamic_pointer_cast
<
EHostCall
>
(
ev
))
&&
strcmp
(
ev
->
source
->
label
,
"C"
)
&&
hc
->
fun
==
"__sys_sendto"
)
{
strcmp
(
ev
->
source
->
label
,
"C"
)
&&
hc
->
fun
==
"__sys_sendto"
)
{
std
::
cout
<<
"---------- REQ START:"
<<
ev
->
ts
<<
std
::
endl
;
ts_off
=
ev
->
ts
;
}
...
...
@@ -101,7 +100,7 @@ void Printer(coro_t::pull_type &source) {
}
void
Consumer
(
coro_t
::
pull_type
&
source
)
{
for
(
auto
ev
:
source
)
{
for
(
auto
ev
:
source
)
{
}
}
...
...
@@ -111,15 +110,15 @@ struct InstStatsData {
uint64_t
tMin
;
uint64_t
tMax
;
uint64_t
tMean
;
std
::
vector
<
uint64_t
>
tAll
;
std
::
vector
<
uint64_t
>
tAll
;
};
void
InstStats
(
coro_t
::
push_type
&
sink
,
coro_t
::
pull_type
&
source
,
struct
InstStatsData
&
data
)
{
struct
InstStatsData
&
data
)
{
uint64_t
last_ts
=
0
;
uint64_t
first_ts
=
0
;
data
.
nInsts
=
0
;
for
(
auto
ev
:
source
)
{
for
(
auto
ev
:
source
)
{
std
::
shared_ptr
<
EHostInstr
>
hi
;
if
((
hi
=
std
::
dynamic_pointer_cast
<
EHostInstr
>
(
ev
)))
{
if
(
!
last_ts
)
{
...
...
@@ -140,9 +139,9 @@ void InstStats(coro_t::push_type &sink, coro_t::pull_type &source,
/*if (lat > 4000)
std::cout << "ILAT: " << lat << " " << std::hex << hi->pc <<
std::dec << " " << hi->ts << std::endl;*/
}
}
last_ts
=
hi
->
ts
;
//last_pc = hi->pc;
//
last_pc = hi->pc;
}
sink
(
ev
);
}
...
...
@@ -153,11 +152,11 @@ void InstStats(coro_t::push_type &sink, coro_t::pull_type &source,
data
.
tMean
=
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
!=
5
)
{
std
::
cerr
<<
"Usage: process CLIENT_HLOG CLIENT_NLOG SERVER_HLOG "
"SERVER_CLOG"
<<
std
::
endl
;
"SERVER_CLOG"
<<
std
::
endl
;
return
1
;
}
...
...
@@ -211,11 +210,11 @@ int main(int argc, char *argv[]) {
std
::
set
<
InstStatsData
*>
isds
;
for
(
auto
p
:
all_parsers
)
{
coro_t
::
pull_type
*
src
=
new
coro_t
::
pull_type
(
boost
::
bind
(
&
log_parser
::
read_coro
,
boost
::
ref
(
*
p
),
_1
));
InstStatsData
*
isd
=
new
InstStatsData
;
isd
->
label
=
p
->
label
;
boost
::
bind
(
&
log_parser
::
read_coro
,
boost
::
ref
(
*
p
),
_1
));
InstStatsData
*
isd
=
new
InstStatsData
;
isd
->
label
=
p
->
label
;
coro_t
::
pull_type
*
istat
=
new
coro_t
::
pull_type
(
boost
::
bind
(
InstStats
,
_1
,
boost
::
ref
(
*
src
),
boost
::
ref
(
*
isd
)));
boost
::
bind
(
InstStats
,
_1
,
boost
::
ref
(
*
src
),
boost
::
ref
(
*
isd
)));
sources
.
insert
(
istat
);
isds
.
insert
(
isd
);
}
...
...
@@ -234,8 +233,8 @@ int main(int argc, char *argv[]) {
std
::
cout
<<
" Instrs: "
<<
isd
->
nInsts
<<
std
::
endl
;
std
::
cout
<<
" Mean instr time: "
<<
isd
->
tMean
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<=
100
;
i
+=
1
)
std
::
cout
<<
" P["
<<
i
<<
"] instr time: "
<<
isd
->
tAll
[
isd
->
tAll
.
size
()
*
i
/
100
-
(
i
==
100
?
1
:
0
)]
<<
std
::
endl
;
std
::
cout
<<
" P["
<<
i
<<
"] instr time: "
<<
isd
->
tAll
[
isd
->
tAll
.
size
()
*
i
/
100
-
(
i
==
100
?
1
:
0
)]
<<
std
::
endl
;
}
}
Prev
1
2
Next
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