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
0a67f9b1
Commit
0a67f9b1
authored
Sep 16, 2020
by
Antoine Kaufmann
Browse files
libnicbm: support for scheduled events
parent
ff491d33
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
4 deletions
+82
-4
libnicbm/include/nicbm.h
libnicbm/include/nicbm.h
+27
-0
libnicbm/nicbm.cc
libnicbm/nicbm.cc
+55
-4
No files found.
libnicbm/include/nicbm.h
View file @
0a67f9b1
#include <set>
namespace
nicbm
{
namespace
nicbm
{
#include <cassert>
#include <cassert>
...
@@ -17,6 +19,13 @@ class DMAOp {
...
@@ -17,6 +19,13 @@ class DMAOp {
void
*
data
;
void
*
data
;
};
};
class
TimedEvent
{
public:
virtual
~
TimedEvent
()
{
}
uint64_t
time
;
};
/**
/**
* The Runner drives the main simulation loop. It's initialized with a reference
* The Runner drives the main simulation loop. It's initialized with a reference
* to a device it should manage, and then once `runMain` is called, it will
* to a device it should manage, and then once `runMain` is called, it will
...
@@ -59,10 +68,23 @@ class Runner {
...
@@ -59,10 +68,23 @@ class Runner {
*/
*/
virtual
void
eth_rx
(
uint8_t
port
,
const
void
*
data
,
size_t
len
)
virtual
void
eth_rx
(
uint8_t
port
,
const
void
*
data
,
size_t
len
)
=
0
;
=
0
;
/**
* A timed event is due.
*/
virtual
void
timed_event
(
TimedEvent
&
ev
);
};
};
protected:
protected:
struct
event_cmp
{
bool
operator
()
(
TimedEvent
*
a
,
TimedEvent
*
b
)
{
return
a
->
time
<
b
->
time
;
}
};
Device
&
dev
;
Device
&
dev
;
std
::
set
<
TimedEvent
*
,
event_cmp
>
events
;
uint64_t
mac_addr
;
uint64_t
mac_addr
;
struct
nicsim_params
nsparams
;
struct
nicsim_params
nsparams
;
struct
cosim_pcie_proto_dev_intro
dintro
;
struct
cosim_pcie_proto_dev_intro
dintro
;
...
@@ -79,6 +101,8 @@ class Runner {
...
@@ -79,6 +101,8 @@ class Runner {
void
eth_recv
(
volatile
struct
cosim_eth_proto_n2d_recv
*
recv
);
void
eth_recv
(
volatile
struct
cosim_eth_proto_n2d_recv
*
recv
);
void
poll_n2d
();
void
poll_n2d
();
bool
event_next
(
uint64_t
&
retval
);
void
event_trigger
();
public:
public:
Runner
(
Device
&
dev_
);
Runner
(
Device
&
dev_
);
...
@@ -90,6 +114,9 @@ class Runner {
...
@@ -90,6 +114,9 @@ class Runner {
void
msi_issue
(
uint8_t
vec
);
void
msi_issue
(
uint8_t
vec
);
void
eth_send
(
const
void
*
data
,
size_t
len
);
void
eth_send
(
const
void
*
data
,
size_t
len
);
void
event_schedule
(
TimedEvent
&
evt
);
void
event_cancel
(
TimedEvent
&
evt
);
uint64_t
time_ps
()
const
;
uint64_t
time_ps
()
const
;
uint64_t
get_mac_addr
()
const
;
uint64_t
get_mac_addr
()
const
;
};
};
...
...
libnicbm/nicbm.cc
View file @
0a67f9b1
...
@@ -113,6 +113,16 @@ void Runner::msi_issue(uint8_t vec)
...
@@ -113,6 +113,16 @@ void Runner::msi_issue(uint8_t vec)
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
}
}
void
Runner
::
event_schedule
(
TimedEvent
&
evt
)
{
events
.
insert
(
&
evt
);
}
void
Runner
::
event_cancel
(
TimedEvent
&
evt
)
{
events
.
erase
(
&
evt
);
}
void
Runner
::
h2d_read
(
volatile
struct
cosim_pcie_proto_h2d_read
*
read
)
void
Runner
::
h2d_read
(
volatile
struct
cosim_pcie_proto_h2d_read
*
read
)
{
{
volatile
union
cosim_pcie_proto_d2h
*
msg
;
volatile
union
cosim_pcie_proto_d2h
*
msg
;
...
@@ -281,8 +291,33 @@ uint64_t Runner::get_mac_addr() const
...
@@ -281,8 +291,33 @@ uint64_t Runner::get_mac_addr() const
return
mac_addr
;
return
mac_addr
;
}
}
bool
Runner
::
event_next
(
uint64_t
&
retval
)
{
if
(
events
.
empty
())
return
false
;
retval
=
(
*
events
.
begin
())
->
time
;
return
true
;
}
void
Runner
::
event_trigger
()
{
auto
it
=
events
.
begin
();
if
(
it
==
events
.
end
())
return
;
TimedEvent
*
ev
=
*
it
;
// event is in the future
if
(
ev
->
time
>
main_time
)
return
;
events
.
erase
(
it
);
dev
.
timed_event
(
*
ev
);
}
Runner
::
Runner
(
Device
&
dev_
)
Runner
::
Runner
(
Device
&
dev_
)
:
dev
(
dev_
)
:
dev
(
dev_
)
,
events
(
event_cmp
())
{
{
//mac_addr = lrand48() & ~(3ULL << 46);
//mac_addr = lrand48() & ~(3ULL << 46);
srand48
(
time
(
NULL
)
^
getpid
());
srand48
(
time
(
NULL
)
^
getpid
());
...
@@ -327,6 +362,8 @@ int Runner::runMain(int argc, char *argv[])
...
@@ -327,6 +362,8 @@ int Runner::runMain(int argc, char *argv[])
fprintf
(
stderr
,
"sync_pci=%d sync_eth=%d
\n
"
,
nsparams
.
sync_pci
,
fprintf
(
stderr
,
"sync_pci=%d sync_eth=%d
\n
"
,
nsparams
.
sync_pci
,
nsparams
.
sync_eth
);
nsparams
.
sync_eth
);
bool
is_sync
=
nsparams
.
sync_pci
||
nsparams
.
sync_eth
;
while
(
!
exiting
)
{
while
(
!
exiting
)
{
while
(
nicsim_sync
(
&
nsparams
,
main_time
))
{
while
(
nicsim_sync
(
&
nsparams
,
main_time
))
{
fprintf
(
stderr
,
"warn: nicsim_sync failed (t=%lu)
\n
"
,
main_time
);
fprintf
(
stderr
,
"warn: nicsim_sync failed (t=%lu)
\n
"
,
main_time
);
...
@@ -335,9 +372,19 @@ int Runner::runMain(int argc, char *argv[])
...
@@ -335,9 +372,19 @@ int Runner::runMain(int argc, char *argv[])
do
{
do
{
poll_h2d
();
poll_h2d
();
poll_n2d
();
poll_n2d
();
next_ts
=
netsim_next_timestamp
(
&
nsparams
);
event_trigger
();
}
while
((
nsparams
.
sync_pci
||
nsparams
.
sync_eth
)
&&
next_ts
<=
main_time
&&
!
exiting
);
if
(
is_sync
)
{
next_ts
=
netsim_next_timestamp
(
&
nsparams
);
}
else
{
next_ts
=
main_time
+
100000
;
}
uint64_t
ev_ts
;
if
(
event_next
(
ev_ts
)
&&
ev_ts
<
next_ts
)
next_ts
=
ev_ts
;
}
while
(
next_ts
<=
main_time
&&
!
exiting
);
main_time
=
next_ts
;
main_time
=
next_ts
;
}
}
...
@@ -345,3 +392,7 @@ int Runner::runMain(int argc, char *argv[])
...
@@ -345,3 +392,7 @@ int Runner::runMain(int argc, char *argv[])
nicsim_cleanup
();
nicsim_cleanup
();
return
0
;
return
0
;
}
}
void
Runner
::
Device
::
timed_event
(
TimedEvent
&
te
)
{
}
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