Change in osmo-pcu[master]: fix time-delta calculations for measurement reports

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/.

Stefan Sperling gerrit-no-reply at lists.osmocom.org
Thu May 31 10:40:25 UTC 2018


Stefan Sperling has uploaded this change for review. ( https://gerrit.osmocom.org/9397


Change subject: fix time-delta calculations for measurement reports
......................................................................

fix time-delta calculations for measurement reports

The previous implementation unconditionally subtracted nanosecond
values from different time measurements, causing overflow if the
current measurement was taken in less of a fraction of a second
than the past measurement. Use timespecsub() instead, which
accounts for nanoseconds correctly.

Change-Id: I7d22e7b5902c230efeae66eb20c17026a4037887
Related: OS#3225
---
M src/gprs_rlcmac_meas.cpp
1 file changed, 14 insertions(+), 17 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/97/9397/1

diff --git a/src/gprs_rlcmac_meas.cpp b/src/gprs_rlcmac_meas.cpp
index ac01f2a..cffdbc6 100644
--- a/src/gprs_rlcmac_meas.cpp
+++ b/src/gprs_rlcmac_meas.cpp
@@ -17,6 +17,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
  
+#include <osmocom/core/timer_compat.h>
+
 #include <gprs_rlcmac.h>
 #include <gprs_debug.h>
 #include <pcu_l1_if.h>
@@ -72,15 +74,15 @@
 int gprs_rlcmac_rssi(struct gprs_rlcmac_tbf *tbf, int8_t rssi)
 {
 	struct timespec now_tv, *rssi_tv = &tbf->meas.rssi_tv;
-	uint32_t elapsed;
+	struct timespec elapsed;
 
 	tbf->meas.rssi_sum += rssi;
 	tbf->meas.rssi_num++;
 
 	osmo_clock_gettime(CLOCK_MONOTONIC, &now_tv);
-	elapsed = ((now_tv.tv_sec - rssi_tv->tv_sec) << 7)
-		+ (((now_tv.tv_nsec - rssi_tv->tv_nsec)/1000) << 7) / 1000000;
-	if (elapsed < 128)
+
+	timespecsub(&now_tv, rssi_tv, &elapsed);
+	if (elapsed.tv_sec < 1)
 		return 0;
 
 	gprs_rlcmac_rssi_rep(tbf);
@@ -116,7 +118,7 @@
 	uint16_t lost)
 {
 	struct timespec now_tv, *loss_tv = &tbf->m_bw.dl_loss_tv;
-	uint32_t elapsed;
+	struct timespec elapsed;
 	uint16_t sum = received + lost;
 
 	/* No measurement values */
@@ -129,10 +131,8 @@
 	tbf->m_bw.dl_loss_received += received;
 	tbf->m_bw.dl_loss_lost += lost;
 
-	osmo_clock_gettime(CLOCK_MONOTONIC, &now_tv);
-	elapsed = ((now_tv.tv_sec - loss_tv->tv_sec) << 7)
-		+ (((now_tv.tv_nsec - loss_tv->tv_nsec)/1000) << 7) / 1000000;
-	if (elapsed < 128)
+	timespecsub(&now_tv, loss_tv, &elapsed);
+	if (elapsed.tv_sec < 1)
 		return 0;
 
 	gprs_rlcmac_lost_rep(tbf);
@@ -169,21 +169,18 @@
 int gprs_rlcmac_dl_bw(struct gprs_rlcmac_dl_tbf *tbf, uint16_t octets)
 {
 	struct timespec now_tv, *bw_tv = &tbf->m_bw.dl_bw_tv;
-	uint32_t elapsed;
+	struct timespec elapsed;
 
 	tbf->m_bw.dl_bw_octets += octets;
 
 	osmo_clock_gettime(CLOCK_MONOTONIC, &now_tv);
-	elapsed = ((now_tv.tv_sec - bw_tv->tv_sec) << 7)
-		+ (((now_tv.tv_nsec - bw_tv->tv_nsec)/1000) << 7) / 1000000;
-	if (elapsed < 128)
+	timespecsub(&now_tv, bw_tv, &elapsed);
+	if (elapsed.tv_sec < 1)
 		return 0;
 
-	tbf->m_bw.dl_throughput = (tbf->m_bw.dl_bw_octets/elapsed);
-
+	tbf->m_bw.dl_throughput = (tbf->m_bw.dl_bw_octets << 10) / ((elapsed.tv_sec << 10) + (elapsed.tv_nsec >> 20));
 	LOGP(DRLCMACMEAS, LOGL_INFO, "DL Bandwitdh of IMSI=%s / TLLI=0x%08x: "
-		"%d KBits/s\n", tbf->imsi(), tbf->tlli(),
-		tbf->m_bw.dl_bw_octets / elapsed);
+		"%d KBits/s\n", tbf->imsi(), tbf->tlli(), tbf->m_bw.dl_throughput);
 
 	/* reset bandwidth values timestamp */
 	memcpy(bw_tv, &now_tv, sizeof(*bw_tv));

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

Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7d22e7b5902c230efeae66eb20c17026a4037887
Gerrit-Change-Number: 9397
Gerrit-PatchSet: 1
Gerrit-Owner: Stefan Sperling <ssperling at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180531/0e6a8778/attachment.htm>


More information about the gerrit-log mailing list