aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2020-03-11 10:31:36 -0400
committerFlorin Coras <florin.coras@gmail.com>2020-03-12 20:55:17 +0000
commit197180031bad1e51ee032d30d8a095a51207454c (patch)
tree2ae3e81dfa609b6d532c902e13ecb82c73e72143 /src/vppinfra
parent7a91b0e264d1dfd911eec18a265ead2ab8a9ad82 (diff)
vppinfra: refactor clib_timebase_t
Add a clib_time_t * argument to clib_timebase_init(...), to encourage client code to share the vlib_main_t's clib_time_t object. Display the current day / date in GMT via the "show time" debug CLI. Fix the test framework so it processes the new "show time" output format. Type: refactor Signed-off-by: Dave Barach <dave@barachs.net> Change-Id: I5e52d57eb164b7cdb6355362d520df6928491711
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/test_time_range.c4
-rw-r--r--src/vppinfra/time_range.c14
-rw-r--r--src/vppinfra/time_range.h12
3 files changed, 18 insertions, 12 deletions
diff --git a/src/vppinfra/test_time_range.c b/src/vppinfra/test_time_range.c
index a22ef3a2c08..a7071091757 100644
--- a/src/vppinfra/test_time_range.c
+++ b/src/vppinfra/test_time_range.c
@@ -30,7 +30,8 @@ test_time_range_main (unformat_input_t * input)
f64 timezone_offset;
/* Init time base */
- clib_timebase_init (tb, -5 /* EST */ , CLIB_TIMEBASE_DAYLIGHT_USA);
+ clib_timebase_init (tb, -5 /* EST */ , CLIB_TIMEBASE_DAYLIGHT_USA,
+ 0 /* allocate a clib_time_t */ );
/* Set up summer time cache */
now = clib_timebase_now (tb);
@@ -142,6 +143,7 @@ test_time_range_main (unformat_input_t * input)
}
unformat_free (input2);
+ clib_mem_free (tb->clib_time);
return 0;
}
diff --git a/src/vppinfra/time_range.c b/src/vppinfra/time_range.c
index ea95284ea03..20048f834d1 100644
--- a/src/vppinfra/time_range.c
+++ b/src/vppinfra/time_range.c
@@ -17,12 +17,20 @@
void
clib_timebase_init (clib_timebase_t * tb, i32 timezone_offset_in_hours,
- clib_timebase_daylight_time_t daylight_type)
+ clib_timebase_daylight_time_t daylight_type,
+ clib_time_t * clib_time)
{
clib_memset (tb, 0, sizeof (*tb));
- clib_time_init (&tb->clib_time);
- tb->time_zero = unix_time_now ();
+ if (clib_time == 0)
+ {
+ tb->clib_time = clib_mem_alloc_aligned
+ (sizeof (*clib_time), CLIB_CACHE_LINE_BYTES);
+ memset (tb->clib_time, 0, sizeof (*clib_time));
+ clib_time_init (tb->clib_time);
+ }
+ else
+ tb->clib_time = clib_time;
tb->timezone_offset = ((f64) (timezone_offset_in_hours)) * 3600.0;
tb->daylight_time_type = daylight_type;
diff --git a/src/vppinfra/time_range.h b/src/vppinfra/time_range.h
index 6dcd82d7deb..993bf9c360c 100644
--- a/src/vppinfra/time_range.h
+++ b/src/vppinfra/time_range.h
@@ -28,12 +28,7 @@ typedef enum
typedef struct
{
/* provides f64 seconds since clib_time_init was called */
- clib_time_t clib_time;
- /*
- * time in f64 seconds since Thursday 1 Jan 1970 00:00:00 UTC
- * when clib_time_init was called
- */
- f64 time_zero;
+ clib_time_t *clib_time;
f64 timezone_offset;
f64 summer_offset;
clib_timebase_daylight_time_t daylight_time_type;
@@ -57,7 +52,8 @@ typedef struct
} clib_timebase_range_t;
void clib_timebase_init (clib_timebase_t * tb, i32 timezone_offset_in_hours,
- clib_timebase_daylight_time_t daylight_type);
+ clib_timebase_daylight_time_t daylight_type,
+ clib_time_t * clib_time);
void clib_timebase_time_to_components (f64 now,
clib_timebase_component_t * cp);
@@ -93,7 +89,7 @@ clib_timebase_now (clib_timebase_t * tb)
{
f64 now;
- now = tb->time_zero + clib_time_now (&tb->clib_time);
+ now = tb->clib_time->init_reference_time + clib_time_now (tb->clib_time);
now += tb->timezone_offset;
now += clib_timebase_summer_offset_fastpath (tb, now);