]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: clock: replace the timeval start_time with start_time_ns
authorWilly Tarreau <w@1wt.eu>
Fri, 28 Apr 2023 12:50:29 +0000 (14:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 28 Apr 2023 14:08:08 +0000 (16:08 +0200)
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
src/activity.c
src/clock.c
src/haproxy.c
src/hlua_fcn.c
src/stats.c

index b7eea0226bf2103e49ecca8ee6f78e30c97feedf..11eae4f6a2f6241800cf2c986cf8d7ec3b42b53f 100644 (file)
@@ -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) */
index d99bf10f6f1b56e9002054675739c36ecb86de97..4f726907a18bba8fe9adc4af6d7246a4dcc0c3d7 100644 (file)
@@ -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;
 
index 61f5af76338c8e6f2575691fdf959b4655c290d4..1b180e35b13bcfc011fd64c2f6d9bfdf34208c43 100644 (file)
@@ -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) */
 
index b083fc568f812cd0241f3a6f39ef6d5c78b896f1..2bd42a95f7b3f1bbe7c47457cb3343d009fdf8bc 100644 (file)
@@ -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.
index 50e1dcd676d94a28062456bd229fd5c5f71a7bf7..ed016c0b85c4a94f032ad7a3587a08c55b02a285 100644 (file)
@@ -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);
index 1dc32d21ab219f278f1c0e24fcb3e058c5c8819a..5f883f9996d340f2336b6ba1f91e8295f86b9466 100644 (file)
@@ -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;