fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/39606?usp=email )
Change subject: trx_toolkit: correct Tx burst advance value
......................................................................
trx_toolkit: correct Tx burst advance value
Change-Id: I559e86a15a3a8b4ec725f9d381e7d28628ea9155
---
M src/target/trx_toolkit/transceiver.py
1 file changed, 2 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/06/39606/1
diff --git a/src/target/trx_toolkit/transceiver.py b/src/target/trx_toolkit/transceiver.py
index 672c261..ad1ee8c 100644
--- a/src/target/trx_toolkit/transceiver.py
+++ b/src/target/trx_toolkit/transceiver.py
@@ -122,8 +122,8 @@
are separete processes that are not perfectly synchronized in time.
Moreover, the transceiver needs some time to prepare a burst for
transmission. This is why the time difference between Uplink and
- Downlink is actually much higher on practice (20 TDMA frame periods
- by default, at the moment of writing this patch).
+ Downlink is actually much higher on practice (currently 2 TDMA
+ frame periods for both trxcon and osmo-bts-trx).
In order to reflect that delay in a virtual environment, this
implementation, just like osmo-trx, queues all to be transmitted
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/39606?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I559e86a15a3a8b4ec725f9d381e7d28628ea9155
Gerrit-Change-Number: 39606
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
fixeria has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/39535?usp=email )
Change subject: trx_toolkit/transceiver: Use with tx_queue_lock instead of manual acquire/release
......................................................................
trx_toolkit/transceiver: Use with tx_queue_lock instead of manual acquire/release
- it is a bit faster
- it is a bit more robust as the lock becomes released in case
some exception is raised before reaching release
Noticed while moving forwarding out of tx_queue_lock in
I7d10c972c45b2b5765e7c3a28f8646508b3c8a82.
Change-Id: I74b194120bcc518d44796b57e36368bdc8de4aab
---
M src/target/trx_toolkit/transceiver.py
1 file changed, 9 insertions(+), 11 deletions(-)
Approvals:
Jenkins Builder: Verified
pespin: Looks good to me, but someone else must approve
lynxis lazus: Looks good to me, approved
fixeria: Looks good to me, approved
diff --git a/src/target/trx_toolkit/transceiver.py b/src/target/trx_toolkit/transceiver.py
index 2a638c5..e6af013 100644
--- a/src/target/trx_toolkit/transceiver.py
+++ b/src/target/trx_toolkit/transceiver.py
@@ -312,18 +312,16 @@
emit = []
wait = []
- self._tx_queue_lock.acquire()
+ with self._tx_queue_lock:
+ for msg in self._tx_queue:
+ if msg.fn < fn:
+ drop.append(msg)
+ elif msg.fn == fn:
+ emit.append(msg)
+ else:
+ wait.append(msg)
- for msg in self._tx_queue:
- if msg.fn < fn:
- drop.append(msg)
- elif msg.fn == fn:
- emit.append(msg)
- else:
- wait.append(msg)
-
- self._tx_queue = wait
- self._tx_queue_lock.release()
+ self._tx_queue = wait
for msg in emit:
fwd.forward_msg(self, msg)
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/39535?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I74b194120bcc518d44796b57e36368bdc8de4aab
Gerrit-Change-Number: 39535
Gerrit-PatchSet: 1
Gerrit-Owner: kirr <kirr(a)nexedi.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: osmith <osmith(a)sysmocom.de>
fixeria has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/39533?usp=email )
Change subject: trx_toolkit/transceiver: Do not forward nor log from under tx_queue_lock
......................................................................
trx_toolkit/transceiver: Do not forward nor log from under tx_queue_lock
Even though for 1 BTS + 1 MS fake_trx works ok with tx-queuing, when I
try to run two ccch_scan's with 1 BTS fake_trx starts occupy ~ 100% of
CPU and emits lots of "Stale ..." messages:
[WARNING] transceiver.py:317 (M2@127.0.0.1:7700) Stale TRXD message (fn=2793): fn=2791 tn=7 pwr=0
[WARNING] transceiver.py:317 (M2@127.0.0.1:7700) Stale TRXD message (fn=2793): fn=2792 tn=0 pwr=0
[WARNING] transceiver.py:317 (M2@127.0.0.1:7700) Stale TRXD message (fn=2793): fn=2792 tn=1 pwr=0
[WARNING] transceiver.py:317 (M2@127.0.0.1:7700) Stale TRXD message (fn=2793): fn=2792 tn=2 pwr=0
[WARNING] transceiver.py:317 (M2@127.0.0.1:7700) Stale TRXD message (fn=2793): fn=2792 tn=3 pwr=0
...
Inspecting a bit with a profiler showed that fake_trx simply cannot keep
up with the load.
Let's try to fix this with optimizing things a bit where it is easy to
notice and easy to pick up low-hanging fruits.
This is the first patch in that optimization series. It moves blocking
calls from out of under tx_queue_lock on transmit path. The reason for
this move is not to block receive path while the transmit path is busy
more than necessary. I originally noticed tx_queue_lock.acquire being
visible in profile of the rx thread which indicates that tx/rx
contention on this lock can really happen if we do non-negligible tasks
from under this lock. Here, in particular, it was forward_msg that was
preparing and actually sending RxMsg to destination. tx_queue_lock is
needed only to protect tx_queue itself and synchronize rx and tx threads
access to it. Once necessary items are appended or popped, we can do
everything else out of this lock.
-> Move everything on the tx codepath, not actually needing access to
tx_queue out of this lock:
- only collect messages to be sent under the lock; actually forward them
after releasing the log;
- same for logging.
Change-Id: I7d10c972c45b2b5765e7c3a28f8646508b3c8a82
---
M src/target/trx_toolkit/transceiver.py
1 file changed, 14 insertions(+), 5 deletions(-)
Approvals:
laforge: Looks good to me, but someone else must approve
fixeria: Looks good to me, approved
Jenkins Builder: Verified
lynxis lazus: Looks good to me, but someone else must approve
pespin: Looks good to me, but someone else must approve
diff --git a/src/target/trx_toolkit/transceiver.py b/src/target/trx_toolkit/transceiver.py
index 4e1cb87..7297abf 100644
--- a/src/target/trx_toolkit/transceiver.py
+++ b/src/target/trx_toolkit/transceiver.py
@@ -308,14 +308,23 @@
if not self.running:
return
+ drop = []
+ emit = []
+
self._tx_queue_lock.acquire()
for msg in self._tx_queue:
- if msg.fn == fn:
- fwd.forward_msg(self, msg)
- elif msg.fn < fn:
- log.warning("(%s) Stale TRXD message (fn=%u): %s"
- % (self, fn, msg.desc_hdr()))
+ if msg.fn < fn:
+ drop.append(msg)
+ elif msg.fn == fn:
+ emit.append(msg)
self._tx_queue = [msg for msg in self._tx_queue if msg.fn > fn]
self._tx_queue_lock.release()
+
+ for msg in emit:
+ fwd.forward_msg(self, msg)
+
+ for msg in drop:
+ log.warning("(%s) Stale TRXD message (fn=%u): %s"
+ % (self, fn, msg.desc_hdr()))
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/39533?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I7d10c972c45b2b5765e7c3a28f8646508b3c8a82
Gerrit-Change-Number: 39533
Gerrit-PatchSet: 1
Gerrit-Owner: kirr <kirr(a)nexedi.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: osmith <osmith(a)sysmocom.de>
fixeria has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/39532?usp=email )
Change subject: trxcon: Advance Uplink TDMA Fn by default again
......................................................................
trxcon: Advance Uplink TDMA Fn by default again
This essentially reverts 923e9b0b (trxcon: do not advance Uplink TDMA Fn
by default; I838b1ebc54e4c5d116f8af2155d97215a6133ba4) for the following
reason:
In trxcon TRX clock is unused, because the signal from BTS is used as
the master clock source instead (see 45c821ae/Ic8a5b6277c6b16392026e0557376257d71c9d230
"trxcon: get rid of the timer driven clock module" for details".
Before restoration of tx-queue in fake_trx this was working ok even with
fn-advance=0 on Ms side, but after I41291708effdd2c767be680fff22ffbd9a56815e
(Revert "Revert "trx_toolkit/transceiver.py: implement the transmit
burst queue"") fake_trx is sending frames having Fn when exactly same Fn
happens corresponding on fake_trx clock. This results in BTS frames
(that are sent with fn-advance=2 by default (see
I7da3d0948f38e12342fb714b29f8edc5e9d0933d in osmo-bts.git and OS#4487)
to be queued, waited to be sent, and then actually sent to Ms on
fn=msg.fn . And then even if Ms replies immediately with that same fn,
that message will be dropped by fake_trx as stalled, because fake_trx
thinks that the message is too late since that fn already happened
according to fake_trx clock.
Here is a trace of how that looks like with 1 BTS and 1 MS(*):
7.106.927 CLOCK fn=80 # fake_trx running
7.111.592 CLOCK fn=81
7.116.289 CLOCK fn=82
7.120.949 CLOCK fn=83
7.125.523 CLOCK fn=84
7.130.000 CLOCK fn=85
7.134.575 CLOCK fn=86
...
7.209.222 CLOCK fn=102
7.209.897 BTS -> fn=104 tn=0 # BTS starts to emit RF
7.210.221 BTS -> fn=104 tn=1
7.210.556 BTS -> fn=104 tn=2
7.210.796 BTS -> fn=104 tn=3
7.211.019 BTS -> fn=104 tn=4
7.211.234 BTS -> fn=104 tn=5
7.211.479 BTS -> fn=104 tn=6
7.211.768 BTS -> fn=104 tn=7
7.213.086 CLOCK fn=103
7.214.354 BTS -> fn=105 tn=0
7.214.566 BTS -> fn=105 tn=1
7.214.685 BTS -> fn=105 tn=2
7.214.792 BTS -> fn=105 tn=3
7.214.890 BTS -> fn=105 tn=4
7.214.985 BTS -> fn=105 tn=5
7.215.083 BTS -> fn=105 tn=6
7.215.184 BTS -> fn=105 tn=7
7.217.823 CLOCK fn=104
7.218.869 BTS -> fn=106 tn=0
7.219.092 BTS -> fn=106 tn=1
7.219.224 BTS -> fn=106 tn=2
7.219.330 BTS -> fn=106 tn=3
7.219.431 BTS -> fn=106 tn=4
7.219.527 BTS -> fn=106 tn=5
7.219.621 BTS -> fn=106 tn=6
7.219.718 BTS -> fn=106 tn=7
7.222.535 CLOCK fn=105
...
9.995.869 CLOCK fn=706 # MS will soon connect.
9.997.138 BTS -> fn=709 tn=0 # Note: BTS is sending fn=709 before CLOCK fn=707
9.997.338 BTS -> fn=709 tn=1 # so this messages become queued before CLOCK fn=709 happens
9.997.444 BTS -> fn=709 tn=2
9.997.535 BTS -> fn=709 tn=3
9.997.620 BTS -> fn=709 tn=4
9.997.708 BTS -> fn=709 tn=5
9.997.789 BTS -> fn=709 tn=6
9.997.874 BTS -> fn=709 tn=7
10.000.583 CLOCK fn=707
10.001.735 BTS -> fn=710 tn=0
10.001.932 BTS -> fn=710 tn=1
10.002.041 BTS -> fn=710 tn=2
10.002.134 BTS -> fn=710 tn=3
10.002.220 BTS -> fn=710 tn=4
10.002.373 BTS -> fn=710 tn=5
10.002.459 BTS -> fn=710 tn=6
10.002.718 BTS -> fn=710 tn=7
[DEBUG] ctrl_if_trx.py:115 (MS) Recv POWEROFF cmd # MS starts to connect
[INFO] ctrl_if_trx.py:117 (MS) Stopping transceiver...
[DEBUG] ctrl_if_trx.py:229 (MS) Ignore CMD ECHO
10.005.203 CLOCK fn=708
[DEBUG] ctrl_if_trx.py:229 (MS) Ignore CMD SETSLOT
10.006.406 BTS -> fn=711 tn=0
[DEBUG] ctrl_if_trx.py:124 (MS) Recv RXTUNE cmd
10.006.999 BTS -> fn=711 tn=1
10.007.153 BTS -> fn=711 tn=2
[DEBUG] ctrl_if_trx.py:131 (MS) Recv TXTUNE cmd
10.007.590 BTS -> fn=711 tn=3
10.007.728 BTS -> fn=711 tn=4
[DEBUG] ctrl_if_trx.py:97 (MS) Recv POWERON CMD # MS connected and activated RF
[INFO] ctrl_if_trx.py:109 (MS) Starting transceiver...
10.008.344 BTS -> fn=711 tn=5
10.008.471 BTS -> fn=711 tn=6
10.008.563 BTS -> fn=711 tn=7
10.009.868 CLOCK fn=709 # CLOCK fn=709 happens
10.009.987 MS <- fn=709 tn=0 # messages of BTS queued previously with that fn=709 are forwarded to Ms
10.010.696 MS <- fn=709 tn=1
10.010.904 MS -> fn=709 tn=0 # <-- MS sends UL message with that same fn=709 _before_ CLOCK fn=710
10.011.397 BTS -> fn=712 tn=0
10.011.507 MS <- fn=709 tn=2
10.011.770 MS <- fn=709 tn=3
10.011.968 MS <- fn=709 tn=4
10.012.156 MS <- fn=709 tn=5
10.012.342 MS <- fn=709 tn=6
10.012.527 MS <- fn=709 tn=7
10.012.914 BTS <- fn=709 tn=0
10.013.166 BTS -> fn=712 tn=1
10.013.524 MS -> fn=709 tn=1 # <-- MS sends UL message with that same fn=709 _before_ CLOCK fn=710
10.013.832 BTS -> fn=712 tn=2
10.013.949 MS -> fn=709 tn=2 # <-- MS sends UL message with that same fn=709 _before_ CLOCK fn=710
10.014.081 BTS -> fn=712 tn=3
10.014.177 MS -> fn=709 tn=3 # <-- MS sends UL message with that same fn=709 _before_ CLOCK fn=710
10.014.361 BTS -> fn=712 tn=4
10.014.475 CLOCK fn=710 # but most of those messages of MS with fn=709 are not picked up
10.014.713 MS -> fn=709 tn=4 # instantly and so become dropped as stale on CLOCK fn=710
10.014.815 MS <- fn=710 tn=0
10.015.032 BTS -> fn=712 tn=5
10.015.687 MS <- fn=710 tn=1
10.016.189 MS <- fn=710 tn=2
10.016.464 MS <- fn=710 tn=3
10.016.648 MS <- fn=710 tn=4
10.016.882 MS <- fn=710 tn=5
10.017.110 MS <- fn=710 tn=6
10.017.336 MS <- fn=710 tn=7
[WARNING] transceiver.py:321 (MS) Stale TRXD message (fn=710): fn=709 tn=1 pwr=0
[WARNING] transceiver.py:321 (MS) Stale TRXD message (fn=710): fn=709 tn=2 pwr=0
[WARNING] transceiver.py:321 (MS) Stale TRXD message (fn=710): fn=709 tn=3 pwr=0
[WARNING] transceiver.py:321 (MS) Stale TRXD message (fn=710): fn=709 tn=4 pwr=0
So without adding some fn-advance it is practically not possible for Ms
to be on time with tx-queueing on TRX even if Ms sends its uplink frames
right immediately after receiving downlink ones.
This way Ms fn-advance has to be 1 at the minimum, so that immediate UL
replies can in principle arrive before fn+1 happens on fake_trx side,
even for tn=7. And it is also better to increase fn-advance once more by
another +1, to compensate for possible jitter due to OS scheduling
latencies and similar things. This way default fn-advance=2 on Ms side
becomes symmetric to default fn-advance on BTS side and Ms<->BTS
exchange starts to work ok even with tx-queueing activated on fake_trx.
In theory it should be possible to reduce those fn-advances to 1 on both
sides, but that will likely require to switch clock granularity from Fn
to Tn increasing precision by an order of magnitude, which will likely
also result in the need to make architectural change of moving trx to
work inside BTS and MS instead of being separate service processes.
That's a big task and I'm not delving into that here.
Note: Uplink Fn advance > 0 is needed for Ms when working with regular
TRX'es as well. The reason is exactly the same as explained above. In
923e9b0b the reason for setting fn-advance=0 by default was that trxcon
is usually being used with fake_trx, and that with fake_trx it is not
needed. But after reenabling tx-queueing we have to revisit even
fake_trx case again.
(*) the trace was captured with the help of the following debugging patch:
--- b/src/target/trx_toolkit/burst_fwd.py
+++ a/src/target/trx_toolkit/burst_fwd.py
@@ -22,6 +22,18 @@
from trx_list import TRXList
+import sys, time
+
+# trace logs msg to stderr with also marking it with high-resolution timestamp.
+t0 = time.time()
+def trace(msg):
+ t = time.time() - t0
+ t_ms = int(t * 1e3) / 1e3
+ us = int((t - t_ms) * 1e6)
+ print("%7.3f.%03d %s" % (t_ms, us, msg), file=sys.stderr)
+
class BurstForwarder(TRXList):
""" Performs burst forwarding between transceivers.
@@ -63,6 +75,7 @@ def forward_msg(self, src_trx, rx_msg):
if trx.get_rx_freq(rx_msg.fn) != tx_freq:
continue
+ trace("%s\t<- fn=%d\ttn=%d" % (trx, rx_msg.fn, rx_msg.tn))
# Transform from TxMsg to RxMsg and forward
tx_msg = rx_msg.trans(ver = trx.data_if._hdr_ver)
trx.handle_data_msg(src_trx, rx_msg, tx_msg)
--- b/src/target/trx_toolkit/fake_trx.py
+++ a/src/target/trx_toolkit/fake_trx.py
@@ -29,7 +29,7 @@
import re
from app_common import ApplicationBase
-from burst_fwd import BurstForwarder
+from burst_fwd import BurstForwarder, trace
from transceiver import Transceiver
from data_msg import Modulation
from clck_gen import CLCKGen
@@ -473,6 +473,7 @@ def run(self):
# This method will be called by the clock thread
def clck_handler(self, fn):
+ trace("CLOCK\tfn=%d" % fn)
# We assume that this list is immutable at run-time
for trx in self.trx_list.trx_list:
trx.clck_tick(self.burst_fwd, fn)
--- b/src/target/trx_toolkit/transceiver.py
+++ a/src/target/trx_toolkit/transceiver.py
@@ -25,6 +25,7 @@
from data_if import DATAInterface
from udp_link import UDPLink
from trx_list import TRXList
+from burst_fwd import trace
from gsm_shared import HoppingParams
@@ -198,6 +199,7 @@ def __init__(self, bind_addr, remote_addr, base_port, **kwargs):
self._tx_queue = []
def __str__(self):
+ return self.name
desc = "%s:%d" % (self.remote_addr, self.base_port)
if self.child_idx > 0:
desc += "/%d" % self.child_idx
@@ -289,6 +291,7 @@ def recv_data_msg(self):
return None
# Enque the message, it will be sent later
+ trace("%s\t-> fn=%d\ttn=%d" % (self, msg.fn, msg.tn))
self.tx_queue_append(msg)
return msg
Change-Id: Icf0b4568b44eb75ee0733391d94b0af86f27ee2e
---
M src/host/trxcon/src/trxcon_main.c
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
laforge: Looks good to me, but someone else must approve
Jenkins Builder: Verified
pespin: Looks good to me, but someone else must approve
fixeria: Looks good to me, approved
diff --git a/src/host/trxcon/src/trxcon_main.c b/src/host/trxcon/src/trxcon_main.c
index 3901e33..78963b7 100644
--- a/src/host/trxcon/src/trxcon_main.c
+++ b/src/host/trxcon/src/trxcon_main.c
@@ -79,7 +79,7 @@
.trx_remote_ip = "127.0.0.1",
.trx_bind_ip = "0.0.0.0",
.trx_base_port = 6700,
- .trx_fn_advance = 0,
+ .trx_fn_advance = 2,
.phyq_fbsb_extend_fns = 0,
};
@@ -184,7 +184,7 @@
printf(" -b --trx-bind TRX bind IP address (default 0.0.0.0)\n");
printf(" -i --trx-remote TRX remote IP address (default 127.0.0.1)\n");
printf(" -p --trx-port Base port of TRX instance (default 6700)\n");
- printf(" -f --trx-advance Uplink burst scheduling advance (default 0)\n");
+ printf(" -f --trx-advance Uplink burst scheduling advance (default 2)\n");
printf(" -F --fbsb-extend FBSB timeout extension (in TDMA FNs, default 0)\n");
printf(" -s --socket Listening socket for layer23 (default /tmp/osmocom_l2)\n");
printf(" -g --gsmtap-ip The destination IP used for GSMTAP (disabled by default)\n");
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/39532?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: Icf0b4568b44eb75ee0733391d94b0af86f27ee2e
Gerrit-Change-Number: 39532
Gerrit-PatchSet: 1
Gerrit-Owner: kirr <kirr(a)nexedi.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: osmith <osmith(a)sysmocom.de>
fixeria has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/39328?usp=email )
Change subject: Revert "Revert "trx_toolkit/transceiver.py: implement the transmit burst queue""
......................................................................
Revert "Revert "trx_toolkit/transceiver.py: implement the transmit burst queue""
This reverts commit d4ed09df57b3461470af501e9687ddd80eb78838,
reinstating tx queue into fake_trx.
It is ok to do so because, as explained in abc63d8d (trx_toolkit/clck_gen.py:
Fix clock generator not to accumulate timing error), the
reason for GSM clock jitter problem was timing error accumulation in
CLCKgen, not problems with py threading.Event.
Note: this restores original tx queue implementation basically as-is
with only resolve minor conflicts during the revert. The original tx
queue implementation wastes CPU cycles though because it linearly scans
the whole tx queue at every TDMA frame. If that CPU usage becomes a real
problem it should be straightforward to fix by reworking tx queue to use
priority queue instead of unordered array via heapq module from standard
library. See https://docs.python.org/3/library/heapq.html for details.
The follow-up patches will make necessarry adjastments for tx-queue to
function properly.
Related: OS#4658, OS#6672
Change-Id: I41291708effdd2c767be680fff22ffbd9a56815e
---
M src/target/trx_toolkit/fake_trx.py
M src/target/trx_toolkit/transceiver.py
2 files changed, 72 insertions(+), 3 deletions(-)
Approvals:
pespin: Looks good to me, but someone else must approve
fixeria: Looks good to me, approved; Verified
diff --git a/src/target/trx_toolkit/fake_trx.py b/src/target/trx_toolkit/fake_trx.py
index 0daecb4..21bd189 100755
--- a/src/target/trx_toolkit/fake_trx.py
+++ b/src/target/trx_toolkit/fake_trx.py
@@ -398,6 +398,8 @@
# Init shared clock generator
self.clck_gen = CLCKGen([])
+ # This method will be called on each TDMA frame
+ self.clck_gen.clck_handler = self.clck_handler
# Power measurement emulation
# Noise: -120 .. -105
@@ -463,14 +465,18 @@
for trx in self.trx_list.trx_list:
# DATA interface
if trx.data_if.sock in r_event:
- msg = trx.recv_data_msg()
- if msg is not None:
- self.burst_fwd.forward_msg(trx, msg)
+ trx.recv_data_msg()
# CTRL interface
if trx.ctrl_if.sock in r_event:
trx.ctrl_if.handle_rx()
+ # This method will be called by the clock thread
+ def clck_handler(self, fn):
+ # We assume that this list is immutable at run-time
+ for trx in self.trx_list.trx_list:
+ trx.clck_tick(self.burst_fwd, fn)
+
def shutdown(self):
log.info("Shutting down...")
diff --git a/src/target/trx_toolkit/transceiver.py b/src/target/trx_toolkit/transceiver.py
index ffd18ab..4e1cb87 100644
--- a/src/target/trx_toolkit/transceiver.py
+++ b/src/target/trx_toolkit/transceiver.py
@@ -19,6 +19,7 @@
# GNU General Public License for more details.
import logging as log
+import threading
from ctrl_if_trx import CTRLInterfaceTRX
from data_if import DATAInterface
@@ -109,6 +110,37 @@
Transceiver and all its timeslots, so using in for the BTS side
does not make any sense (imagine BCCH hopping together with DCCH).
+ == The transmit burst queue
+
+ According to 3GPP 45.002, the time difference between Uplink and
+ Downlink corresponds to three TDMA timeslot periods. However,
+ in general the L1 implementations (such as osmo-bts-trx and trxcon)
+ never schedule to be transmitted bursts for the current TDMA frame
+ immediately. Instead, they are being scheduled prematurely.
+
+ The rationale is that both transceiver and the L1 implementation
+ are separete processes that are not perfectly synchronized in time.
+ Moreover, the transceiver needs some time to prepare a burst for
+ transmission. This is why the time difference between Uplink and
+ Downlink is actually much higher on practice (20 TDMA frame periods
+ by default, at the moment of writing this patch).
+
+ In order to reflect that delay in a virtual environment, this
+ implementation, just like a normal transceiver (e.g. osmo-trx),
+ queues all to be transmitted (L12TRX) bursts, so hey remain in
+ the transmit queue until the appropriate time of transmission.
+
+ The API user is supposed to call recv_data_msg() in order to obtain
+ a L12TRX message on the TRXD (data) inteface, so it gets queued by
+ this function. Then, to ensure the timeous transmission, the user
+ of this implementation needs to call clck_tick() on each TDMA
+ frame. Both functions are thread-safe (queue mutex).
+
+ In a multi-trx configuration, the use of queue additionally ensures
+ proper burst aggregation on multiple TRXD connections, so all L12TRX
+ messages are guaranteed to be sent in the right order, i.e. with
+ monolithically-increasing TDMA frame numbers.
+
"""
def __init__(self, bind_addr, remote_addr, base_port, **kwargs):
@@ -161,6 +193,10 @@
# List of child transceivers
self.child_trx_list = TRXList()
+ # Tx (L12TRX) burst queue and mutex
+ self._tx_queue_lock = threading.Lock()
+ self._tx_queue = []
+
def __str__(self):
desc = "%s:%d" % (self.remote_addr, self.base_port)
if self.child_idx > 0:
@@ -220,6 +256,7 @@
for trx in trx_list:
trx.running = poweron
if not poweron:
+ trx.tx_queue_clear()
trx.disable_fh()
# Trigger clock generator if required
@@ -251,8 +288,34 @@
"is not running => dropping..." % (self, msg.desc_hdr()))
return None
+ # Enque the message, it will be sent later
+ self.tx_queue_append(msg)
return msg
def handle_data_msg(self, msg):
# TODO: make legacy mode configurable (via argv?)
self.data_if.send_msg(msg, legacy = True)
+
+ def tx_queue_append(self, msg):
+ with self._tx_queue_lock:
+ self._tx_queue.append(msg)
+
+ def tx_queue_clear(self):
+ with self._tx_queue_lock:
+ self._tx_queue.clear()
+
+ def clck_tick(self, fwd, fn):
+ if not self.running:
+ return
+
+ self._tx_queue_lock.acquire()
+
+ for msg in self._tx_queue:
+ if msg.fn == fn:
+ fwd.forward_msg(self, msg)
+ elif msg.fn < fn:
+ log.warning("(%s) Stale TRXD message (fn=%u): %s"
+ % (self, fn, msg.desc_hdr()))
+
+ self._tx_queue = [msg for msg in self._tx_queue if msg.fn > fn]
+ self._tx_queue_lock.release()
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/39328?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I41291708effdd2c767be680fff22ffbd9a56815e
Gerrit-Change-Number: 39328
Gerrit-PatchSet: 5
Gerrit-Owner: kirr <kirr(a)nexedi.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: laforge <laforge(a)osmocom.org>
Gerrit-CC: osmith <osmith(a)sysmocom.de>