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
bfdc0f43
Commit
bfdc0f43
authored
Dec 21, 2024
by
Jonas Kaufmann
Browse files
orchestration/instantiation/base: refactor classes Socket and SockType to a separate module
parent
f8a938ff
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
91 additions
and
62 deletions
+91
-62
symphony/orchestration/simbricks/orchestration/instantiation/base.py
...chestration/simbricks/orchestration/instantiation/base.py
+24
-37
symphony/orchestration/simbricks/orchestration/instantiation/socket.py
...estration/simbricks/orchestration/instantiation/socket.py
+37
-0
symphony/orchestration/simbricks/orchestration/simulation/base.py
.../orchestration/simbricks/orchestration/simulation/base.py
+17
-16
symphony/orchestration/simbricks/orchestration/simulation/host.py
.../orchestration/simbricks/orchestration/simulation/host.py
+2
-1
symphony/orchestration/simbricks/orchestration/simulation/net/net_base.py
...ration/simbricks/orchestration/simulation/net/net_base.py
+4
-3
symphony/orchestration/simbricks/orchestration/simulation/pcidev.py
...rchestration/simbricks/orchestration/simulation/pcidev.py
+5
-4
symphony/runtime/simbricks/runtime/simulation_executor.py
symphony/runtime/simbricks/runtime/simulation_executor.py
+2
-1
No files found.
symphony/orchestration/simbricks/orchestration/instantiation/base.py
View file @
bfdc0f43
...
...
@@ -22,7 +22,6 @@
from
__future__
import
annotations
import
enum
import
pathlib
import
shutil
import
typing
...
...
@@ -35,25 +34,13 @@ from simbricks.orchestration.system import pcie as sys_pcie
from
simbricks.orchestration.system
import
mem
as
sys_mem
from
simbricks.orchestration.system
import
eth
as
sys_eth
from
simbricks.orchestration.system.host
import
disk_images
from
simbricks.orchestration.instantiation
import
inst_socket
if
typing
.
TYPE_CHECKING
:
from
simbricks.orchestration.simulation
import
base
as
sim_base
from
simbricks.runtime
import
command_executor
class
SockType
(
enum
.
Enum
):
LISTEN
=
enum
.
auto
()
CONNECT
=
enum
.
auto
()
class
Socket
(
util_base
.
IdObj
):
def
__init__
(
self
,
path
:
str
=
""
,
ty
:
SockType
=
SockType
.
LISTEN
):
super
().
__init__
()
self
.
_path
=
path
self
.
_type
=
ty
class
InstantiationEnvironment
(
util_base
.
IdObj
):
def
__init__
(
...
...
@@ -94,7 +81,7 @@ class Instantiation():
self
.
_preserve_checkpoints
:
bool
=
True
self
.
preserve_tmp_folder
:
bool
=
False
# NOTE: temporary data structure
self
.
_socket_per_interface
:
dict
[
sys_base
.
Interface
,
Socket
]
=
{}
self
.
_socket_per_interface
:
dict
[
sys_base
.
Interface
,
inst_socket
.
Socket
]
=
{}
# NOTE: temporary data structure
self
.
_sim_dependency
:
(
dict
[
sim_base
.
Simulator
,
set
[
sim_base
.
Simulator
]]
|
None
...
...
@@ -137,21 +124,21 @@ class Instantiation():
)
def
_updated_tracker_mapping
(
self
,
interface
:
sys_base
.
Interface
,
socket
:
Socket
self
,
interface
:
sys_base
.
Interface
,
socket
:
inst_socket
.
Socket
)
->
None
:
# update interface mapping
if
interface
in
self
.
_socket_per_interface
:
raise
Exception
(
"an interface cannot be associated with two sockets"
)
self
.
_socket_per_interface
[
interface
]
=
socket
def
_get_socket_by_interface
(
self
,
interface
:
sys_base
.
Interface
)
->
Socket
|
None
:
def
_get_socket_by_interface
(
self
,
interface
:
sys_base
.
Interface
)
->
inst_socket
.
Socket
|
None
:
if
interface
not
in
self
.
_socket_per_interface
:
return
None
return
self
.
_socket_per_interface
[
interface
]
def
_get_opposing_socket_by_interface
(
self
,
interface
:
sys_base
.
Interface
)
->
Socket
|
None
:
)
->
inst_socket
.
Socket
|
None
:
opposing_interface
=
self
.
_get_opposing_interface
(
interface
=
interface
)
socket
=
self
.
_get_socket_by_interface
(
interface
=
opposing_interface
)
return
socket
...
...
@@ -179,27 +166,27 @@ class Instantiation():
enforce_existence
=
False
,
)
def
_create_opposing_socket
(
self
,
socket
:
Socket
,
socket_type
:
SockType
)
->
Socket
:
def
_create_opposing_socket
(
self
,
socket
:
inst_socket
.
Socket
,
socket_type
:
inst_socket
.
SockType
)
->
inst_socket
.
Socket
:
new_ty
=
(
SockType
.
LISTEN
if
socket
.
_type
==
SockType
.
CONNECT
else
SockType
.
CONNECT
inst_socket
.
SockType
.
LISTEN
if
socket
.
_type
==
inst_socket
.
SockType
.
CONNECT
else
inst_socket
.
SockType
.
CONNECT
)
if
new_ty
!=
socket_type
:
raise
Exception
(
f
"cannot create opposing socket, as required type is not supported: required=
{
new_ty
.
name
}
, supported=
{
socket_type
.
name
}
"
)
new_path
=
socket
.
_path
new_socket
=
Socket
(
path
=
new_path
,
ty
=
new_ty
)
new_socket
=
inst_socket
.
Socket
(
path
=
new_path
,
ty
=
new_ty
)
return
new_socket
def
get_socket
(
self
,
interface
:
sys_base
.
Interface
)
->
Socket
|
None
:
def
get_socket
(
self
,
interface
:
sys_base
.
Interface
)
->
inst_socket
.
Socket
|
None
:
socket
=
self
.
_get_socket_by_interface
(
interface
=
interface
)
if
socket
:
return
socket
return
None
def
_get_socket
(
self
,
interface
:
sys_base
.
Interface
,
socket_type
:
SockType
)
->
Socket
:
self
,
interface
:
sys_base
.
Interface
,
socket_type
:
inst_socket
.
SockType
)
->
inst_socket
.
Socket
:
if
self
.
_opposing_interface_within_same_sim
(
interface
=
interface
):
raise
Exception
(
...
...
@@ -223,7 +210,7 @@ class Instantiation():
# create socket if opposing socket was not created yet
sock_path
=
self
.
_interface_to_sock_path
(
interface
=
interface
)
new_socket
=
Socket
(
path
=
sock_path
,
ty
=
socket_type
)
new_socket
=
inst_socket
.
Socket
(
path
=
sock_path
,
ty
=
socket_type
)
self
.
_updated_tracker_mapping
(
interface
=
interface
,
socket
=
new_socket
)
print
(
f
"created socket:
{
new_socket
.
_path
}
"
)
return
new_socket
...
...
@@ -252,32 +239,32 @@ class Instantiation():
def
update_a_depends_on_b
(
inf_a
:
sys_base
.
Interface
,
inf_b
:
sys_base
.
Interface
):
sim_a
=
self
.
find_sim_by_interface
(
interface
=
inf_a
)
sim_b
=
self
.
find_sim_by_interface
(
interface
=
inf_b
)
a_sock
:
set
[
SockType
]
=
sim_a
.
supported_socket_types
(
interface
=
inf_a
)
b_sock
:
set
[
SockType
]
=
sim_b
.
supported_socket_types
(
interface
=
inf_b
)
a_sock
:
set
[
inst_socket
.
SockType
]
=
sim_a
.
supported_socket_types
(
interface
=
inf_a
)
b_sock
:
set
[
inst_socket
.
SockType
]
=
sim_b
.
supported_socket_types
(
interface
=
inf_b
)
if
a_sock
!=
b_sock
:
if
len
(
a_sock
)
==
0
or
len
(
b_sock
)
==
0
:
raise
Exception
(
"cannot create socket and resolve dependency if no socket type is supported for an interface"
)
if
SockType
.
CONNECT
in
a_sock
:
assert
SockType
.
LISTEN
in
b_sock
if
inst_socket
.
SockType
.
CONNECT
in
a_sock
:
assert
inst_socket
.
SockType
.
LISTEN
in
b_sock
insert_dependency
(
sim_a
,
depends_on
=
sim_b
)
self
.
_get_socket
(
interface
=
inf_a
,
socket_type
=
SockType
.
CONNECT
)
self
.
_get_socket
(
interface
=
inf_b
,
socket_type
=
SockType
.
LISTEN
)
self
.
_get_socket
(
interface
=
inf_a
,
socket_type
=
inst_socket
.
SockType
.
CONNECT
)
self
.
_get_socket
(
interface
=
inf_b
,
socket_type
=
inst_socket
.
SockType
.
LISTEN
)
else
:
assert
SockType
.
CONNECT
in
b_sock
assert
inst_socket
.
SockType
.
CONNECT
in
b_sock
insert_dependency
(
sim_b
,
depends_on
=
sim_a
)
self
.
_get_socket
(
interface
=
inf_b
,
socket_type
=
SockType
.
CONNECT
)
self
.
_get_socket
(
interface
=
inf_a
,
socket_type
=
SockType
.
LISTEN
)
self
.
_get_socket
(
interface
=
inf_b
,
socket_type
=
inst_socket
.
SockType
.
CONNECT
)
self
.
_get_socket
(
interface
=
inf_a
,
socket_type
=
inst_socket
.
SockType
.
LISTEN
)
else
:
# deadlock?
if
len
(
a_sock
)
!=
2
or
len
(
b_sock
)
!=
2
:
raise
Exception
(
"cannot solve deadlock"
)
# both support both we just pick an order
insert_dependency
(
sim_a
,
depends_on
=
sim_b
)
self
.
_get_socket
(
interface
=
sim_a
,
socket_type
=
SockType
.
CONNECT
)
self
.
_get_socket
(
interface
=
sim_b
,
socket_type
=
SockType
.
LISTEN
)
self
.
_get_socket
(
interface
=
sim_a
,
socket_type
=
inst_socket
.
SockType
.
CONNECT
)
self
.
_get_socket
(
interface
=
sim_b
,
socket_type
=
inst_socket
.
SockType
.
LISTEN
)
# build dependency graph
for
sim
in
self
.
simulation
.
all_simulators
():
...
...
@@ -299,7 +286,7 @@ class Instantiation():
async
def
wait_for_sockets
(
self
,
sockets
:
list
[
Socket
]
=
[],
sockets
:
list
[
inst_socket
.
Socket
]
=
[],
)
->
None
:
wait_socks
=
list
(
map
(
lambda
sock
:
sock
.
_path
,
sockets
))
await
self
.
executor
.
await_files
(
wait_socks
,
verbose
=
True
)
...
...
symphony/orchestration/simbricks/orchestration/instantiation/socket.py
0 → 100644
View file @
bfdc0f43
# Copyright 2022 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import
enum
from
simbricks.utils
import
base
as
util_base
class
SockType
(
enum
.
Enum
):
LISTEN
=
enum
.
auto
()
CONNECT
=
enum
.
auto
()
class
Socket
(
util_base
.
IdObj
):
def
__init__
(
self
,
path
:
str
=
""
,
ty
:
SockType
=
SockType
.
LISTEN
):
super
().
__init__
()
self
.
_path
=
path
self
.
_type
=
ty
symphony/orchestration/simbricks/orchestration/simulation/base.py
View file @
bfdc0f43
...
...
@@ -27,6 +27,7 @@ import asyncio
import
typing
as
tp
import
simbricks.orchestration.system
as
sys_conf
import
simbricks.orchestration.instantiation.base
as
inst_base
import
simbricks.orchestration.instantiation.socket
as
inst_socket
import
simbricks.orchestration.simulation.channel
as
sim_chan
import
simbricks.utils.base
as
utils_base
...
...
@@ -146,21 +147,21 @@ class Simulator(utils_base.IdObj):
@
staticmethod
def
filter_sockets
(
sockets
:
list
[
inst_
base
.
Socket
],
filter_type
:
inst_
base
.
S
ockType
=
inst_
base
.
S
ockType
.
LISTEN
,
)
->
list
[
inst_
base
.
Socket
]:
sockets
:
list
[
inst_
socket
.
Socket
],
filter_type
:
inst_
socket
.
s
ockType
=
inst_
socket
.
s
ockType
.
LISTEN
,
)
->
list
[
inst_
socket
.
Socket
]:
res
=
list
(
filter
(
lambda
sock
:
sock
.
_type
==
filter_type
,
sockets
))
return
res
@
staticmethod
def
split_sockets_by_type
(
sockets
:
list
[
inst_
base
.
Socket
],
)
->
tuple
[
list
[
inst_
base
.
Socket
],
list
[
inst_
base
.
Socket
]]:
sockets
:
list
[
inst_
socket
.
Socket
],
)
->
tuple
[
list
[
inst_
socket
.
Socket
],
list
[
inst_
socket
.
Socket
]]:
listen
=
Simulator
.
filter_sockets
(
sockets
=
sockets
,
filter_type
=
inst_
base
.
S
ockType
.
LISTEN
sockets
=
sockets
,
filter_type
=
inst_
socket
.
s
ockType
.
LISTEN
)
connect
=
Simulator
.
filter_sockets
(
sockets
=
sockets
,
filter_type
=
inst_
base
.
S
ockType
.
CONNECT
sockets
=
sockets
,
filter_type
=
inst_
socket
.
s
ockType
.
CONNECT
)
return
listen
,
connect
...
...
@@ -229,7 +230,7 @@ class Simulator(utils_base.IdObj):
def
_get_socks_by_comp
(
self
,
inst
:
inst_base
.
Instantiation
,
comp
:
sys_conf
.
Component
)
->
list
[
inst_
base
.
Socket
]:
)
->
list
[
inst_
socket
.
Socket
]:
if
comp
not
in
self
.
_components
:
raise
Exception
(
"comp must be a simulators component"
)
sockets
=
[]
...
...
@@ -241,15 +242,15 @@ class Simulator(utils_base.IdObj):
def
_get_socks_by_all_comp
(
self
,
inst
:
inst_base
.
Instantiation
)
->
list
[
inst_
base
.
Socket
]:
)
->
list
[
inst_
socket
.
Socket
]:
sockets
=
[]
for
comp
in
self
.
_components
:
sockets
.
extend
(
self
.
_get_socks_by_comp
(
inst
=
inst
,
comp
=
comp
))
return
sockets
def
_get_all_sockets_by_type
(
self
,
inst
:
inst_base
.
Instantiation
,
sock_type
:
inst_
base
.
S
ockType
)
->
list
[
inst_
base
.
Socket
]:
self
,
inst
:
inst_base
.
Instantiation
,
sock_type
:
inst_
socket
.
s
ockType
)
->
list
[
inst_
socket
.
Socket
]:
sockets
=
self
.
_get_socks_by_all_comp
(
inst
=
inst
)
sockets
=
Simulator
.
filter_sockets
(
sockets
=
sockets
,
filter_type
=
sock_type
)
return
sockets
...
...
@@ -285,21 +286,21 @@ class Simulator(utils_base.IdObj):
@
abc
.
abstractmethod
def
supported_socket_types
(
self
,
interface
:
sys_conf
.
Interface
)
->
set
[
inst_
base
.
S
ockType
]:
)
->
set
[
inst_
socket
.
s
ockType
]:
return
[]
# Sockets to be cleaned up: always the CONNECTING sockets
# pylint: disable=unused-argument
def
sockets_cleanup
(
self
,
inst
:
inst_base
.
Instantiation
)
->
list
[
inst_
base
.
Socket
]:
def
sockets_cleanup
(
self
,
inst
:
inst_base
.
Instantiation
)
->
list
[
inst_
socket
.
Socket
]:
return
self
.
_get_all_sockets_by_type
(
inst
=
inst
,
sock_type
=
inst_
base
.
S
ockType
.
LISTEN
inst
=
inst
,
sock_type
=
inst_
socket
.
s
ockType
.
LISTEN
)
# sockets to wait for indicating the simulator is ready
# pylint: disable=unused-argument
def
sockets_wait
(
self
,
inst
:
inst_base
.
Instantiation
)
->
list
[
inst_
base
.
Socket
]:
def
sockets_wait
(
self
,
inst
:
inst_base
.
Instantiation
)
->
list
[
inst_
socket
.
Socket
]:
return
self
.
_get_all_sockets_by_type
(
inst
=
inst
,
sock_type
=
inst_
base
.
S
ockType
.
LISTEN
inst
=
inst
,
sock_type
=
inst_
socket
.
s
ockType
.
LISTEN
)
def
start_delay
(
self
)
->
int
:
...
...
symphony/orchestration/simbricks/orchestration/simulation/host.py
View file @
bfdc0f43
...
...
@@ -31,6 +31,7 @@ from simbricks.orchestration.system import host as sys_host
from
simbricks.orchestration.system
import
pcie
as
sys_pcie
from
simbricks.orchestration.system
import
mem
as
sys_mem
from
simbricks.utils
import
base
as
utils_base
from
simbricks.orchestration.instantiation
import
socket
as
inst_socket
class
HostSim
(
sim_base
.
Simulator
):
...
...
@@ -60,7 +61,7 @@ class HostSim(sim_base.Simulator):
def
supported_socket_types
(
self
,
interface
:
system
.
Interface
)
->
set
[
inst_base
.
SockType
]:
return
[
inst_
base
.
SockType
.
CONNECT
]
return
[
inst_
socket
.
SockType
.
CONNECT
]
class
Gem5Sim
(
HostSim
):
...
...
symphony/orchestration/simbricks/orchestration/simulation/net/net_base.py
View file @
bfdc0f43
...
...
@@ -26,6 +26,7 @@ from simbricks.orchestration.system import base as sys_base
from
simbricks.orchestration.system
import
eth
as
sys_eth
from
simbricks.orchestration.simulation
import
base
as
sim_base
from
simbricks.orchestration.instantiation
import
base
as
inst_base
from
simbricks.orchestration.instantiation
import
socket
as
inst_socket
from
simbricks.utils
import
base
as
base_utils
...
...
@@ -48,7 +49,7 @@ class NetSim(sim_base.Simulator):
def
supported_socket_types
(
self
,
interface
:
sys_base
.
Interface
)
->
set
[
inst_
base
.
SockType
]:
)
->
set
[
inst_
socket
.
SockType
]:
return
[
inst_base
.
SockType
.
CONNECT
]
def
toJSON
(
self
)
->
dict
:
...
...
@@ -293,12 +294,12 @@ class NS3DumbbellNet(SimpleNS3Sim):
left_socks
=
self
.
_get_socks_by_comp
(
inst
=
inst
,
comp
=
self
.
_left
)
for
sock
in
left_socks
:
assert
sock
.
_type
==
inst_
base
.
SockType
.
CONNECT
assert
sock
.
_type
==
inst_
socket
.
SockType
.
CONNECT
cmd
+=
f
"--SimbricksPortLeft=
{
sock
.
_path
}
"
right_sockets
=
self
.
_get_socks_by_comp
(
inst
=
inst
,
comp
=
self
.
_right
)
for
sock
in
right_sockets
:
assert
sock
.
_type
==
inst_
base
.
SockType
.
CONNECT
assert
sock
.
_type
==
inst_
socket
.
SockType
.
CONNECT
cmd
+=
f
"--SimbricksPortRight=
{
sock
.
_path
}
"
if
self
.
opt
is
not
None
:
...
...
symphony/orchestration/simbricks/orchestration/simulation/pcidev.py
View file @
bfdc0f43
...
...
@@ -27,6 +27,7 @@ from simbricks.orchestration.system import pcie as sys_pcie
from
simbricks.orchestration.system
import
eth
as
sys_eth
from
simbricks.orchestration.system
import
nic
as
sys_nic
from
simbricks.orchestration.instantiation
import
base
as
inst_base
from
simbricks.orchestration.instantiation
import
socket
as
inst_socket
from
simbricks.orchestration.simulation
import
base
as
sim_base
...
...
@@ -43,8 +44,8 @@ class PCIDevSim(sim_base.Simulator):
def
supported_socket_types
(
self
,
interface
:
sys_base
.
Interface
)
->
set
[
inst_
base
.
SockType
]:
return
[
inst_
base
.
SockType
.
LISTEN
]
)
->
set
[
inst_
socket
.
SockType
]:
return
[
inst_
socket
.
SockType
.
LISTEN
]
class
NICSim
(
PCIDevSim
):
...
...
@@ -75,11 +76,11 @@ class NICSim(PCIDevSim):
nic_device
=
nic_devices
[
0
]
socket
=
inst
.
get_socket
(
interface
=
nic_device
.
_pci_if
)
assert
socket
is
not
None
and
socket
.
_type
==
inst_
base
.
SockType
.
LISTEN
assert
socket
is
not
None
and
socket
.
_type
==
inst_
socket
.
SockType
.
LISTEN
cmd
+=
f
"
{
socket
.
_path
}
"
socket
=
inst
.
get_socket
(
interface
=
nic_device
.
_eth_if
)
assert
socket
is
not
None
and
socket
.
_type
==
inst_
base
.
SockType
.
LISTEN
assert
socket
is
not
None
and
socket
.
_type
==
inst_
socket
.
SockType
.
LISTEN
cmd
+=
f
"
{
socket
.
_path
}
"
cmd
+=
(
...
...
symphony/runtime/simbricks/runtime/simulation_executor.py
View file @
bfdc0f43
...
...
@@ -30,6 +30,7 @@ import abc
from
simbricks.runtime
import
output
from
simbricks.orchestration.simulation
import
base
as
sim_base
from
simbricks.orchestration.instantiation
import
base
as
inst_base
from
simbricks.orchestration.instantiation
import
socket
as
inst_socket
from
simbricks.runtime
import
command_executor
from
simbricks.utils
import
graphlib
...
...
@@ -47,7 +48,7 @@ class SimulationBaseRunner(abc.ABC):
self
.
_out
:
output
.
SimulationOutput
=
output
.
SimulationOutput
(
self
.
_instantiation
.
simulation
)
self
.
_out_listener
:
dict
[
sim_base
.
Simulator
,
command_executor
.
OutputListener
]
=
{}
self
.
_running
:
list
[
tuple
[
sim_base
.
Simulator
,
command_executor
.
SimpleComponent
]]
=
[]
self
.
_sockets
:
list
[
inst_
base
.
Socket
]
=
[]
self
.
_sockets
:
list
[
inst_
socket
.
Socket
]
=
[]
self
.
_wait_sims
:
list
[
command_executor
.
Component
]
=
[]
@
abc
.
abstractmethod
...
...
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