Change in osmo-trx[master]: osmo-trx: Add osmo_signal to stop whole transceiver chain correctly o...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Mon Sep 3 15:07:27 UTC 2018


Pau Espin Pedrol has uploaded this change for review. ( https://gerrit.osmocom.org/10743


Change subject: osmo-trx: Add osmo_signal to stop whole transceiver chain correctly on error
......................................................................

osmo-trx: Add osmo_signal to stop whole transceiver chain correctly on error

Transceiver::stop() can only be called from either CTRL iface thread or
from main thread (running osmocom loop). That's because stop attempts to
cancel and then join all the other threads, which would then lock if
attempting to stop from some of them.
As a result, the best option is to indicate to the user of the
transceiver option (osmo-trx.cpp) to stop it in a correct fashion by
destroying the object from the main thread.

Change-Id: Iac1d2dbe2328e735db2d4b933cb67b1af1babca1
---
M CommonLibs/Makefile.am
A CommonLibs/osmo_signal.h
M Transceiver52M/Transceiver.cpp
M Transceiver52M/Transceiver.h
M Transceiver52M/osmo-trx.cpp
5 files changed, 81 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/43/10743/1

diff --git a/CommonLibs/Makefile.am b/CommonLibs/Makefile.am
index 2332acb..3173397 100644
--- a/CommonLibs/Makefile.am
+++ b/CommonLibs/Makefile.am
@@ -49,4 +49,5 @@
 	Logger.h \
 	trx_vty.h \
 	debug.h \
+	osmo_signal.h \
 	config_defs.h
diff --git a/CommonLibs/osmo_signal.h b/CommonLibs/osmo_signal.h
new file mode 100644
index 0000000..4d201d3
--- /dev/null
+++ b/CommonLibs/osmo_signal.h
@@ -0,0 +1,37 @@
+/* (C) 2018 by sysmocom s.f.m.c. GmbH <info at sysmocom.de>
+ *
+ * Author: Pau Espin Pedrol <pespin at sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+/* Generic signalling/notification infrastructure */
+
+#pragma once
+
+#include <osmocom/core/signal.h>
+
+/*
+ * Signalling subsystems
+ */
+enum signal_subsystems {
+	SS_TRANSC,
+};
+
+/* SS_TRANSC signals */
+enum SS_TRANSC {
+	S_TRANSC_STOP_REQUIRED, /* Transceiver fatal error, it should be stopped */
+};
diff --git a/Transceiver52M/Transceiver.cpp b/Transceiver52M/Transceiver.cpp
index a1ebb30..d827adb 100644
--- a/Transceiver52M/Transceiver.cpp
+++ b/Transceiver52M/Transceiver.cpp
@@ -27,6 +27,10 @@
 #include "Transceiver.h"
 #include <Logger.h>
 
+extern "C" {
+#include "osmo_signal.h"
+}
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -115,7 +119,7 @@
   : mBasePort(wBasePort), mLocalAddr(TRXAddress), mRemoteAddr(GSMcoreAddress),
     mClockSocket(TRXAddress, wBasePort, GSMcoreAddress, wBasePort + 100),
     mTransmitLatency(wTransmitLatency), mRadioInterface(wRadioInterface),
-    rssiOffset(wRssiOffset),
+    rssiOffset(wRssiOffset), sig_cbfn(NULL),
     mSPSTx(tx_sps), mSPSRx(rx_sps), mChans(chans), mEdge(false), mOn(false), mForceClockInterface(false),
     mTxFreq(0.0), mRxFreq(0.0), mTSC(0), mMaxExpectedDelayAB(0), mMaxExpectedDelayNB(0),
     mWriteBurstToDiskMask(0)
@@ -219,6 +223,17 @@
   return true;
 }
 
+void Transceiver::setSignalHandler(osmo_signal_cbfn cbfn)
+{
+  if(this->sig_cbfn)
+    osmo_signal_unregister_handler(SS_TRANSC, this->sig_cbfn, NULL);
+
+  if(cbfn) {
+    this->sig_cbfn = cbfn;
+    osmo_signal_register_handler(SS_TRANSC, this->sig_cbfn, NULL);
+  }
+}
+
 /*
  * Start the transceiver
  *
@@ -885,8 +900,12 @@
 
 void Transceiver::driveReceiveRadio()
 {
-  if (!mRadioInterface->driveReceiveRadio()) {
+  int rc = mRadioInterface->driveReceiveRadio();
+  if (rc == 0) {
     usleep(100000);
+  } else if (rc < 0) {
+    LOG(FATAL) << "radio Interface receive failed, requesting stop.";
+    osmo_signal_dispatch(SS_TRANSC, S_TRANSC_STOP_REQUIRED, this);
   } else if (mForceClockInterface || mTransmitDeadlineClock > mLastClockUpdateTime + GSM::Time(216,0)) {
     mForceClockInterface = false;
     writeClockInterface();
diff --git a/Transceiver52M/Transceiver.h b/Transceiver52M/Transceiver.h
index f9b54f0..e250adc 100644
--- a/Transceiver52M/Transceiver.h
+++ b/Transceiver52M/Transceiver.h
@@ -31,6 +31,7 @@
 #include <sys/socket.h>
 
 extern "C" {
+#include <osmocom/core/signal.h>
 #include "config_defs.h"
 }
 
@@ -128,6 +129,8 @@
   /** accessor for number of channels */
   size_t numChans() const { return mChans; };
 
+  void setSignalHandler(osmo_signal_cbfn cbfn);
+
   /** Codes for channel combinations */
   typedef enum {
     FILL,               ///< Channel is transmitted, but unused
@@ -177,6 +180,8 @@
 
   double rssiOffset;                      ///< RSSI to dBm conversion offset
 
+  osmo_signal_cbfn *sig_cbfn;              ///< Registered Signal Handler to announce events.
+
   /** modulate and add a burst to the transmit queue */
   void addRadioVector(size_t chan, BitVector &bits,
                       int RSSI, GSM::Time &wTime);
diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp
index 1c40fcf..d01a4cf 100644
--- a/Transceiver52M/osmo-trx.cpp
+++ b/Transceiver52M/osmo-trx.cpp
@@ -55,6 +55,7 @@
 #include "convert.h"
 #include "trx_vty.h"
 #include "debug.h"
+#include "osmo_signal.h"
 }
 
 #define DEFAULT_CONFIG_FILE	"osmo-trx.cfg"
@@ -112,6 +113,20 @@
 	return radio;
 }
 
+/* Callback function to be called every time we receive a signal from TRANSC */
+static int transc_sig_cb(unsigned int subsys, unsigned int signal,
+		     void *handler_data, void *signal_data)
+{
+	switch (signal) {
+	case S_TRANSC_STOP_REQUIRED:
+		gshutdown = true;
+                break;
+	default:
+                break;
+	}
+	return 0;
+}
+
 /* Create transceiver core
  *     The multi-threaded modem core operates at multiples of the GSM rate of
  *     270.8333 ksps and consists of GSM specific modulation, demodulation,
@@ -132,6 +147,8 @@
 		return -1;
 	}
 
+        transceiver->setSignalHandler(transc_sig_cb);
+
 	for (size_t i = 0; i < trx->cfg.num_chans; i++) {
 		fifo = radio->receiveFIFO(i);
 		if (fifo && transceiver->receiveFIFO(fifo, i))

-- 
To view, visit https://gerrit.osmocom.org/10743
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iac1d2dbe2328e735db2d4b933cb67b1af1babca1
Gerrit-Change-Number: 10743
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180903/decb6f38/attachment.htm>


More information about the gerrit-log mailing list