Skip to content

Commit 5eb9316

Browse files
committed
driver: introduce txchunk argument for console drivers
The txdelay argument only applies to single bytes. Sending those packets over the Internet causes additional per packet overhead, as each packet only contains a single byte payload. Introduce an argument to group bytes into chunks, such that the txdelay applies to the chunk. This will reduce the overhead of packets send over the internet and better utilizes hardware FIFO's on the receiver side. The default chunk size is 1 byte. Signed-off-by: Fabian Pfitzner <f.pfitzner@pengutronix.de>
1 parent 1064f73 commit 5eb9316

12 files changed

Lines changed: 45 additions & 13 deletions

File tree

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ New Features in 25.1
1212
``add_port_forward()`` and ``remove_port_forward()`` in case there is more
1313
than one network interface defined.
1414
- Guermok HDMI to USB 3.0 capture dongle supported
15+
- The `consoleexpectmixin` now supports chunking of multiple bytes
16+
with the ``txchunk`` attribute.
1517

1618
Breaking changes in 25.1
1719
~~~~~~~~~~~~~~~~~~~~~~~~

doc/configuration.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,13 +1961,15 @@ Binds to:
19611961
19621962
SerialDriver:
19631963
txdelay: 0.05
1964+
txchunk: 1
19641965
19651966
Implements:
19661967
- :any:`ConsoleProtocol`
19671968
- :any:`ResetProtocol`
19681969

19691970
Arguments:
1970-
- txdelay (float, default=0.0): time in seconds to wait before sending each byte
1971+
- txdelay (float, default=0.0): time in seconds to wait before sending a chunk
1972+
- txchunk (int, default=1): number of bytes the `txdelay` should apply to
19711973
- timeout (float, default=3.0): time in seconds to wait for a network serial port before
19721974
an error occurs
19731975

@@ -2221,10 +2223,12 @@ Implements:
22212223
ExternalConsoleDriver:
22222224
cmd: 'microcom /dev/ttyUSB2'
22232225
txdelay: 0.05
2226+
txchunk: 1
22242227
22252228
Arguments:
22262229
- cmd (str): command to execute and then bind to.
2227-
- txdelay (float, default=0.0): time in seconds to wait before sending each byte
2230+
- txdelay (float, default=0.0): time in seconds to wait before sending a chunk
2231+
- txchunk (int, default=1): number of bytes the `txdelay` should apply to
22282232

22292233
AndroidFastbootDriver
22302234
~~~~~~~~~~~~~~~~~~~~~

doc/overview.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ specific driver set a binding mapping before creating the driver:
147147
>>> t.set_binding_map({"port": "Second"})
148148
>>> sd = SerialDriver(t, "Driver")
149149
>>> sd
150-
SerialDriver(target=Target(name='Test', env=None), name='Driver', state=<BindingState.bound: 1>, txdelay=0.0, timeout=3.0)
150+
SerialDriver(target=Target(name='Test', env=None), name='Driver', state=<BindingState.bound: 1>, txdelay=0.0, txchunk=1, timeout=3.0)
151151
>>> sd.port
152152
SerialPort(target=Target(name='Test', env=None), name='Second', state=<BindingState.bound: 1>, avail=True, port=None, speed=115200)
153153

doc/usage.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ Active drivers can be accessed by class (any :any:`Driver <labgrid.driver>` or
283283
>>> console = FakeConsoleDriver(target, 'console')
284284
>>> target.activate(console)
285285
>>> target[FakeConsoleDriver]
286-
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0)
286+
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0, txchunk=1)
287287
>>> target[FakeConsoleDriver, 'console']
288-
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0)
288+
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0, txchunk=1)
289289

290290
Driver Deactivation
291291
^^^^^^^^^^^^^^^^^^^
@@ -302,7 +302,7 @@ Driver deactivation works in a similar manner:
302302
.. doctest:: driver-deactivation
303303

304304
>>> target.deactivate(console)
305-
[FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.bound: 1>, txdelay=0.0)]
305+
[FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.bound: 1>, txdelay=0.0, txchunk=1)]
306306

307307
Drivers need to be deactivated in the following cases:
308308

@@ -393,7 +393,7 @@ To access the target's console, the correct driver object can be found by using
393393

394394
>>> cp = t.get_driver('ConsoleProtocol')
395395
>>> cp
396-
SerialDriver(target=Target(name='example', env=Environment(config_file='example-env.yaml')), name=None, state=<BindingState.active: 2>, txdelay=0.0, timeout=3.0)
396+
SerialDriver(target=Target(name='example', env=Environment(config_file='example-env.yaml')), name=None, state=<BindingState.active: 2>, txdelay=0.0, txchunk=1, timeout=3.0)
397397
>>> cp.write(b'test')
398398
4
399399

examples/strategy/local.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ targets:
88
name: "example"
99
SerialDriver:
1010
txdelay: 0.01
11+
txchunk: 1
1112
BareboxDriver:
1213
prompt: 'barebox@[^:]+:[^ ]+ '
1314
bootstring: 'Modules linked in'

labgrid/driver/consoleexpectmixin.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ def read(self, size=1, timeout=0.0, max_size=None):
3434
@step(args=['data'], tag='console')
3535
def write(self, data):
3636
if self.txdelay:
37-
self.logger.debug("Write %i bytes: %s (with %fs txdelay)",
38-
len(data), data, self.txdelay)
37+
self.logger.debug("Write %i bytes: %s (with %fs txdelay per %i bytes)",
38+
len(data), data, self.txdelay, self.txchunk)
39+
3940
count = 0
40-
for i in range(len(data)):
41+
for i in range(0, len(data), self.txchunk):
4142
time.sleep(self.txdelay)
42-
count += self._write(data[i:i+1])
43+
count += self._write(data[i:i+self.txchunk])
44+
4345
return count
4446

4547
self.logger.debug("Write %i bytes: %s", len(data), data)

labgrid/driver/externalconsoledriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ExternalConsoleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
2121
"""
2222
cmd = attr.ib(validator=attr.validators.instance_of(str))
2323
txdelay = attr.ib(default=0.0, validator=attr.validators.instance_of(float))
24+
txchunk = attr.ib(default=1, validator=attr.validators.instance_of(int))
2425

2526
def __attrs_post_init__(self):
2627
super().__attrs_post_init__()

labgrid/driver/fake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
@attr.s(eq=False)
1515
class FakeConsoleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
1616
txdelay = attr.ib(default=0.0, validator=attr.validators.instance_of(float))
17+
txchunk = attr.ib(default=1, validator=attr.validators.instance_of(int))
1718

1819
def __attrs_post_init__(self):
1920
super().__attrs_post_init__()

labgrid/driver/qemudriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __attrs_post_init__(self):
9999
super().__attrs_post_init__()
100100
self.status = 0
101101
self.txdelay = None
102+
self.txchunk = None
102103
self._child = None
103104
self._tempdir = None
104105
self._socket = None

labgrid/driver/serialdriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class SerialDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
2020
bindings = {"port": {"SerialPort", "NetworkSerialPort"}, }
2121

2222
txdelay = attr.ib(default=0.0, validator=attr.validators.instance_of(float))
23+
txchunk = attr.ib(default=1, validator=attr.validators.instance_of(int))
2324
timeout = attr.ib(default=3.0, validator=attr.validators.instance_of(float))
2425

2526
def __attrs_post_init__(self):

0 commit comments

Comments
 (0)