]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: checks: use a nanosecond counters instead of timeval for checks->start
authorWilly Tarreau <w@1wt.eu>
Fri, 28 Apr 2023 12:39:50 +0000 (14:39 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 28 Apr 2023 14:08:08 +0000 (16:08 +0200)
Now we store the checks start date as a nanosecond timestamps instead
of a timeval, this will simplify the operations with "now" in the near
future.

include/haproxy/check-t.h
src/check.c
src/mailers.c

index c489ae3513c64a8b03e17680ec427d3ee12f47bf..5b80189ee2fcbb3294ce8c5a7704d4eeb2f3c9fc 100644 (file)
@@ -156,7 +156,7 @@ struct check {
        struct buffer bi, bo;                   /* input and output buffers to send/recv check */
        struct buffer_wait buf_wait;            /* Wait list for buffer allocation */
        struct task *task;                      /* the task associated to the health check processing, NULL if disabled */
-       struct timeval start;                   /* last health check start time */
+       ullong start;                           /* last health check start time */
        long duration;                          /* time in ms took to finish last health check */
        short status, code;                     /* check result, check code */
        unsigned short port;                    /* the port to use for the health checks */
index a8aeb9a15f49a80afb4647ce743cab5a8ca9b0e7..1d67dfd49ed6875a092ca50e77f86ad2352db716 100644 (file)
@@ -471,7 +471,7 @@ void set_server_check_status(struct check *check, short status, const char *desc
        if (status == HCHK_STATUS_START) {
                check->result = CHK_RES_UNKNOWN;        /* no result yet */
                check->desc[0] = '\0';
-               check->start = now;
+               check->start = tv_to_ns(&now);
                return;
        }
 
@@ -490,10 +490,10 @@ void set_server_check_status(struct check *check, short status, const char *desc
 
        if (status == HCHK_STATUS_HANA)
                check->duration = -1;
-       else if (!tv_iszero(&check->start)) {
+       else if (check->start) {
                /* set_server_check_status() may be called more than once */
-               check->duration = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&check->start));
-               tv_zero(&check->start);
+               check->duration = ns_to_ms(tv_to_ns(&now) - check->start);
+               check->start = 0;
        }
 
        /* no change is expected if no state change occurred */
@@ -1499,7 +1499,7 @@ int start_check_task(struct check *check, int mininter,
 
        /* check this every ms */
        t->expire = tick_add(now_ms, MS_TO_TICKS(mininter * srvpos / nbcheck));
-       check->start = now;
+       check->start = tv_to_ns(&now);
        task_queue(t);
 
        return 1;
index 05d531306fa4d559a8889363851558a16063e8e5..89732d563f44037d821ab5a3483a45b886a85aa2 100644 (file)
@@ -145,7 +145,7 @@ int init_email_alert(struct mailers *mls, struct proxy *p, char **err)
 
                /* check this in one ms */
                t->expire    = TICK_ETERNITY;
-               check->start = now;
+               check->start = tv_to_ns(&now);
                task_queue(t);
        }