<p>pespin has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-bts/+/15614">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">bts-trx: Allocate struct osmo_trx_clock_state as part of bts-trx private data<br><br>Change-Id: I9b7ffb51423ada74b8be347c57eade08f307f88f<br>---<br>M src/osmo-bts-trx/l1_if.h<br>M src/osmo-bts-trx/main.c<br>M src/osmo-bts-trx/scheduler_trx.c<br>3 files changed, 52 insertions(+), 44 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/14/15614/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/osmo-bts-trx/l1_if.h b/src/osmo-bts-trx/l1_if.h</span><br><span>index 87df951..29bd246 100644</span><br><span>--- a/src/osmo-bts-trx/l1_if.h</span><br><span>+++ b/src/osmo-bts-trx/l1_if.h</span><br><span>@@ -5,6 +5,50 @@</span><br><span> #include <osmo-bts/phy_link.h></span><br><span> #include "trx_if.h"</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * TRX frame clock handling</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * In a "normal" synchronous PHY layer, we would be polled every time</span><br><span style="color: hsl(120, 100%, 40%);">+ * the PHY needs data for a given frame number.  However, the</span><br><span style="color: hsl(120, 100%, 40%);">+ * OpenBTS-inherited TRX protocol works differently:  We (L1) must</span><br><span style="color: hsl(120, 100%, 40%);">+ * autonomously send burst data based on our own clock, and every so</span><br><span style="color: hsl(120, 100%, 40%);">+ * often (currently every ~ 216 frames), we get a clock indication from</span><br><span style="color: hsl(120, 100%, 40%);">+ * the TRX.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * We're using a MONOTONIC timerfd interval timer for the 4.615ms frame</span><br><span style="color: hsl(120, 100%, 40%);">+ * intervals, and then compute + send the 8 bursts for that frame.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Upon receiving a clock indication from the TRX, we compensate</span><br><span style="color: hsl(120, 100%, 40%);">+ * accordingly: If we were transmitting too fast, we're delaying the</span><br><span style="color: hsl(120, 100%, 40%);">+ * next interval timer accordingly.  If we were too slow, we immediately</span><br><span style="color: hsl(120, 100%, 40%);">+ * send burst data for the missing frame numbers.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! clock state of a given TRX */</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_trx_clock_state {</span><br><span style="color: hsl(120, 100%, 40%);">+      /*! number of FN periods without TRX clock indication */</span><br><span style="color: hsl(120, 100%, 40%);">+      uint32_t fn_without_clock_ind;</span><br><span style="color: hsl(120, 100%, 40%);">+        struct {</span><br><span style="color: hsl(120, 100%, 40%);">+              /*! last FN we processed based on FN period timer */</span><br><span style="color: hsl(120, 100%, 40%);">+          uint32_t fn;</span><br><span style="color: hsl(120, 100%, 40%);">+          /*! time at which we last processed FN */</span><br><span style="color: hsl(120, 100%, 40%);">+             struct timespec tv;</span><br><span style="color: hsl(120, 100%, 40%);">+   } last_fn_timer;</span><br><span style="color: hsl(120, 100%, 40%);">+      struct {</span><br><span style="color: hsl(120, 100%, 40%);">+              /*! last FN we received a clock indication for */</span><br><span style="color: hsl(120, 100%, 40%);">+             uint32_t fn;</span><br><span style="color: hsl(120, 100%, 40%);">+          /*! time at which we received the last clock indication */</span><br><span style="color: hsl(120, 100%, 40%);">+            struct timespec tv;</span><br><span style="color: hsl(120, 100%, 40%);">+   } last_clk_ind;</span><br><span style="color: hsl(120, 100%, 40%);">+       /*! Osmocom FD wrapper for timerfd */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct osmo_fd fn_timer_ofd;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* gsm_bts->model_priv, specific to osmo-bts-trx */</span><br><span style="color: hsl(120, 100%, 40%);">+struct bts_trx_priv {</span><br><span style="color: hsl(120, 100%, 40%);">+     struct osmo_trx_clock_state clk_s;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct trx_config {</span><br><span>      uint8_t                 trxd_hdr_ver_req; /* requested TRXD header version */</span><br><span>        uint8_t                 trxd_hdr_ver_use; /* actual TRXD header version in use */</span><br><span>diff --git a/src/osmo-bts-trx/main.c b/src/osmo-bts-trx/main.c</span><br><span>index b1fa207..cf40ea3 100644</span><br><span>--- a/src/osmo-bts-trx/main.c</span><br><span>+++ b/src/osmo-bts-trx/main.c</span><br><span>@@ -97,6 +97,10 @@</span><br><span> </span><br><span> int bts_model_init(struct gsm_bts *bts)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+   struct bts_trx_priv *bts_trx = talloc_zero(bts, struct bts_trx_priv);</span><br><span style="color: hsl(120, 100%, 40%);">+ bts_trx->clk_s.fn_timer_ofd.fd = -1;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     bts->model_priv = bts_trx;</span><br><span>        bts->variant = BTS_OSMO_TRX;</span><br><span>      bts->support.ciphers = CIPHER_A5(1) | CIPHER_A5(2) | CIPHER_A5(3);</span><br><span> </span><br><span>diff --git a/src/osmo-bts-trx/scheduler_trx.c b/src/osmo-bts-trx/scheduler_trx.c</span><br><span>index 8b0c761..6c3a8ff 100644</span><br><span>--- a/src/osmo-bts-trx/scheduler_trx.c</span><br><span>+++ b/src/osmo-bts-trx/scheduler_trx.c</span><br><span>@@ -1580,48 +1580,6 @@</span><br><span>      return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/*</span><br><span style="color: hsl(0, 100%, 40%);">- * TRX frame clock handling</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * In a "normal" synchronous PHY layer, we would be polled every time</span><br><span style="color: hsl(0, 100%, 40%);">- * the PHY needs data for a given frame number.  However, the</span><br><span style="color: hsl(0, 100%, 40%);">- * OpenBTS-inherited TRX protocol works differently:  We (L1) must</span><br><span style="color: hsl(0, 100%, 40%);">- * autonomously send burst data based on our own clock, and every so</span><br><span style="color: hsl(0, 100%, 40%);">- * often (currently every ~ 216 frames), we get a clock indication from</span><br><span style="color: hsl(0, 100%, 40%);">- * the TRX.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * We're using a MONOTONIC timerfd interval timer for the 4.615ms frame</span><br><span style="color: hsl(0, 100%, 40%);">- * intervals, and then compute + send the 8 bursts for that frame.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * Upon receiving a clock indication from the TRX, we compensate</span><br><span style="color: hsl(0, 100%, 40%);">- * accordingly: If we were transmitting too fast, we're delaying the</span><br><span style="color: hsl(0, 100%, 40%);">- * next interval timer accordingly.  If we were too slow, we immediately</span><br><span style="color: hsl(0, 100%, 40%);">- * send burst data for the missing frame numbers.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*! clock state of a given TRX */</span><br><span style="color: hsl(0, 100%, 40%);">-struct osmo_trx_clock_state {</span><br><span style="color: hsl(0, 100%, 40%);">-        /*! number of FN periods without TRX clock indication */</span><br><span style="color: hsl(0, 100%, 40%);">-        uint32_t fn_without_clock_ind;</span><br><span style="color: hsl(0, 100%, 40%);">-  struct {</span><br><span style="color: hsl(0, 100%, 40%);">-                /*! last FN we processed based on FN period timer */</span><br><span style="color: hsl(0, 100%, 40%);">-            uint32_t fn;</span><br><span style="color: hsl(0, 100%, 40%);">-            /*! time at which we last processed FN */</span><br><span style="color: hsl(0, 100%, 40%);">-               struct timespec tv;</span><br><span style="color: hsl(0, 100%, 40%);">-     } last_fn_timer;</span><br><span style="color: hsl(0, 100%, 40%);">-        struct {</span><br><span style="color: hsl(0, 100%, 40%);">-                /*! last FN we received a clock indication for */</span><br><span style="color: hsl(0, 100%, 40%);">-               uint32_t fn;</span><br><span style="color: hsl(0, 100%, 40%);">-            /*! time at which we received the last clock indication */</span><br><span style="color: hsl(0, 100%, 40%);">-              struct timespec tv;</span><br><span style="color: hsl(0, 100%, 40%);">-     } last_clk_ind;</span><br><span style="color: hsl(0, 100%, 40%);">- /*! Osmocom FD wrapper for timerfd */</span><br><span style="color: hsl(0, 100%, 40%);">-   struct osmo_fd fn_timer_ofd;</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* TODO: This must go and become part of the phy_link */</span><br><span style="color: hsl(0, 100%, 40%);">-static struct osmo_trx_clock_state g_clk_s = { .fn_timer_ofd.fd = -1 };</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /*! duration of a GSM frame in nano-seconds. (120ms/26) */</span><br><span> #define FRAME_DURATION_nS        4615384</span><br><span> /*! duration of a GSM frame in micro-seconds (120s/26) */</span><br><span>@@ -1665,7 +1623,8 @@</span><br><span> static int trx_fn_timer_cb(struct osmo_fd *ofd, unsigned int what)</span><br><span> {</span><br><span>      struct gsm_bts *bts = ofd->data;</span><br><span style="color: hsl(0, 100%, 40%);">-     struct osmo_trx_clock_state *tcs = &g_clk_s;</span><br><span style="color: hsl(120, 100%, 40%);">+      struct bts_trx_priv *bts_trx = (struct bts_trx_priv *)bts->model_priv;</span><br><span style="color: hsl(120, 100%, 40%);">+     struct osmo_trx_clock_state *tcs = &bts_trx->clk_s;</span><br><span>   struct timespec tv_now;</span><br><span>      uint64_t expire_count;</span><br><span>       int64_t elapsed_us, error_us;</span><br><span>@@ -1748,7 +1707,8 @@</span><br><span> /*! called every time we receive a clock indication from TRX */</span><br><span> int trx_sched_clock(struct gsm_bts *bts, uint32_t fn)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-  struct osmo_trx_clock_state *tcs = &g_clk_s;</span><br><span style="color: hsl(120, 100%, 40%);">+      struct bts_trx_priv *bts_trx = (struct bts_trx_priv *)bts->model_priv;</span><br><span style="color: hsl(120, 100%, 40%);">+     struct osmo_trx_clock_state *tcs = &bts_trx->clk_s;</span><br><span>   struct timespec tv_now;</span><br><span>      int elapsed_fn;</span><br><span>      int64_t elapsed_us, elapsed_us_since_clk, elapsed_fn_since_clk, error_us_since_clk;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-bts/+/15614">change 15614</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-bts/+/15614"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-bts </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I9b7ffb51423ada74b8be347c57eade08f307f88f </div>
<div style="display:none"> Gerrit-Change-Number: 15614 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>