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>
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40074?usp=email )
Change subject: trx_toolkit/data_msg: Remove burst from *Msg constructor arguments
......................................................................
trx_toolkit/data_msg: Remove burst from *Msg constructor arguments
Grepping through whole codebase does not reveal any place which invokes *Msg(burst=...).
Sonn we will add type to burst and it will be different types for TxMsg and RxMsg.
Adjust *Msg signature not to accept any burst argument as a preparatory
step for that.
Change-Id: I189956fdc0591ec64c09d4c7e1e3659dfc630fc0
---
M src/target/trx_toolkit/data_msg.pyx
1 file changed, 2 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/74/40074/1
diff --git a/src/target/trx_toolkit/data_msg.pyx b/src/target/trx_toolkit/data_msg.pyx
index ccbdd71..4b59fce 100644
--- a/src/target/trx_toolkit/data_msg.pyx
+++ b/src/target/trx_toolkit/data_msg.pyx
@@ -77,8 +77,8 @@
CHDR_VERSION_MAX = 0b1111
KNOWN_VERSIONS = tuple(range(KNOWN_VERSION_MAX+1))
- def __init__(self, fn = None, tn = None, burst = None, ver = 0):
- self.burst = burst # bytes|bytearray for ubit, array[b] for sbit, array[B] for usbit
+ def __init__(self, fn = None, tn = None, ver = 0):
+ self.burst = None # bytes|bytearray for ubit, array[b] for sbit, array[B] for usbit
self.ver = ver
self.fn = fn
self.tn = tn
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40074?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: I189956fdc0591ec64c09d4c7e1e3659dfc630fc0
Gerrit-Change-Number: 40074
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>