From e8e4712771026d59d4916f00f8a4d3a3212c1a7d Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 28 Apr 2023 14:39:50 +0200 Subject: [PATCH] MINOR: checks: use a nanosecond counters instead of timeval for checks->start 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 | 2 +- src/check.c | 10 +++++----- src/mailers.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/haproxy/check-t.h b/include/haproxy/check-t.h index c489ae351..5b80189ee 100644 --- a/include/haproxy/check-t.h +++ b/include/haproxy/check-t.h @@ -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 */ diff --git a/src/check.c b/src/check.c index a8aeb9a15..1d67dfd49 100644 --- a/src/check.c +++ b/src/check.c @@ -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; diff --git a/src/mailers.c b/src/mailers.c index 05d531306..89732d563 100644 --- a/src/mailers.c +++ b/src/mailers.c @@ -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); }