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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Introduce bts_shutdown FSM<br><br>Using an FSM here will allow for more complex ordered shutdown<br>procedures, like power ramp down, waiting for TRX deact asyncrhonously,<br>etc.<br><br>Current commit leaves everything in place already prepared to implement<br>ramp down, which will be implemented in next commit in the series.<br><br>Related: SYS#4920<br>Change-Id: I8f48f17e61c3b9b86342eaf5b8a2b1ac9758bde5<br>---<br>M include/osmo-bts/Makefile.am<br>A include/osmo-bts/bts_shutdown_fsm.h<br>M include/osmo-bts/gsm_data.h<br>M src/common/Makefile.am<br>M src/common/bts.c<br>A src/common/bts_shutdown_fsm.c<br>M src/common/gsm_data.c<br>7 files changed, 204 insertions(+), 34 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmo-bts/Makefile.am b/include/osmo-bts/Makefile.am</span><br><span>index 4999ab4..310fce2 100644</span><br><span>--- a/include/osmo-bts/Makefile.am</span><br><span>+++ b/include/osmo-bts/Makefile.am</span><br><span>@@ -2,6 +2,7 @@</span><br><span>        abis.h \</span><br><span>     bts.h \</span><br><span>      bts_model.h \</span><br><span style="color: hsl(120, 100%, 40%);">+ bts_shutdown_fsm.h \</span><br><span>         gsm_data.h \</span><br><span>         logging.h \</span><br><span>  measurement.h \</span><br><span>diff --git a/include/osmo-bts/bts_shutdown_fsm.h b/include/osmo-bts/bts_shutdown_fsm.h</span><br><span>new file mode 100644</span><br><span>index 0000000..1268b2b</span><br><span>--- /dev/null</span><br><span>+++ b/include/osmo-bts/bts_shutdown_fsm.h</span><br><span>@@ -0,0 +1,38 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/* BTS shutdown FSM */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* (C) 2020 by sysmocom - s.m.f.c. GmbH <info@sysmocom.de></span><br><span style="color: hsl(120, 100%, 40%);">+ * Author: Pau Espin Pedrol <pespin@sysmocom.de></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * All Rights Reserved</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU Affero General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; either version 3 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+ * (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * You should have received a copy of the GNU Affero General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#pragma once</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/fsm.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* 3GPP TS 24.008 ยง 4.1.3.3 GMM mobility management states on the network side */</span><br><span style="color: hsl(120, 100%, 40%);">+enum bts_shutdown_fsm_states {</span><br><span style="color: hsl(120, 100%, 40%);">+       BTS_SHUTDOWN_ST_NONE,</span><br><span style="color: hsl(120, 100%, 40%);">+ BTS_SHUTDOWN_ST_WAIT_RAMP_DOWN_COMPL,</span><br><span style="color: hsl(120, 100%, 40%);">+ BTS_SHUTDOWN_ST_EXIT,</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%);">+enum bts_shutdown_fsm_events {</span><br><span style="color: hsl(120, 100%, 40%);">+   BTS_SHUTDOWN_EV_START,</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%);">+extern struct osmo_fsm bts_shutdown_fsm;</span><br><span>diff --git a/include/osmo-bts/gsm_data.h b/include/osmo-bts/gsm_data.h</span><br><span>index 9032aeb..416864f 100644</span><br><span>--- a/include/osmo-bts/gsm_data.h</span><br><span>+++ b/include/osmo-bts/gsm_data.h</span><br><span>@@ -733,6 +733,9 @@</span><br><span>                char *sock_path;</span><br><span>     } pcu;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    struct osmo_fsm_inst *shutdown_fi; /* FSM instance to manage shutdown procedure during process exit */</span><br><span style="color: hsl(120, 100%, 40%);">+        struct osmo_tdef *T_defs; /* Timer defines */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>      void *model_priv; /* Allocated by bts_model, contains model specific data pointer */</span><br><span> };</span><br><span> </span><br><span>diff --git a/src/common/Makefile.am b/src/common/Makefile.am</span><br><span>index 85b7038..2fa5514 100644</span><br><span>--- a/src/common/Makefile.am</span><br><span>+++ b/src/common/Makefile.am</span><br><span>@@ -27,6 +27,7 @@</span><br><span>      tx_power.c \</span><br><span>         bts_ctrl_commands.c \</span><br><span>        bts_ctrl_lookup.c \</span><br><span style="color: hsl(120, 100%, 40%);">+   bts_shutdown_fsm.c \</span><br><span>         l1sap.c \</span><br><span>    cbch.c \</span><br><span>     power_control.c \</span><br><span>diff --git a/src/common/bts.c b/src/common/bts.c</span><br><span>index d2bca2f..dccb098 100644</span><br><span>--- a/src/common/bts.c</span><br><span>+++ b/src/common/bts.c</span><br><span>@@ -269,39 +269,6 @@</span><br><span>        return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static void shutdown_timer_cb(void *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-    fprintf(stderr, "Shutdown timer expired\n");</span><br><span style="color: hsl(0, 100%, 40%);">-  exit(42);</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%);">-static struct osmo_timer_list shutdown_timer = {</span><br><span style="color: hsl(0, 100%, 40%);">-      .cb = &shutdown_timer_cb,</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%);">-void bts_shutdown(struct gsm_bts *bts, const char *reason)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-      struct gsm_bts_trx *trx;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-        if (osmo_timer_pending(&shutdown_timer)) {</span><br><span style="color: hsl(0, 100%, 40%);">-          LOGP(DOML, LOGL_NOTICE,</span><br><span style="color: hsl(0, 100%, 40%);">-                 "BTS is already being shutdown.\n");</span><br><span style="color: hsl(0, 100%, 40%);">-          return;</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%);">-       LOGP(DOML, LOGL_NOTICE, "Shutting down BTS %u, Reason %s\n",</span><br><span style="color: hsl(0, 100%, 40%);">-          bts->nr, reason);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    llist_for_each_entry_reverse(trx, &bts->trx_list, list) {</span><br><span style="color: hsl(0, 100%, 40%);">-                bts_model_trx_deact_rf(trx);</span><br><span style="color: hsl(0, 100%, 40%);">-            bts_model_trx_close(trx);</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%);">-       /* schedule a timer to make sure select loop logic can run again</span><br><span style="color: hsl(0, 100%, 40%);">-         * to dispatch any pending primitives */</span><br><span style="color: hsl(0, 100%, 40%);">-        osmo_timer_schedule(&shutdown_timer, 3, 0);</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /* main link is established, send status report */</span><br><span> int bts_link_estab(struct gsm_bts *bts)</span><br><span> {</span><br><span>diff --git a/src/common/bts_shutdown_fsm.c b/src/common/bts_shutdown_fsm.c</span><br><span>new file mode 100644</span><br><span>index 0000000..50ef652</span><br><span>--- /dev/null</span><br><span>+++ b/src/common/bts_shutdown_fsm.c</span><br><span>@@ -0,0 +1,144 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/* BTS shutdown FSM */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* (C) 2020 by sysmocom - s.m.f.c. GmbH <info@sysmocom.de></span><br><span style="color: hsl(120, 100%, 40%);">+ * Author: Pau Espin Pedrol <pespin@sysmocom.de></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * All Rights Reserved</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU Affero General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; either version 3 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+ * (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * You should have received a copy of the GNU Affero General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/fsm.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/tdef.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmo-bts/bts_shutdown_fsm.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmo-bts/logging.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmo-bts/gsm_data.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmo-bts/bts_model.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define X(s) (1 << (s))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct osmo_tdef_state_timeout bts_shutdown_fsm_timeouts[32] = {</span><br><span style="color: hsl(120, 100%, 40%);">+     [BTS_SHUTDOWN_ST_WAIT_RAMP_DOWN_COMPL] = { .T = -1 },</span><br><span style="color: hsl(120, 100%, 40%);">+ [BTS_SHUTDOWN_ST_EXIT] = { .T = -2 },</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%);">+#define bts_shutdown_fsm_state_chg(fi, NEXT_STATE) \</span><br><span style="color: hsl(120, 100%, 40%);">+     osmo_tdef_fsm_inst_state_chg(fi, NEXT_STATE, bts_shutdown_fsm_timeouts, ((struct gsm_bts *)fi->priv)->T_defs, -1)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void st_none(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       switch(event) {</span><br><span style="color: hsl(120, 100%, 40%);">+       case BTS_SHUTDOWN_EV_START:</span><br><span style="color: hsl(120, 100%, 40%);">+           bts_shutdown_fsm_state_chg(fi, BTS_SHUTDOWN_ST_WAIT_RAMP_DOWN_COMPL);</span><br><span style="color: hsl(120, 100%, 40%);">+         break;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void st_wait_ramp_down_compl_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        /* TODO: here power ramp down will be started on all TRX, prior to changing state */</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%);">+static void st_wait_ramp_down_compl(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       /* TODO: In here once we have ramp down implemented we'll transit to</span><br><span style="color: hsl(120, 100%, 40%);">+         regular exit. For now we simply wait for state timeout</span><br><span style="color: hsl(120, 100%, 40%);">+        bts_shutdown_fsm_state_chg(fi, BTS_SHUTDOWN_ST_EXIT);</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void st_exit_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       struct gsm_bts *bts = (struct gsm_bts *)fi->priv;</span><br><span style="color: hsl(120, 100%, 40%);">+  struct gsm_bts_trx *trx;</span><br><span style="color: hsl(120, 100%, 40%);">+      llist_for_each_entry_reverse(trx, &bts->trx_list, list) {</span><br><span style="color: hsl(120, 100%, 40%);">+              bts_model_trx_deact_rf(trx);</span><br><span style="color: hsl(120, 100%, 40%);">+          bts_model_trx_close(trx);</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+     /* There's yet no way to get confirmation from lower layers regarding</span><br><span style="color: hsl(120, 100%, 40%);">+        state. Allow a few seconds of select() loop and timeout timer will</span><br><span style="color: hsl(120, 100%, 40%);">+    exit later */</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%);">+static struct osmo_fsm_state bts_shutdown_fsm_states[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+     [BTS_SHUTDOWN_ST_NONE] = {</span><br><span style="color: hsl(120, 100%, 40%);">+            .in_event_mask =</span><br><span style="color: hsl(120, 100%, 40%);">+                      X(BTS_SHUTDOWN_EV_START),</span><br><span style="color: hsl(120, 100%, 40%);">+             .out_state_mask = X(BTS_SHUTDOWN_ST_WAIT_RAMP_DOWN_COMPL),</span><br><span style="color: hsl(120, 100%, 40%);">+            .name = "NONE",</span><br><span style="color: hsl(120, 100%, 40%);">+             .action = st_none,</span><br><span style="color: hsl(120, 100%, 40%);">+    },</span><br><span style="color: hsl(120, 100%, 40%);">+    [BTS_SHUTDOWN_ST_WAIT_RAMP_DOWN_COMPL] = {</span><br><span style="color: hsl(120, 100%, 40%);">+            .in_event_mask = 0,</span><br><span style="color: hsl(120, 100%, 40%);">+           .out_state_mask =</span><br><span style="color: hsl(120, 100%, 40%);">+                     X(BTS_SHUTDOWN_ST_EXIT),</span><br><span style="color: hsl(120, 100%, 40%);">+              .name = "WAIT_RAMP_DOWN_COMPL",</span><br><span style="color: hsl(120, 100%, 40%);">+             .onenter = st_wait_ramp_down_compl_on_enter,</span><br><span style="color: hsl(120, 100%, 40%);">+          .action = st_wait_ramp_down_compl,</span><br><span style="color: hsl(120, 100%, 40%);">+    },</span><br><span style="color: hsl(120, 100%, 40%);">+    [BTS_SHUTDOWN_ST_EXIT] = {</span><br><span style="color: hsl(120, 100%, 40%);">+            .name = "EXIT",</span><br><span style="color: hsl(120, 100%, 40%);">+             .onenter = st_exit_on_enter,</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+const struct value_string bts_shutdown_fsm_event_names[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_VALUE_STRING(BTS_SHUTDOWN_EV_START),</span><br><span style="color: hsl(120, 100%, 40%);">+     { 0, NULL }</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%);">+int bts_shutdown_fsm_timer_cb(struct osmo_fsm_inst *fi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (fi->state) {</span><br><span style="color: hsl(120, 100%, 40%);">+       case BTS_SHUTDOWN_ST_WAIT_RAMP_DOWN_COMPL:</span><br><span style="color: hsl(120, 100%, 40%);">+            LOGPFSML(fi, LOGL_ERROR, "Timer expired waiting for ramp down complete\n");</span><br><span style="color: hsl(120, 100%, 40%);">+         bts_shutdown_fsm_state_chg(fi, BTS_SHUTDOWN_ST_EXIT);</span><br><span style="color: hsl(120, 100%, 40%);">+         break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case BTS_SHUTDOWN_ST_EXIT:</span><br><span style="color: hsl(120, 100%, 40%);">+            LOGPFSML(fi, LOGL_NOTICE, "Shutdown process completed successfuly, exiting process\n");</span><br><span style="color: hsl(120, 100%, 40%);">+             exit(0);</span><br><span style="color: hsl(120, 100%, 40%);">+              break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              OSMO_ASSERT(false);</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 style="color: hsl(120, 100%, 40%);">+struct osmo_fsm bts_shutdown_fsm = {</span><br><span style="color: hsl(120, 100%, 40%);">+  .name = "BTS_SHUTDOWN",</span><br><span style="color: hsl(120, 100%, 40%);">+     .states = bts_shutdown_fsm_states,</span><br><span style="color: hsl(120, 100%, 40%);">+    .num_states = ARRAY_SIZE(bts_shutdown_fsm_states),</span><br><span style="color: hsl(120, 100%, 40%);">+    .event_names = bts_shutdown_fsm_event_names,</span><br><span style="color: hsl(120, 100%, 40%);">+  .log_subsys = DOML,</span><br><span style="color: hsl(120, 100%, 40%);">+   .timer_cb = bts_shutdown_fsm_timer_cb,</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%);">+static __attribute__((constructor)) void bts_shutdown_fsm_init(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_ASSERT(osmo_fsm_register(&bts_shutdown_fsm) == 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%);">+void bts_shutdown(struct gsm_bts *bts, const char *reason)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       struct osmo_fsm_inst *fi = bts->shutdown_fi;</span><br><span style="color: hsl(120, 100%, 40%);">+       if (fi->state != BTS_SHUTDOWN_ST_NONE) {</span><br><span style="color: hsl(120, 100%, 40%);">+           LOGPFSML(fi, LOGL_NOTICE, "BTS is already being shutdown.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+              return;</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%);">+   LOGPFSML(fi, LOGL_NOTICE, "Shutting down BTS, reason: %s\n", reason);</span><br><span style="color: hsl(120, 100%, 40%);">+       osmo_fsm_inst_dispatch(fi, BTS_SHUTDOWN_EV_START, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/common/gsm_data.c b/src/common/gsm_data.c</span><br><span>index c680001..18d5b66 100644</span><br><span>--- a/src/common/gsm_data.c</span><br><span>+++ b/src/common/gsm_data.c</span><br><span>@@ -28,12 +28,22 @@</span><br><span> </span><br><span> #include <osmocom/core/linuxlist.h></span><br><span> #include <osmocom/core/talloc.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/statistics.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/fsm.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/tdef.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #include <osmocom/gsm/gsm_utils.h></span><br><span> #include <osmocom/gsm/abis_nm.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <osmocom/core/statistics.h></span><br><span> #include <osmocom/codec/ecu.h></span><br><span> </span><br><span> #include <osmo-bts/gsm_data.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmo-bts/bts_shutdown_fsm.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct osmo_tdef bts_T_defs[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+  { .T=-1, .default_val=1, .desc="Time after which osmo-bts exits if regular ramp down during shut down process does not finish (s)" },</span><br><span style="color: hsl(120, 100%, 40%);">+       { .T=-2, .default_val=3, .desc="Time after which osmo-bts exits if requesting transceivers to stop during shut down process does not finish (s)" },</span><br><span style="color: hsl(120, 100%, 40%);">+ {}</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span> </span><br><span> void gsm_abis_mo_reset(struct gsm_abis_mo *mo)</span><br><span> {</span><br><span>@@ -277,6 +287,12 @@</span><br><span>     INIT_LLIST_HEAD(&bts->trx_list);</span><br><span>      bts->ms_max_power = 15;      /* dBm */</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ bts->T_defs = bts_T_defs;</span><br><span style="color: hsl(120, 100%, 40%);">+  osmo_tdefs_reset(bts->T_defs);</span><br><span style="color: hsl(120, 100%, 40%);">+     bts->shutdown_fi = osmo_fsm_inst_alloc(&bts_shutdown_fsm, bts, bts,</span><br><span style="color: hsl(120, 100%, 40%);">+                                           LOGL_INFO, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+      osmo_fsm_inst_update_id_f(bts->shutdown_fi, "bts%d", bts->nr);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>     gsm_mo_init(&bts->mo, bts, NM_OC_BTS,</span><br><span>                         bts->nr, 0xff, 0xff);</span><br><span>     gsm_mo_init(&bts->site_mgr.mo, bts, NM_OC_SITE_MANAGER,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-bts/+/18903">change 18903</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/+/18903"/><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: I8f48f17e61c3b9b86342eaf5b8a2b1ac9758bde5 </div>
<div style="display:none"> Gerrit-Change-Number: 18903 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </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 <vyanitskiy@sysmocom.de> </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-CC: neels <nhofmeyr@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>