kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40088?usp=email )
Change subject: trx_toolkit/data_msg: TODO random -> C
......................................................................
trx_toolkit/data_msg: TODO random -> C
With this patch I'm completing my optimization work on fake_trx. I have
not had time to convert random routines to C yet. In my testing I was
not activating any FakeTRX random modes at all and so lack of C random
support was not showing in the profiles. But if those random modes will
be activated py-level random will certainly slow things down. Add TODO
entries to fix that.
For the reference compared to the state where Cython was just introduced
in I2159a07bece13bda4f6ccd957063d4644d8b5e4f (trx_toolkit: Move
FakeTRX-related performance-sensitive modules to Cython) we now perform
significantly better: for 1 BTS + 2 ccch_scan fake_trx now takes ~ 25%
of CPU without clock overruns. While at that Pyx-base state it was
taking ~ 70% of CPU with frequent clock overruns.
Profiles at pyx-base and hereby state can be seen here:
http://navytux.spb.ru/~kirr/osmo/fake_trx/pyx-base.htmlhttp://navytux.spb.ru/~kirr/osmo/fake_trx/pyx-optimized.html
and if comparing the effect of whole optimization work starting from
Ic9e16720daeb348b5f9c535c24a682db53a93529 parented on 54a0052a
(fake_trx: Remove unneeded field assignment) the effect is as follows:
Running 1 BTS + 2 Mobiles without Frequency Hopping + 1 ccch_scan
Before optimization work:
fake_trx is occupying 2 CPU cores loading every core close to
100% with hitting clock overrun non-stop.
After optimization work:
fake_Trx is occupying 1 CPU core with loading it ~ 35% by only
one thread without hitting any clock overrun.
Change-Id: If2c091c0a729a04dcac954ab0905b6f3be32a533
---
M src/target/trx_toolkit/data_msg.pyx
1 file changed, 12 insertions(+), 12 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/88/40088/1
diff --git a/src/target/trx_toolkit/data_msg.pyx b/src/target/trx_toolkit/data_msg.pyx
index bdc3119..d62dd63 100644
--- a/src/target/trx_toolkit/data_msg.pyx
+++ b/src/target/trx_toolkit/data_msg.pyx
@@ -131,11 +131,11 @@
def rand_fn(self):
''' Generate a random frame number. '''
- return random.randint(0, GSM_HYPERFRAME)
+ return random.randint(0, GSM_HYPERFRAME) # TODO -> C
def rand_tn(self):
''' Generate a random timeslot number. '''
- return random.randint(0, 7)
+ return random.randint(0, 7) # TODO -> C
def rand_hdr(self):
''' Randomize the message header. '''
@@ -393,7 +393,7 @@
if max is None:
max = PWR_MAX
- return random.randint(min, max)
+ return random.randint(min, max) # TODO -> C
def rand_hdr(self):
''' Randomize message specific header. '''
@@ -457,7 +457,7 @@
def rand_burst(self, length = GMSK_BURST_LEN):
''' Generate a random message specific burst. '''
- self.burst = bytearray([random.randint(0, 1) for _ in range(length)])
+ self.burst = bytearray([random.randint(0, 1) for _ in range(length)]) # TODO -> C
def trans(self, ver = None):
''' Transform this message into RxMsg. '''
@@ -625,7 +625,7 @@
if max is None:
max = RSSI_MAX
- return random.randint(min, max)
+ return random.randint(min, max) # TODO -> C
def rand_toa256(self, min = None, max = None):
''' Generate a random ToA (Time of Arrival) value. '''
@@ -636,7 +636,7 @@
if max is None:
max = TOA256_MAX
- return random.randint(min, max)
+ return random.randint(min, max) # TODO -> C
def rand_hdr(self):
''' Randomize message specific header. '''
@@ -646,15 +646,15 @@
self.toa256 = self.rand_toa256()
if self.ver >= 0x01:
- self.mod_type = random.choice(_mod_registry)
+ self.mod_type = random.choice(_mod_registry) # TODO -> C
if self.mod_type is ModGMSK:
- self.tsc_set = random.randint(0, 3)
+ self.tsc_set = random.randint(0, 3) # TODO -> C
else:
- self.tsc_set = random.randint(0, 1)
- self.tsc = random.randint(0, TSC_MAX)
+ self.tsc_set = random.randint(0, 1) # TODO -> C
+ self.tsc = random.randint(0, TSC_MAX) # TODO -> C
# C/I: Carrier-to-Interference ratio
- self.ci = random.randint(CI_MIN, CI_MAX)
+ self.ci = random.randint(CI_MIN, CI_MAX) # TODO -> C
def desc_hdr(self):
''' Generate human-readable header description. '''
@@ -815,7 +815,7 @@
if length is None:
length = self.mod_type.bl
- self.burst = array.array('b', [random.randint(-127, 127) for _ in range(length)])
+ self.burst = array.array('b', [random.randint(-127, 127) for _ in range(length)]) # TODO -> C
def trans(self, ver = None):
''' Transform this message to TxMsg. '''
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40088?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: If2c091c0a729a04dcac954ab0905b6f3be32a533
Gerrit-Change-Number: 40088
Gerrit-PatchSet: 1
Gerrit-Owner: kirr <kirr(a)nexedi.com>
Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-CC: osmith <osmith(a)sysmocom.de>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40090?usp=email )
Change subject: trx_toolkit/transceiver: Use `msg is None` instead of `not msg`
......................................................................
trx_toolkit/transceiver: Use `msg is None` instead of `not msg`
`msg is None` are two pointers comparision. `not msg` goes to py-level
and can generally invoke arbitrary python code.
Change-Id: I1278bed0a83dfac13734467f5333fae30e19bd5a
---
M src/target/trx_toolkit/transceiver.pyx
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/90/40090/1
diff --git a/src/target/trx_toolkit/transceiver.pyx b/src/target/trx_toolkit/transceiver.pyx
index 901a637..2b408a5 100644
--- a/src/target/trx_toolkit/transceiver.pyx
+++ b/src/target/trx_toolkit/transceiver.pyx
@@ -277,7 +277,7 @@
cdef TxMsg recv_data_msg(self): # -> TxMsg | None
# Read and parse data from socket
msg = self.data_if.recv_tx_msg()
- if not msg:
+ if msg is None:
return None
# Make sure that transceiver is configured and running
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40090?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: I1278bed0a83dfac13734467f5333fae30e19bd5a
Gerrit-Change-Number: 40090
Gerrit-PatchSet: 1
Gerrit-Owner: kirr <kirr(a)nexedi.com>
Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-CC: osmith <osmith(a)sysmocom.de>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40083?usp=email )
Change subject: trx_toolkit/data_msg: Switch RxMsg .rssi .toa256 .tsc_set .tsc .ci from object to int
......................................................................
trx_toolkit/data_msg: Switch RxMsg .rssi .toa256 .tsc_set .tsc .ci from object to int
This are integer fields, assigning C-level type avoids py-related overhead
on access and arithmetics.
Change-Id: I66abcf26896ab83f94f144941ea2dd64f7a4821f
---
M src/target/trx_toolkit/data_msg.pxd
M src/target/trx_toolkit/data_msg.pyx
M src/target/trx_toolkit/test_data_msg.py
3 files changed, 28 insertions(+), 25 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/83/40083/1
diff --git a/src/target/trx_toolkit/data_msg.pxd b/src/target/trx_toolkit/data_msg.pxd
index e5c605e..e0acbda 100644
--- a/src/target/trx_toolkit/data_msg.pxd
+++ b/src/target/trx_toolkit/data_msg.pxd
@@ -70,15 +70,15 @@
cdef class RxMsg(Msg):
cdef public array.array burst # array.array[b] | None
- cdef public object rssi # int | None
- cdef public object toa256 # int | None
+ cdef public int rssi # RSSI_UNSET - unset
+ cdef public int toa256 # TOA256_UNSET - unset
# Version 0x01 specific
cdef public Modulation mod_type # Modulation | None
- cdef public object tsc_set # int | None
- cdef public object tsc # int | None
- cdef public object ci # int | None
+ cdef public int tsc_set # -1 if unset
+ cdef public int tsc # -1 if unset
+ cdef public int ci # CI_UNSET if unset
cdef _validate_burst_v0(self)
diff --git a/src/target/trx_toolkit/data_msg.pyx b/src/target/trx_toolkit/data_msg.pyx
index 1d40726..1e786c1 100644
--- a/src/target/trx_toolkit/data_msg.pyx
+++ b/src/target/trx_toolkit/data_msg.pyx
@@ -453,10 +453,12 @@
# rxlev2dbm(0..63) gives us [-110..-47], plus -10 dbm for noise
cdef int RSSI_MIN = -120
cdef int RSSI_MAX = -47
+cdef int RSSI_UNSET = 0
# Min and max values of int16_t
cdef int TOA256_MIN = -32768
-cdef int TOA256_MAX = 32767
+cdef int TOA256_MAX = 32767-1
+cdef int TOA256_UNSET = TOA256_MAX+1
# TSC (Training Sequence Code) range is [0, 7]
cdef int TSC_MAX = 7
@@ -464,6 +466,7 @@
# C/I range (in centiBels)
cdef int CI_MIN = -1280
cdef int CI_MAX = 1280
+cdef int CI_UNSET = 0x7fff
# IDLE frame / nope detection indicator
cdef int NOPE_IND = (1 << 7)
@@ -474,16 +477,16 @@
''' Rx (TRX -> L1) message coding API. '''
def __cinit__(self):
- self.rssi = None
- self.toa256 = None
+ self.rssi = RSSI_UNSET
+ self.toa256 = TOA256_UNSET
# Version 0x01 specific (default values)
self.mod_type = ModGMSK
self.nope_ind = False
- self.tsc_set = None
- self.tsc = None
- self.ci = None
+ self.tsc_set = -1
+ self.tsc = -1
+ self.ci = CI_UNSET
cdef int HDR_LEN(self) except -1:
''' Calculate header length depending on its version. '''
@@ -541,13 +544,13 @@
# Validate common fields
Msg._validate(self)
- if self.rssi is None:
+ if self.rssi == RSSI_UNSET:
raise ValueError("RSSI is not set")
if self.rssi < RSSI_MIN or self.rssi > RSSI_MAX:
raise ValueError("RSSI %d is out of range" % self.rssi)
- if self.toa256 is None:
+ if self.toa256 == TOA256_UNSET:
raise ValueError("ToA256 is not set")
if self.toa256 < TOA256_MIN or self.toa256 > TOA256_MAX:
@@ -558,7 +561,7 @@
if type(self.mod_type) is not Modulation:
raise ValueError("Unknown Rx modulation type")
- if self.tsc_set is None:
+ if self.tsc_set == -1:
raise ValueError("TSC set is not set")
if self.mod_type is ModGMSK:
@@ -568,7 +571,7 @@
if not (0 <= self.tsc_set < 2):
raise ValueError("TSC set %d is out of range" % self.tsc_set)
- if self.tsc is None:
+ if self.tsc == -1:
raise ValueError("TSC is not set")
if not (0 <= self.tsc <= TSC_MAX):
@@ -576,7 +579,7 @@
# Version specific parameters (also present in NOPE.ind)
if self.ver >= 0x01:
- if self.ci is None:
+ if self.ci == CI_UNSET:
raise ValueError("C/I is not set")
if self.ci < CI_MIN or self.ci > CI_MAX:
@@ -630,21 +633,21 @@
# Describe the common part
result = Msg.desc_hdr(self)
- if self.rssi is not None:
+ if self.rssi != RSSI_UNSET:
result += ("rssi=%d " % self.rssi)
- if self.toa256 is not None:
+ if self.toa256 != TOA256_UNSET:
result += ("toa256=%d " % self.toa256)
if self.ver >= 0x01:
if not self.nope_ind:
if self.mod_type is not None:
result += ("%s " % self.mod_type)
- if self.tsc_set is not None:
+ if self.tsc_set != -1:
result += ("set=%u " % self.tsc_set)
- if self.tsc is not None:
+ if self.tsc != -1:
result += ("tsc=%u " % self.tsc)
- if self.ci is not None:
+ if self.ci != CI_UNSET:
result += ("C/I=%d cB " % self.ci)
else:
result += "(IDLE / NOPE IND) "
@@ -676,8 +679,8 @@
self.nope_ind = (mts & NOPE_IND) > 0
if self.nope_ind:
self.mod_type = None
- self.tsc_set = None
- self.tsc = None
+ self.tsc_set = -1
+ self.tsc = -1
return 0
# TSC: . . . . . X X X
diff --git a/src/target/trx_toolkit/test_data_msg.py b/src/target/trx_toolkit/test_data_msg.py
index db9a998..8d1d014 100644
--- a/src/target/trx_toolkit/test_data_msg.py
+++ b/src/target/trx_toolkit/test_data_msg.py
@@ -102,8 +102,8 @@
else:
msg.nope_ind = True
msg.mod_type = None
- msg.tsc_set = None
- msg.tsc = None
+ msg.tsc_set = -1
+ msg.tsc = -1
# Encode a given message to bytes
msg_enc = msg.gen_msg(legacy)
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40083?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: I66abcf26896ab83f94f144941ea2dd64f7a4821f
Gerrit-Change-Number: 40083
Gerrit-PatchSet: 1
Gerrit-Owner: kirr <kirr(a)nexedi.com>
Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-CC: osmith <osmith(a)sysmocom.de>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40085?usp=email )
Change subject: trx_toolkit/data_msg: Disable cyclic GC support for RxMsg
......................................................................
trx_toolkit/data_msg: Disable cyclic GC support for RxMsg
Checking profiling turned out that there are frequent
PyObject_GC_Track/PyObject_GC_UnTrack for RxMsg because BurstForwarder
creates RxMsg often: to forward on received TxMsg burst to N
destinations - N RxMsg instances are currently created.
Investigating generated data_msg.c code shows that neither Msg, nor TxMsg
have Py_TPFLAGS_HAVE_GC flag set, but RxMsg does have it set and does
have generated .tp_traverse and .tp_clear routines. Investigating a bit
more turns our that if we exclude `array.array burst` from RxMsg
definition, all those cyclic-GC related things go away from generated
code. So somehow Cython thinks that array.array can have a back pointer
to RxMsg and emits GC supporting code due to that.
But that is not possible to have a back-pointer from array.array to
RxMsg: the only object that array.array references is arraydescr object:
https://github.com/cython/cython/blob/e22e99e9/Cython/Includes/cpython/arra…
which is plain C struct inside and does not reference other objects at all:
https://github.com/cython/cython/blob/e22e99e9/Cython/Includes/cpython/arra…
-> So disable cyclic-GC support for RxMsg to avoid associated overhead.
Do so for TxMsg and Msg explicitly for symmetry as well.
Change-Id: I2c592cec4931db04c29cadfeb97ce5325295d862
---
M src/target/trx_toolkit/data_msg.pxd
M src/target/trx_toolkit/data_msg.pyx
2 files changed, 8 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/85/40085/1
diff --git a/src/target/trx_toolkit/data_msg.pxd b/src/target/trx_toolkit/data_msg.pxd
index e0acbda..2eb6ed3 100644
--- a/src/target/trx_toolkit/data_msg.pxd
+++ b/src/target/trx_toolkit/data_msg.pxd
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# cython: language_level=3
-from cython cimport final
+from cython cimport final, no_gc # NOTE no_gc means "no cyclic gc", acyclic gc support is still there
from cpython cimport array
from libc.stdint cimport int8_t, int64_t, uint8_t
@@ -19,6 +19,7 @@
cdef Modulation ModGMSK
+@no_gc
cdef class Msg:
cdef readonly int ver
cdef readonly int64_t fn # -1 if not valid
@@ -58,6 +59,7 @@
@final
+@no_gc
cdef class TxMsg(Msg):
cdef public bytearray burst # | None
cdef readonly int pwr # -1 if unset
@@ -67,6 +69,7 @@
@final
+@no_gc # NOTE by default cython thinks that .burst might participate in cycle
cdef class RxMsg(Msg):
cdef public array.array burst # array.array[b] | None
diff --git a/src/target/trx_toolkit/data_msg.pyx b/src/target/trx_toolkit/data_msg.pyx
index 1e786c1..304dbdb 100644
--- a/src/target/trx_toolkit/data_msg.pyx
+++ b/src/target/trx_toolkit/data_msg.pyx
@@ -19,7 +19,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-from cython cimport final
+from cython cimport final, no_gc
from libc.stdint cimport int16_t, int64_t, uint16_t, uint32_t
from cpython cimport array
@@ -79,6 +79,7 @@
cdef int KNOWN_VERSION_MAX = 1 # 0, 1
+@no_gc
cdef class Msg:
''' TRXD (DATA) message coding API (common part). '''
@@ -318,6 +319,7 @@
cdef int PWR_MAX = 0xff
@final
+@no_gc
cdef class TxMsg(Msg):
''' Tx (L1 -> TRX) message coding API. '''
@@ -473,6 +475,7 @@
@final
+@no_gc
cdef class RxMsg(Msg):
''' Rx (TRX -> L1) message coding API. '''
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40085?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: I2c592cec4931db04c29cadfeb97ce5325295d862
Gerrit-Change-Number: 40085
Gerrit-PatchSet: 1
Gerrit-Owner: kirr <kirr(a)nexedi.com>
Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-CC: osmith <osmith(a)sysmocom.de>
Gerrit-CC: pespin <pespin(a)sysmocom.de>