<p>pespin <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/osmo-bts/+/15706">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  ipse: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">bts-trx: Time out if no clock ind recvd after RSP POWERON<br><br>Before this patch, if due to whatever reason the TRX started fine (RSP<br>POWERON 0) and sockets were created but no CLOCK IND was ever received<br>by the BTS, it wouldn't notice since the timerfd timeouts<br>(bts_shutdown("no clock")) are only checked after the first CLOCK IND is<br>sent by the TRX.<br>As a result, the BTS would be kept on forever saying everything is fine<br>but it would be sending no DL burst at all to the TRX (tested with a<br>modfied osmo-trx dropping clock indication).<br>With this patch, new APIs are added to indicate the scheduler_trx code<br>the timeframes where clock ind are expected (between RSP POWERON 0 and<br>RSP POWEROFF 0); if TRX sends clock indications out of that timeframe,<br>BTs lower layers will drop them (controlled by "powered" bool).<br>Hence, the scheduler_trx can now place a timeout (reusing same timerfd<br>because its new use is exclusive in time with its other previous use)<br>when it is told that CLOCK IND should start appearing, and if none<br>arrives in considerable time, then the BTS can be shut down to notify<br>the rest of the network.<br><br>Related: OS#4215<br>Change-Id: Iba5dbe867aff10e70ec73dbf1f7aeeecb15c0a4d<br>---<br>M include/osmo-bts/scheduler.h<br>M src/osmo-bts-trx/l1_if.c<br>M src/osmo-bts-trx/scheduler_trx.c<br>3 files changed, 57 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmo-bts/scheduler.h b/include/osmo-bts/scheduler.h</span><br><span>index e693e3e..3100a1d 100644</span><br><span>--- a/include/osmo-bts/scheduler.h</span><br><span>+++ b/include/osmo-bts/scheduler.h</span><br><span>@@ -175,6 +175,12 @@</span><br><span> /*! \brief PHY informs us of new (current) GSM frame number */</span><br><span> int trx_sched_clock(struct gsm_bts *bts, uint32_t fn);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief PHY informs us clock indications should start to be received */</span><br><span style="color: hsl(120, 100%, 40%);">+int trx_sched_clock_started(struct gsm_bts *bts);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief PHY informs us no more clock indications should be received anymore */</span><br><span style="color: hsl(120, 100%, 40%);">+int trx_sched_clock_stopped(struct gsm_bts *bts);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \brief set multiframe scheduler to given physical channel config */</span><br><span> int trx_sched_set_pchan(struct l1sched_trx *l1t, uint8_t tn,</span><br><span>         enum gsm_phys_chan_config pchan);</span><br><span>diff --git a/src/osmo-bts-trx/l1_if.c b/src/osmo-bts-trx/l1_if.c</span><br><span>index 1079128..38b43b9 100644</span><br><span>--- a/src/osmo-bts-trx/l1_if.c</span><br><span>+++ b/src/osmo-bts-trx/l1_if.c</span><br><span>@@ -176,10 +176,13 @@</span><br><span>    plink->u.osmotrx.poweronoff_sent = false;</span><br><span> </span><br><span>     if (poweronoff) {</span><br><span style="color: hsl(0, 100%, 40%);">-               if (rc == 0 && pinst->phy_link->state != PHY_LINK_CONNECTED)</span><br><span style="color: hsl(120, 100%, 40%);">+            if (rc == 0 && pinst->phy_link->state != PHY_LINK_CONNECTED) {</span><br><span style="color: hsl(120, 100%, 40%);">+                  trx_sched_clock_started(pinst->trx->bts);</span><br><span>                      phy_link_state_set(pinst->phy_link, PHY_LINK_CONNECTED);</span><br><span style="color: hsl(0, 100%, 40%);">-             else if (rc != 0 && pinst->phy_link->state != PHY_LINK_SHUTDOWN)</span><br><span style="color: hsl(120, 100%, 40%);">+                } else if (rc != 0 && pinst->phy_link->state != PHY_LINK_SHUTDOWN) {</span><br><span style="color: hsl(120, 100%, 40%);">+                    trx_sched_clock_stopped(pinst->trx->bts);</span><br><span>                      phy_link_state_set(pinst->phy_link, PHY_LINK_SHUTDOWN);</span><br><span style="color: hsl(120, 100%, 40%);">+            }</span><br><span>    }</span><br><span> }</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 af639e2..8662a14 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>@@ -1682,6 +1682,52 @@</span><br><span>     return -1;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief This is the cb of the initial timer set upon start. On timeout, it</span><br><span style="color: hsl(120, 100%, 40%);">+ *  means it wasn't replaced and hence no CLOCK IND was received. */</span><br><span style="color: hsl(120, 100%, 40%);">+static int trx_start_noclockind_to_cb(struct osmo_fd *ofd, unsigned int what)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        struct gsm_bts *bts = ofd->data;</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 style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  osmo_fd_close(&tcs->fn_timer_ofd); /* Avoid being called again */</span><br><span style="color: hsl(120, 100%, 40%);">+      bts_shutdown(bts, "No clock since TRX was started");</span><br><span style="color: hsl(120, 100%, 40%);">+        return -1;</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%);">+/*! \brief PHY informs us clock indications should start to be received */</span><br><span style="color: hsl(120, 100%, 40%);">+int trx_sched_clock_started(struct gsm_bts *bts)</span><br><span style="color: hsl(120, 100%, 40%);">+{</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 style="color: hsl(120, 100%, 40%);">+    const struct timespec it_val = {3, 0};</span><br><span style="color: hsl(120, 100%, 40%);">+        const struct timespec it_intval = {0, 0};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   LOGP(DL1C, LOGL_NOTICE, "GSM clock started, waiting for clock indications\n");</span><br><span style="color: hsl(120, 100%, 40%);">+      osmo_fd_close(&tcs->fn_timer_ofd);</span><br><span style="color: hsl(120, 100%, 40%);">+     memset(tcs, 0, sizeof(*tcs));</span><br><span style="color: hsl(120, 100%, 40%);">+ tcs->fn_timer_ofd.fd = -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Set up timeout to shutdown BTS if no clock ind is received in a few</span><br><span style="color: hsl(120, 100%, 40%);">+         * seconds. Upon clock ind receival, fn_timer_ofd will be reused and</span><br><span style="color: hsl(120, 100%, 40%);">+   * timeout won't trigger.</span><br><span style="color: hsl(120, 100%, 40%);">+  */</span><br><span style="color: hsl(120, 100%, 40%);">+   osmo_timerfd_setup(&tcs->fn_timer_ofd, trx_start_noclockind_to_cb, bts);</span><br><span style="color: hsl(120, 100%, 40%);">+       osmo_timerfd_schedule(&tcs->fn_timer_ofd, &it_val, &it_intval);</span><br><span style="color: hsl(120, 100%, 40%);">+        return 0;</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%);">+/*! \brief PHY informs us no more clock indications should be received anymore */</span><br><span style="color: hsl(120, 100%, 40%);">+int trx_sched_clock_stopped(struct gsm_bts *bts)</span><br><span style="color: hsl(120, 100%, 40%);">+{</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 style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  LOGP(DL1C, LOGL_NOTICE, "GSM clock stopped\n");</span><br><span style="color: hsl(120, 100%, 40%);">+     osmo_fd_close(&tcs->fn_timer_ofd);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! reset clock with current fn and schedule it. Called when trx becomes</span><br><span>  *  available or when max clock skew is reached */</span><br><span> static int trx_setup_clock(struct gsm_bts *bts, struct osmo_trx_clock_state *tcs,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-bts/+/15706">change 15706</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/+/15706"/><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: Iba5dbe867aff10e70ec73dbf1f7aeeecb15c0a4d </div>
<div style="display:none"> Gerrit-Change-Number: 15706 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: fixeria <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: ipse <Alexander.Chemeris@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>