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
3e1b2d38
Commit
3e1b2d38
authored
Sep 27, 2022
by
Hejing Li
Browse files
NetMem: initializes, buggy in Outsync
parent
391c5c3d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
134 additions
and
56 deletions
+134
-56
sims/mem/netmem/netmem.cc
sims/mem/netmem/netmem.cc
+134
-56
No files found.
sims/mem/netmem/netmem.cc
View file @
3e1b2d38
...
@@ -36,17 +36,31 @@
...
@@ -36,17 +36,31 @@
#include <iostream>
#include <iostream>
#include <vector>
#include <vector>
#include <simbricks/base/cxxatomicfix.h>
#include <arpa/inet.h>
#include <netinet/udp.h>
#include <linux/ip.h>
#include <linux/if_ether.h>
#include <simbricks/base/cxxatomicfix.h>
extern
"C"
{
extern
"C"
{
#include <simbricks/mem/if.h>
#include <simbricks/network/if.h>
#include <simbricks/nicif/nicif.h>
#include <simbricks/mem/memop.h>
#include <simbricks/base/proto.h>
};
};
#define NETMEM_DEBUG 1
static
int
exiting
=
0
;
static
int
exiting
=
0
,
sync_mem
=
1
;
static
uint64_t
cur_ts
=
0
;
static
uint64_t
cur_ts
=
0
;
uint8_t
*
mem_array
;
uint64_t
size
;
uint64_t
base_addr
;
union
mac_addr_
{
uint64_t
mac_64
;
uint8_t
mac_byte
[
6
];
};
union
mac_addr_
mac_addr
;
static
void
sigint_handler
(
int
dummy
)
{
static
void
sigint_handler
(
int
dummy
)
{
exiting
=
1
;
exiting
=
1
;
...
@@ -56,32 +70,54 @@ static void sigusr1_handler(int dummy) {
...
@@ -56,32 +70,54 @@ static void sigusr1_handler(int dummy) {
fprintf
(
stderr
,
"main_time = %lu
\n
"
,
cur_ts
);
fprintf
(
stderr
,
"main_time = %lu
\n
"
,
cur_ts
);
}
}
void
handlePacket
(
SimbricksNetIf
*
netif
,
volatile
struct
SimbricksProtoNetMsgPacket
*
packet
)
{
volatile
union
SimbricksProtoMemM2H
*
m2h_msg
=
(
SimbricksProtoMemM2H
*
)
malloc
(
sizeof
(
SimbricksProtoMemM2H
));
volatile
struct
SimbricksProtoMemM2HWritecomp
*
wc
=
&
m2h_msg
->
writecomp
;
wc
->
req_id
=
1
;
volatile
union
SimbricksProtoNetMsg
*
msg
=
SimbricksNetIfOutAlloc
(
netif
,
cur_ts
);
if
(
msg
==
NULL
)
return
;
volatile
struct
SimbricksProtoNetMsgPacket
*
net_packet
=
&
msg
->
packet
;
memcpy
((
void
*
)
net_packet
->
data
,
(
void
*
)
m2h_msg
,
sizeof
(
SimbricksProtoMemM2H
));
packet
->
port
=
0
;
packet
->
len
=
sizeof
(
SimbricksProtoMemM2H
);
SimbricksNetIfOutSend
(
netif
,
msg
,
SIMBRICKS_PROTO_NET_MSG_PACKET
);
};
void
PollN2M
(
SimbricksNetIf
*
netif
,
uint64_t
cur_ts
)
{
void
PollN2M
(
struct
SimbricksNetIf
*
netif
,
uint64_t
cur_ts
)
{
volatile
union
SimbricksProtoNetMsg
*
msg
=
SimbricksNetIfInPoll
(
netif
,
cur_ts
);
volatile
union
SimbricksProtoNetMsg
*
msg
=
SimbricksNetIfInPoll
(
netif
,
cur_ts
);
if
(
msg
==
NULL
){
if
(
msg
==
NULL
){
return
;
return
;
}
}
uint8_t
type
;
int
i
;
uint8_t
type
,
type_mem
;
uint64_t
addr
,
len
;
volatile
uint8_t
*
data
;
volatile
union
SimbricksProtoNetMsg
*
msg_to
;
volatile
struct
SimbricksProtoNetMsgPacket
*
packet
=
&
msg
->
packet
;
type
=
SimbricksNetIfInType
(
netif
,
msg
);
type
=
SimbricksNetIfInType
(
netif
,
msg
);
switch
(
type
)
{
switch
(
type
)
{
case
SIMBRICKS_PROTO_NET_MSG_PACKET
:
case
SIMBRICKS_PROTO_NET_MSG_PACKET
:
handlePacket
(
netif
,
&
msg
->
packet
);
printf
(
"received network packet
\n
"
);
struct
ethhdr
*
eth_hdr
;
struct
iphdr
*
ip_hdr
;
struct
udphdr
*
udp_hdr
;
struct
MemOp
*
memop
;
void
*
data
;
eth_hdr
=
(
struct
ethhdr
*
)
packet
->
data
;
ip_hdr
=
(
struct
iphdr
*
)(
eth_hdr
+
1
);
udp_hdr
=
(
struct
udphdr
*
)(
ip_hdr
+
1
);
memop
=
(
struct
MemOp
*
)(
udp_hdr
+
1
);
data
=
(
void
*
)(
memop
+
1
);
type_mem
=
memop
->
OpType
;
switch
(
type_mem
)
{
case
SIMBRICKS_PROTO_MEM_H2M_MSG_READ
:
printf
(
"NetMem received read request
\n
"
);
break
;
case
SIMBRICKS_PROTO_MEM_H2M_MSG_WRITE
:
printf
(
"NetMem received write request
\n
"
);
break
;
default:
fprintf
(
stderr
,
"ForwardToETH: unsupported type=%u
\n
"
,
type
);
}
break
;
break
;
case
SIMBRICKS_PROTO_MSG_TYPE_SYNC
:
case
SIMBRICKS_PROTO_MSG_TYPE_SYNC
:
...
@@ -96,62 +132,104 @@ void PollN2M(SimbricksNetIf *netif, uint64_t cur_ts) {
...
@@ -96,62 +132,104 @@ void PollN2M(SimbricksNetIf *netif, uint64_t cur_ts) {
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
int
asid
=
0
;
signal
(
SIGINT
,
sigint_handler
);
signal
(
SIGINT
,
sigint_handler
);
signal
(
SIGUSR1
,
sigusr1_handler
);
signal
(
SIGUSR1
,
sigusr1_handler
);
int
sync_net
=
1
;
uint64_t
next_ts
=
0
;
uint64_t
ts_a
=
0
;
const
char
*
shmPath
;
struct
SimbricksBaseIfParams
netParams
;
struct
SimbricksBaseIfParams
netParams
;
struct
SimbricksNetIf
netif
;
struct
SimbricksNicIf
netif
;
const
char
*
shmPath
;
SimbricksNetIfDefaultParams
(
&
netParams
);
SimbricksNetIfDefaultParams
(
&
netParams
);
if
(
argc
<
4
||
argc
>
7
)
{
if
(
argc
<
7
||
argc
>
11
)
{
fprintf
(
stderr
,
fprintf
(
stderr
,
"Usage: netmem ETH-SOCKET"
"Usage: netmem [SIZE] [BASE-ADDR] [ASID] [ETH-SOCKET] "
"SHM [SYNC-MODE] [START-TICK] [SYNC-PERIOD]"
"[SHM] [MAC-ADDR] [SYNC-MODE] [START-TICK] [SYNC-PERIOD] [ETH-LATENCY]
\n
"
);
"[ETH-LATENCY]
\n
"
);
return
-
1
;
return
-
1
;
}
}
if
(
argc
>=
9
)
cur_ts
=
strtoull
(
argv
[
8
],
NULL
,
0
);
if
(
argc
>=
10
)
netParams
.
sync_interval
=
strtoull
(
argv
[
9
],
NULL
,
0
)
*
1000ULL
;
if
(
argc
>=
11
)
netParams
.
link_latency
=
strtoull
(
argv
[
10
],
NULL
,
0
)
*
1000ULL
;
size
=
strtoull
(
argv
[
1
],
NULL
,
0
);
base_addr
=
strtoull
(
argv
[
2
],
NULL
,
0
);
asid
=
atoi
(
argv
[
3
]);
netParams
.
sock_path
=
argv
[
4
];
shmPath
=
argv
[
5
];
mac_addr
.
mac_64
=
strtoull
(
argv
[
6
],
NULL
,
16
);
printf
(
"mac_byte: %lx
\n
"
,
mac_addr
.
mac_64
);
printf
(
"mac_8: %X:%X:%X:%X:%X:%X
\n
"
,
mac_addr
.
mac_byte
[
0
],
mac_addr
.
mac_byte
[
1
],
mac_addr
.
mac_byte
[
2
],
mac_addr
.
mac_byte
[
3
],
mac_addr
.
mac_byte
[
4
],
mac_addr
.
mac_byte
[
5
]);
if
(
argc
>=
5
)
netParams
.
sync_mode
=
kSimbricksBaseIfSyncOptional
;
cur_ts
=
strtoull
(
argv
[
4
],
NULL
,
0
);
netParams
.
blocking_conn
=
false
;
if
(
argc
>=
6
)
//netif.base.sync = sync_mem;
netParams
.
sync_interval
=
strtoull
(
argv
[
5
],
NULL
,
0
)
*
1000ULL
;
if
(
argc
>=
7
)
netParams
.
link_latency
=
strtoull
(
argv
[
6
],
NULL
,
0
)
*
1000ULL
;
netParams
.
sock_path
=
argv
[
1
];
mem_array
=
(
uint8_t
*
)
malloc
(
size
*
sizeof
(
uint8_t
));
shmPath
=
argv
[
2
];
netParams
.
sync_mode
=
kSimbricksBaseIfSyncOptional
;
if
(
!
mem_array
){
perror
(
"no array allocated
\n
"
);
}
netif
.
net
.
base
.
sync
=
sync_net
;
size_t
shm_size
=
0
;
shm_size
+=
netParams
.
in_num_entries
*
netParams
.
in_entries_size
;
shm_size
+=
netParams
.
out_num_entries
*
netParams
.
out_entries_size
;
if
(
SimbricksNicIfInit
(
&
netif
,
shmPath
,
&
netParams
,
NULL
,
NULL
)){
std
::
string
shm_path_
=
shmPath
;
fprintf
(
stderr
,
"nicif init error happens"
);
struct
SimbricksBaseIfSHMPool
pool_
;
return
-
1
;
memset
(
&
pool_
,
0
,
sizeof
(
pool_
));
if
(
SimbricksBaseIfInit
(
&
netif
.
base
,
&
netParams
)){
perror
(
"Init: SimbricksBaseIfInit failed
\n
"
);
return
EXIT_FAILURE
;
}
if
(
SimbricksBaseIfSHMPoolCreate
(
&
pool_
,
shm_path_
.
c_str
(),
shm_size
)
!=
0
)
{
perror
(
"NetMemIfInit: SimbricksBaseIfSHMPoolCreate failed"
);
return
false
;
}
if
(
SimbricksBaseIfListen
(
&
netif
.
base
,
&
pool_
)){
perror
(
"SimbricksBaseIfConnect failed"
);
return
false
;
}
}
struct
SimBricksBaseIfEstablishData
ests
[
1
];
struct
SimbricksProtoNetIntro
intro
;
ests
[
0
].
base_if
=
&
netif
.
base
;
ests
[
0
].
tx_intro
=
&
intro
;
ests
[
0
].
tx_intro_len
=
sizeof
(
intro
);
ests
[
0
].
rx_intro
=
&
intro
;
ests
[
0
].
rx_intro_len
=
sizeof
(
intro
);
if
(
SimBricksBaseIfEstablish
(
ests
,
1
))
{
fprintf
(
stderr
,
"SimBricksBaseIfEstablish failed
\n
"
);
return
false
;
}
sync_mem
=
SimbricksBaseIfSyncEnabled
(
&
netif
.
base
);
f
printf
(
stderr
,
"start polling
\n
"
);
printf
(
"start polling
\n
"
);
while
(
!
exiting
){
while
(
!
exiting
){
while
(
SimbricksNetIfOutSync
(
&
netif
,
cur_ts
))
{
while
(
SimbricksNetIfOutSync
(
&
netif
.
net
,
cur_ts
))
{
//fprintf(stderr, "warn: SimbricksNetIfSync failed (t=%lu)\n", cur_ts);
fprintf
(
stderr
,
"warn: SimbricksNicifSync failed (netif=%lu)
\n
"
,
cur_ts
);
}
}
do
{
do
{
PollN2M
(
&
netif
.
net
,
cur_ts
);
ts_a
=
SimbricksNetIfInTimestamp
(
&
netif
.
net
);
PollN2M
(
&
netif
,
cur_ts
);
}
while
(
!
exiting
&&
((
sync_net
&&
ts_a
<=
cur_ts
)));
if
(
sync_mem
){
next_ts
=
SimbricksNetIfInTimestamp
(
&
netif
);
}
if
(
sync_net
)
}
while
(
!
exiting
&&
next_ts
<=
cur_ts
);
cur_ts
=
ts_a
;
}
}
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