From c05d30e9d8f55ff7f04741c7ae836f74c703822a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 28 Apr 2023 14:50:29 +0200 Subject: [PATCH] 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. --- include/haproxy/clock.h | 2 +- src/activity.c | 2 +- src/clock.c | 2 +- src/haproxy.c | 2 +- src/hlua_fcn.c | 3 +-- src/stats.c | 4 ++-- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/haproxy/clock.h b/include/haproxy/clock.h index b7eea0226..11eae4f6a 100644 --- a/include/haproxy/clock.h +++ b/include/haproxy/clock.h @@ -26,7 +26,7 @@ #include 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 d99bf10f6..4f726907a 100644 --- a/src/activity.c +++ b/src/activity.c @@ -1087,7 +1087,7 @@ static int cli_io_handler_show_activity(struct appctx *appctx) } 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 61f5af763..1b180e35b 100644 --- a/src/clock.c +++ b/src/clock.c @@ -27,7 +27,7 @@ #include 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 b083fc568..2bd42a95f 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1509,7 +1509,7 @@ static void init_early(int argc, char **argv) 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 50e1dcd67..ed016c0b8 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -305,8 +305,7 @@ int hlua_now(lua_State *L) */ 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 1dc32d21a..5f883f999 100644 --- a/src/stats.c +++ b/src/stats.c @@ -3555,7 +3555,7 @@ static void stats_dump_html_info(struct stconn *sc, struct uri_auth *uri) { 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 @@ int stats_fill_info(struct field *info, int len, uint flags) } 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;