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.orgStefan Sperling has uploaded this change for review. ( https://gerrit.osmocom.org/9302
Change subject: read monotonic clock with clock_gettime() instead of gettimeofday()
......................................................................
read monotonic clock with clock_gettime() instead of gettimeofday()
There have been test failures on the osmo-pcu Jenkins builders due
to apparent clock drift. Switch relevant code from gettimeofday()
to clock_gettime() with CLOCK_MONOTONIC to prevent time from going
backwards and causing negative time deltas in calculations.
Change-Id: I775d85d0d3ac740330879e588bdab6fce7f0b46c
Related: OS#3225
---
M src/gprs_rlcmac_meas.cpp
M src/tbf.cpp
M src/tbf.h
3 files changed, 21 insertions(+), 21 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/02/9302/1
diff --git a/src/gprs_rlcmac_meas.cpp b/src/gprs_rlcmac_meas.cpp
index 41a7531..4f4f853 100644
--- a/src/gprs_rlcmac_meas.cpp
+++ b/src/gprs_rlcmac_meas.cpp
@@ -71,22 +71,22 @@
/* RSSI values received from MS */
int gprs_rlcmac_rssi(struct gprs_rlcmac_tbf *tbf, int8_t rssi)
{
- struct timeval now_tv, *rssi_tv = &tbf->meas.rssi_tv;
+ struct timespec now_tv, *rssi_tv = &tbf->meas.rssi_tv;
uint32_t elapsed;
tbf->meas.rssi_sum += rssi;
tbf->meas.rssi_num++;
- gettimeofday(&now_tv, NULL);
+ osmo_clock_gettime(CLOCK_MONOTONIC, &now_tv);
elapsed = ((now_tv.tv_sec - rssi_tv->tv_sec) << 7)
- + ((now_tv.tv_usec - rssi_tv->tv_usec) << 7) / 1000000;
+ + ((now_tv.tv_nsec/1000 - rssi_tv->tv_nsec/1000) << 7) / 1000000;
if (elapsed < 128)
return 0;
gprs_rlcmac_rssi_rep(tbf);
/* reset rssi values and timestamp */
- memcpy(rssi_tv, &now_tv, sizeof(struct timeval));
+ memcpy(rssi_tv, &now_tv, sizeof(*rssi_tv));
tbf->meas.rssi_sum = 0;
tbf->meas.rssi_num = 0;
@@ -115,7 +115,7 @@
int gprs_rlcmac_received_lost(struct gprs_rlcmac_dl_tbf *tbf, uint16_t received,
uint16_t lost)
{
- struct timeval now_tv, *loss_tv = &tbf->m_bw.dl_loss_tv;
+ struct timespec now_tv, *loss_tv = &tbf->m_bw.dl_loss_tv;
uint32_t elapsed;
uint16_t sum = received + lost;
@@ -129,16 +129,16 @@
tbf->m_bw.dl_loss_received += received;
tbf->m_bw.dl_loss_lost += lost;
- gettimeofday(&now_tv, NULL);
+ osmo_clock_gettime(CLOCK_MONOTONIC, &now_tv);
elapsed = ((now_tv.tv_sec - loss_tv->tv_sec) << 7)
- + ((now_tv.tv_usec - loss_tv->tv_usec) << 7) / 1000000;
+ + ((now_tv.tv_nsec/1000 - loss_tv->tv_nsec/1000) << 7) / 1000000;
if (elapsed < 128)
return 0;
gprs_rlcmac_lost_rep(tbf);
/* reset lost values and timestamp */
- memcpy(loss_tv, &now_tv, sizeof(struct timeval));
+ memcpy(loss_tv, &now_tv, sizeof(*loss_tv));
tbf->m_bw.dl_loss_received = 0;
tbf->m_bw.dl_loss_lost = 0;
@@ -168,14 +168,14 @@
int gprs_rlcmac_dl_bw(struct gprs_rlcmac_dl_tbf *tbf, uint16_t octets)
{
- struct timeval now_tv, *bw_tv = &tbf->m_bw.dl_bw_tv;
+ struct timespec now_tv, *bw_tv = &tbf->m_bw.dl_bw_tv;
uint32_t elapsed;
tbf->m_bw.dl_bw_octets += octets;
- gettimeofday(&now_tv, NULL);
+ osmo_clock_gettime(CLOCK_MONOTONIC, &now_tv);
elapsed = ((now_tv.tv_sec - bw_tv->tv_sec) << 7)
- + ((now_tv.tv_usec - bw_tv->tv_usec) << 7) / 1000000;
+ + ((now_tv.tv_nsec/1000 - bw_tv->tv_nsec/1000) << 7) / 1000000;
if (elapsed < 128)
return 0;
@@ -186,7 +186,7 @@
tbf->m_bw.dl_bw_octets / elapsed);
/* reset bandwidth values timestamp */
- memcpy(bw_tv, &now_tv, sizeof(struct timeval));
+ memcpy(bw_tv, &now_tv, sizeof(*bw_tv));
tbf->m_bw.dl_bw_octets = 0;
return 0;
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 14c1ee2..cd81731 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -182,7 +182,7 @@
rssi_sum(0),
rssi_num(0)
{
- timerclear(&rssi_tv);
+ memset(&rssi_tv, 0, sizeof(rssi_tv));
}
gprs_rlcmac_tbf::gprs_rlcmac_tbf(BTS *bts_, gprs_rlcmac_tbf_direction dir) :
@@ -913,7 +913,7 @@
}
/* set timestamp */
- gettimeofday(&tbf->meas.rssi_tv, NULL);
+ osmo_clock_gettime(CLOCK_MONOTONIC, &tbf->meas.rssi_tv);
tbf->set_ms(ms);
@@ -1024,8 +1024,8 @@
dl_loss_lost(0),
dl_loss_received(0)
{
- timerclear(&dl_bw_tv);
- timerclear(&dl_loss_tv);
+ memset(&dl_bw_tv, 0, sizeof(dl_bw_tv));
+ memset(&dl_loss_tv, 0, sizeof(dl_loss_tv));
}
gprs_rlcmac_dl_tbf::gprs_rlcmac_dl_tbf(BTS *bts_) :
@@ -1114,8 +1114,8 @@
tbf->m_last_dl_poll_fn = -1;
tbf->m_last_dl_drained_fn = -1;
- gettimeofday(&tbf->m_bw.dl_bw_tv, NULL);
- gettimeofday(&tbf->m_bw.dl_loss_tv, NULL);
+ osmo_clock_gettime(CLOCK_MONOTONIC, &tbf->m_bw.dl_bw_tv);
+ osmo_clock_gettime(CLOCK_MONOTONIC, &tbf->m_bw.dl_loss_tv);
return tbf;
}
diff --git a/src/tbf.h b/src/tbf.h
index 803b294..dc0b050 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -318,7 +318,7 @@
unsigned int num_fT_exp; /* number of consecutive fT expirations */
struct Meas {
- struct timeval rssi_tv; /* timestamp for rssi calculation */
+ struct timespec rssi_tv; /* timestamp for rssi calculation */
int32_t rssi_sum; /* sum of rssi values */
int rssi_num; /* number of rssi values added since rssi_tv */
@@ -665,11 +665,11 @@
int32_t m_last_dl_drained_fn;
struct BandWidth {
- struct timeval dl_bw_tv; /* timestamp for dl bw calculation */
+ struct timespec dl_bw_tv; /* timestamp for dl bw calculation */
uint32_t dl_bw_octets; /* number of octets since bw_tv */
uint32_t dl_throughput; /* throughput to be displayed in stats */
- struct timeval dl_loss_tv; /* timestamp for loss calculation */
+ struct timespec dl_loss_tv; /* timestamp for loss calculation */
uint16_t dl_loss_lost; /* sum of lost packets */
uint16_t dl_loss_received; /* sum of received packets */
--
To view, visit https://gerrit.osmocom.org/9302
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: I775d85d0d3ac740330879e588bdab6fce7f0b46c
Gerrit-Change-Number: 9302
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/20180525/7b6651dd/attachment.htm>