Change in libosmocore[master]: gprs_ns2_vc_fsm: use CLOCK_MONOTONIC for alive elapsed timer

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

laforge gerrit-no-reply at lists.osmocom.org
Fri Feb 12 09:37:50 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/22869 )

Change subject: gprs_ns2_vc_fsm: use CLOCK_MONOTONIC for alive elapsed timer
......................................................................

gprs_ns2_vc_fsm: use CLOCK_MONOTONIC for alive elapsed timer

gettimeofday can jump and the comment says it should not be used for elapsed timer.

Related: OS#4997
Change-Id: I41989d8f9f82f4d1f7b97f11577653699365c8ae
---
M src/gb/gprs_ns2_vc_fsm.c
1 file changed, 10 insertions(+), 6 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved
  daniel: Looks good to me, but someone else must approve



diff --git a/src/gb/gprs_ns2_vc_fsm.c b/src/gb/gprs_ns2_vc_fsm.c
index 66ee450..88ce8ae 100644
--- a/src/gb/gprs_ns2_vc_fsm.c
+++ b/src/gb/gprs_ns2_vc_fsm.c
@@ -70,7 +70,7 @@
 		struct osmo_timer_list timer;
 		enum ns2_timeout mode;
 		int N;
-		struct timeval timer_started;
+		struct timespec timer_started;
 	} alive;
 };
 
@@ -155,7 +155,7 @@
 	priv->alive.mode = NS_TOUT_TNS_ALIVE;
 	priv->alive.N = 0;
 
-	osmo_gettimeofday(&priv->alive.timer_started, NULL);
+	osmo_clock_gettime(CLOCK_MONOTONIC, &priv->alive.timer_started);
 	ns2_tx_alive(priv->nsvc);
 	osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_ALIVE], 0);
 }
@@ -167,11 +167,15 @@
 
 static int alive_timer_elapsed_ms(struct gprs_ns2_vc_priv *priv)
 {
-	struct timeval now, elapsed;
-	osmo_gettimeofday(&now, NULL);
-	timersub(&now, &priv->alive.timer_started, &elapsed);
+	struct timespec now, elapsed;
 
-	return 1000 * elapsed.tv_sec + elapsed.tv_usec / 1000;
+	if (osmo_clock_gettime(CLOCK_MONOTONIC, &now) != 0)
+		return 0;
+
+	timespecsub(&now, &priv->alive.timer_started, &elapsed);
+	LOGNSVC(priv->nsvc, LOGL_ERROR, "elapsed: %ld, now: %ld, saved: %ld.\n",
+		elapsed.tv_sec, now.tv_sec, priv->alive.timer_started.tv_sec);
+	return elapsed.tv_sec * 1000 + (elapsed.tv_nsec / 1000000);
 }
 
 static void recv_test_procedure(struct osmo_fsm_inst *fi)

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I41989d8f9f82f4d1f7b97f11577653699365c8ae
Gerrit-Change-Number: 22869
Gerrit-PatchSet: 6
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210212/1ae9240d/attachment.htm>


More information about the gerrit-log mailing list