Skip to content

Commit

Permalink
Refactor the device capabilites
Browse files Browse the repository at this point in the history
Signed-off-by: Amber <kumar.amber@intel.com>
  • Loading branch information
kamber-intel committed Jun 4, 2024
1 parent 890519c commit fbe3161
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 109 deletions.
37 changes: 11 additions & 26 deletions detd/devices/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

from ..logger import get_logger

from ..scheduler import TxCapability
from ..scheduler import DataPath

logger = get_logger(__name__)

Expand All @@ -41,6 +39,12 @@ def from_pci_id(pci_id):

raise NameError("Unrecognized PCI ID: {}".format(pci_id))

class Capability(enum.Enum):
Qbv = 0
Qbu = 1
LTC = 2
Preemption = 3

class Device:

"""
Expand All @@ -60,11 +64,7 @@ def __init__(self, num_tx_queues, num_rx_queues):
self.systeminfo = SystemInformation()
self.systemconf = SystemConfigurator()

self.tx_capabilities = TxCapability.default()
self.data_path_capabilities = DataPath.default()
self.launch_time_control = False
self.TxSelectionOffload = False
self.preemption = False
self.capabilities = []

self.num_tx_queues = num_tx_queues
self.num_rx_queues = num_rx_queues
Expand Down Expand Up @@ -118,23 +118,8 @@ def supports_schedule(self, schedule):
'''

raise NotImplementedError("The handler class for the device must implement this function")


def get_tx_capabilities(self):
return self.tx_capabilities

def supports_ltc(self):
"""Returns True if the device supports Launch Time Control (LTC),
False otherwise."""
return self.launch_time_control

def supports_tx_selection_offload(self):
return self.TxSelectionOffload

def get_data_path(self):
'''Returns True if the device supports the specified DataPath capability,
False otherwise.'''
return self.data_path_capabilities

def supports_preemption(self):
return self.preemption
def device_hints(self):
'''Returns device supported Hints.
'''
raise None
33 changes: 26 additions & 7 deletions detd/devices/intel_i210.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@

from ..logger import get_logger

from ..scheduler import TxCapability

from .device import Capability
from .device import Device

from ..scheduler import DataPath
from ..scheduler import TxCapability
from ..scheduler import Hints

logger = get_logger(__name__)

Expand All @@ -29,6 +32,8 @@ class IntelI210(Device):
NUM_TX_QUEUES = 4
NUM_RX_QUEUES = 4

CAPABILITIES = [Capability.LTC]

PCI_IDS_VALID = ['8086:1533', '8086:1536', '8086:1537', '8086:1538', '8086:157B',
'8086:157C', '8086:15F6']

Expand All @@ -43,12 +48,6 @@ def __init__(self, pci_id):

super().__init__(IntelI210.NUM_TX_QUEUES, IntelI210.NUM_RX_QUEUES)

self.launch_time_control = True
self.data_path_capabilities = DataPath.AF_PACKET
self.tx_capabilities = TxCapability.software
self.TxSelectionOffload = False
self.preemption = False

self.features['rxvlan'] = 'off'

# self.num_tx_ring_entries and self.num_rx_ring_entries
Expand All @@ -73,3 +72,23 @@ def get_base_time_multiple(self):
def supports_schedule(self, schedule):

return True

def device_hints(self):
# Check the capabilities and set the Hints

preemption = False
launch_time_control = False
TxSelectionOffload = False
datapath = DataPath.AF_PACKET

if Capability.Qbv in self.capabilities:
txcapability = TxCapability.Qbv
if Capability.Qbu in self.capabilities and not Capability.Qbv in self.capabilities:
txcapability = TxCapability.Qbu
if Capability.Preemption in self.capabilities:
preemption = True
if Capability.LTC in self.capabilities:
launch_time_control = True
TxSelectionOffload = False
datapath = DataPath.AF_PACKET
return Hints(txcapability, TxSelectionOffload ,datapath, preemption, launch_time_control)
30 changes: 23 additions & 7 deletions detd/devices/intel_i225.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

from ..logger import get_logger

from ..scheduler import TxCapability
from .device import Capability
from .device import Device

from ..scheduler import DataPath
from ..scheduler import TxCapability
from ..scheduler import Hints

logger = get_logger(__name__)

Expand All @@ -27,6 +29,8 @@ class IntelI225(Device):
NUM_TX_QUEUES = 4
NUM_RX_QUEUES = 4

CAPABILITIES = [Capability.Qbv]

# Devices supporting TSN: i225-LM, i225-IT
PCI_IDS_VALID = ['8086:0D9F', '8086:15F2']

Expand All @@ -51,12 +55,6 @@ def __init__(self, pci_id):
if pci_id in IntelI225.PCI_IDS_UNPROGRAMMED:
raise "The flash image in this i225 device is empty, or the NVM configuration loading failed."

self.launch_time_control = False
self.data_path_capabilities = DataPath.AF_PACKET
self.tx_capabilities = TxCapability.Qbv
self.TxSelectionOffload = True
self.preemption = False

self.features['rxvlan'] = 'off'
#self.features['hw-tc-offload'] = 'on'

Expand Down Expand Up @@ -88,3 +86,21 @@ def supports_schedule(self, schedule):
# FIXME: check additional constraints, like maximum cycle time

return True

def device_hints(self):
# Check the capabilities and set the Hints
preemption = False
launch_time_control = False
TxSelectionOffload = True
datapath = DataPath.AF_PACKET

if Capability.Qbv in self.capabilities:
txcapability = TxCapability.Qbv
if Capability.Qbu in self.capabilities and not Capability.Qbv in self.capabilities:
txcapability = TxCapability.Qbu
if Capability.Preemption in self.capabilities:
preemption = True
if Capability.LTC in self.capabilities:
launch_time_control = True

return Hints(txcapability, TxSelectionOffload ,datapath, preemption, launch_time_control)
29 changes: 23 additions & 6 deletions detd/devices/intel_mgbeehl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

from ..logger import get_logger

from ..scheduler import TxCapability
from .device import Capability
from .device import Device

from ..scheduler import DataPath
from ..scheduler import TxCapability
from ..scheduler import Hints

logger = get_logger(__name__)

Expand Down Expand Up @@ -58,11 +60,7 @@ def __init__(self, pci_id):

super().__init__(IntelMgbeEhl.NUM_TX_QUEUES, IntelMgbeEhl.NUM_RX_QUEUES)

self.launch_time_control = True
self.data_path_capabilities = DataPath.AF_PACKET
self.tx_capabilities = TxCapability.Qbv
self.TxSelectionOffload = False
self.preemption = False
self.capabilities = [Capability.Qbv]

self.features['rxvlan'] = 'off'
self.features['hw-tc-offload'] = 'on'
Expand All @@ -84,3 +82,22 @@ def supports_schedule(self, schedule):
# FIXME: check additional constraints, like maximum cycle time

return True

def device_hints(self):
# Check the capabilities and set the Hints

preemption = False
launch_time_control = False
TxSelectionOffload = True
datapath = DataPath.AF_PACKET

if Capability.Qbv in self.capabilities:
txcapability = TxCapability.Qbv
if Capability.Qbu in self.capabilities and not Capability.Qbv in self.capabilities:
txcapability = TxCapability.Qbu
if Capability.Preemption in self.capabilities:
preemption = True
if Capability.LTC in self.capabilities:
launch_time_control = True

return Hints(txcapability, TxSelectionOffload ,datapath, preemption, launch_time_control)
63 changes: 25 additions & 38 deletions detd/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,42 +221,29 @@ def update_base_time(self, config):

def _get_device_hints(self, config):

# Default config based on the device capabilies
tx_selection = config.interface.device.get_tx_capabilities()
tx_selection_offload = config.interface.device.supports_tx_selection_offload()
data_path = config.interface.device.get_data_path()
preemption = config.interface.device.supports_preemption()
launch_time_control = config.interface.device.supports_ltc()

# Check if the device supports the requested features
if config.hints.data_path is not None and DataPath(config.hints.data_path) != self.interface.device.get_data_path():
raise ValueError(f"Device does not support the requested DataPath feature."
f"Requested: {DataPath(config.hints.data_path)}, Device Capabilities: {self.interface.device.get_data_path()}")
else:
data_path = DataPath(config.hints.data_path)

if config.hints.tx_selection is not None and TxCapability(config.hints.tx_selection) != self.interface.device.get_tx_capabilities():
raise ValueError(f"Device does not support the requested Tx selection feature."
f"Requested: {TxCapability(config.hints.tx_selection)}, Device Capabilities: {self.interface.device.get_tx_capabilities()}")
else:
tx_selection = TxCapability(config.hints.tx_selection)

if config.hints.launch_time_control is not None and config.hints.launch_time_control != self.interface.device.supports_ltc():
raise ValueError(f"Device does not support the requested launch_time_control feature."
f"Requested: {config.hints.launch_time_control}, Device Capabilities: {self.interface.device.supports_ltc()}")
else:
launch_time_control = config.hints.launch_time_control

if config.hints.tx_selection_offload is not None and config.hints.tx_selection_offload != self.interface.device.supports_tx_selection_offload():
raise ValueError(f"Device does not support the requested tx_selection_offload feature."
f"Requested: {config.hints.tx_selection_offload}, Device Capabilities: {self.interface.device.supports_tx_selection_offload()}")
else:
tx_selection_offload = config.hints.tx_selection_offload

if config.hints.preemption is not None and config.hints.preemption != self.interface.device.supports_preemption():
raise ValueError(f"Device does not support the requested preemption feature."
f"Requested: {config.hints.preemption}, Device Capabilities: {self.interface.device.supports_preemption()}")
else:
preemption = config.hints.preemption
# Get the device suggested default hints
hints = self.interface.device.device_hints()

if config.hints is not None:
# Check if the device supports the requested features
if DataPath(config.hints.data_path) != hints.data_path:
raise ValueError(f"Device does not support the requested DataPath feature."
f"Requested: {DataPath(config.hints.data_path)}, Device Capabilities: {hints.data_path}")

if TxCapability(config.hints.tx_selection) != hints.tx_selection:
raise ValueError(f"Device does not support the requested Tx selection feature."
f"Requested: {TxCapability(config.hints.tx_selection)}, Device Capabilities: {hints.tx_selection}")

if config.hints.launch_time_control != hints.launch_time_control:
raise ValueError(f"Device does not support the requested launch_time_control feature."
f"Requested: {config.hints.launch_time_control}, Device Capabilities: {hints.launch_time_control}")

if config.hints.tx_selection_offload != hints.tx_selection_offload:
raise ValueError(f"Device does not support the requested tx_selection_offload feature."
f"Requested: {config.hints.tx_selection_offload}, Device Capabilities: {hints.tx_selection_offload}")

if config.hints.preemption != hints.preemption:
raise ValueError(f"Device does not support the requested preemption feature."
f"Requested: {config.hints.preemption}, Device Capabilities: {hints.preemption}")

return Hints(tx_selection, tx_selection_offload, data_path, preemption, launch_time_control)
return hints
12 changes: 7 additions & 5 deletions detd/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ def send_qos_request(self, configuration, setup_socket):
request.txmin = configuration.stream.txoffset
request.txmax = configuration.stream.txoffset
request.setup_socket = setup_socket
request.tx_selection = configuration.hints.tx_selection.value
request.tx_selection_offload = configuration.hints.tx_selection_offload
request.data_path = configuration.hints.data_path.value
request.preemption = configuration.hints.preemption
request.launch_time_control = configuration.hints.launch_time_control

if configuration.hints is not None:
request.tx_selection = configuration.hints.tx_selection.value
request.tx_selection_offload = configuration.hints.tx_selection_offload
request.data_path = configuration.hints.data_path.value
request.preemption = configuration.hints.preemption
request.launch_time_control = configuration.hints.launch_time_control

message = request.SerializeToString()
self.send(message)
Expand Down
23 changes: 4 additions & 19 deletions detd/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ def __init__(self, interface, stream, traffic, hints = None):
self.interface = interface
self.stream = stream
self.traffic = traffic

# Initialize hints to a default value if None is passed
if hints is None:
self.hints = Hints(TxCapability.Qbv, False, DataPath.AF_PACKET, False, True)
else:
self.hints = hints
self.hints = hints


class StreamConfiguration:
Expand Down Expand Up @@ -391,23 +386,13 @@ def reschedule(self):
self.schedule.add_best_effort_padding(self.traffics[0])
# FIXME: error handling

class TxCapability(enum.Enum):
software = 0 # SOFTWARE
Qbv = 1 # ENHANCEMENTS_FOR_SCHEDULED_TRAFFIC
Qbu = 2 # STRICT_PRIORITY

@staticmethod
def default():
return TxCapability.none

class DataPath(enum.Enum):
none = 0
AF_PACKET = 1
AF_XDP_ZC = 2

@staticmethod
def default():
return DataPath.none
class TxCapability(enum.Enum):
Qbv = 1 # ENHANCEMENTS_FOR_SCHEDULED_TRAFFIC
Qbu = 2 # STRICT_PRIORITY

class Hints:
"""
Expand Down
2 changes: 1 addition & 1 deletion detd/systemconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def __init__(self):
def setup(self, interface, mapping, scheduler, base_time, hints):
tc = CommandTc()

if hints.tx_selection == TxCapability.Qbv:
if (hints.tx_selection == TxCapability.Qbv or hints.tx_selection == TxCapability.Qbu) and hints.tx_selection_offload == True:
tc.set_taprio_offload(interface, mapping, scheduler, base_time)
else:
tc.set_taprio_software(interface, mapping, scheduler, base_time)
Expand Down

0 comments on commit fbe3161

Please sign in to comment.