aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/time.h
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-12-01 08:59:03 -0500
committerFlorin Coras <florin.coras@gmail.com>2019-12-02 23:00:21 +0000
commite52d8d880ac644f07154bc2fb94035a198ed6688 (patch)
treeffbc53cdc8859504d32a6066b033394936332772 /src/vppinfra/time.h
parent5ef9ca6c0de25993bde0dbc354cc4a5bc83ab0eb (diff)
vppinfra: preserve total_cpu_time across clock freq adjustment
If clib_time_verify_frequency() adjusts the clock frequency, transform total_cpu_time to the new time coordinate space. Otherwise, we break comparisons with previous clib_time_now() value. Without this correction, time jumps in one direction or the other depending on the sign of the frequency change. Reasonably harmless in most cases, but under perfect storm conditions the wheels fall off. Type: fix Signed-off-by: Dave Barach <dave@barachs.net> Change-Id: I21802c2630e2c87ff817cd732b7d78bc022cd2d7
Diffstat (limited to 'src/vppinfra/time.h')
-rw-r--r--src/vppinfra/time.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/vppinfra/time.h b/src/vppinfra/time.h
index ae738db1307..b2d749256d3 100644
--- a/src/vppinfra/time.h
+++ b/src/vppinfra/time.h
@@ -205,14 +205,16 @@ clib_time_now_internal (clib_time_t * c, u64 n)
{
u64 l = c->last_cpu_time;
u64 t = c->total_cpu_time;
+ f64 rv;
t += n - l;
c->total_cpu_time = t;
c->last_cpu_time = n;
+ rv = t * c->seconds_per_clock;
if (PREDICT_FALSE
((c->last_cpu_time -
c->last_verify_cpu_time) >> c->log2_clocks_per_frequency_verify))
clib_time_verify_frequency (c);
- return t * c->seconds_per_clock;
+ return rv;
}
/* Maximum f64 value as max clib_time */