MINOR: clock: replace the timeval start_time with start_time_ns
Now that "now" is no more a timeval, there's no point keeping a copy
of it as a timeval, let's also switch start_time to nanoseconds, it
simplifies operations.
diff --git a/include/haproxy/clock.h b/include/haproxy/clock.h
index b7eea02..11eae4f 100644
--- a/include/haproxy/clock.h
+++ b/include/haproxy/clock.h
@@ -26,7 +26,7 @@
#include <haproxy/api.h>
extern struct timeval start_date; /* the process's start date in wall-clock time */
-extern struct timeval start_time; /* the process's start date in internal monotonic time */
+extern ullong start_time_ns; /* the process's start date in internal monotonic time (ns) */
extern volatile ullong global_now_ns; /* common monotonic date between all threads, in ns (wraps every 585 yr) */
extern THREAD_LOCAL ullong now_ns; /* internal monotonic date derived from real clock, in ns (wraps every 585 yr) */
diff --git a/src/activity.c b/src/activity.c
index d99bf10..4f72690 100644
--- a/src/activity.c
+++ b/src/activity.c
@@ -1087,7 +1087,7 @@
} while (0)
/* retrieve uptime */
- up = now_ns - tv_to_ns(&start_time);
+ up = now_ns - start_time_ns;
up_sec = ns_to_sec(up);
up_usec = (up / 1000U) % 1000000U;
diff --git a/src/clock.c b/src/clock.c
index 61f5af7..1b180e3 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -27,7 +27,7 @@
#include <haproxy/tools.h>
struct timeval start_date; /* the process's start date in wall-clock time */
-struct timeval start_time; /* the process's start date in internal monotonic time */
+ullong start_time_ns; /* the process's start date in internal monotonic time (ns) */
volatile ullong global_now_ns; /* common monotonic date between all threads, in ns (wraps every 585 yr) */
volatile uint global_now_ms; /* common monotonic date in milliseconds (may wrap) */
diff --git a/src/haproxy.c b/src/haproxy.c
index b083fc5..2bd42a9 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -1509,7 +1509,7 @@
tzset();
clock_init_process_date();
start_date = date;
- start_time = NS_TO_TV(now_ns);
+ start_time_ns = now_ns;
pid = getpid();
/* Set local host name and adjust some environment variables.
diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c
index 50e1dcd..ed016c0 100644
--- a/src/hlua_fcn.c
+++ b/src/hlua_fcn.c
@@ -305,8 +305,7 @@
*/
struct timeval tv;
- tv = NS_TO_TV(now_ns);
- tv_remain(&start_time, &tv, &tv); // tv = now_ns - start_time
+ tv = NS_TO_TV(now_ns - start_time_ns);
tv_add(&tv, &tv, &start_date);
lua_newtable(L);
diff --git a/src/stats.c b/src/stats.c
index 1dc32d2..5f883f9 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -3555,7 +3555,7 @@
{
struct appctx *appctx = __sc_appctx(sc);
struct show_stat_ctx *ctx = appctx->svcctx;
- unsigned int up = (ns_to_sec(now_ns) - start_time.tv_sec);
+ unsigned int up = ns_to_sec(now_ns - start_time_ns);
char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
const char *scope_ptr = stats_scope_ptr(appctx, sc);
unsigned long long bps;
@@ -4628,7 +4628,7 @@
}
glob_out_b32 *= 32; // values are 32-byte units
- up = now_ns - tv_to_ns(&start_time);
+ up = now_ns - start_time_ns;
up_sec = ns_to_sec(up);
up_usec = (up / 1000U) % 1000000U;