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.
This commit is contained in:
Willy Tarreau 2023-04-28 14:50:29 +02:00
parent 69530f59ae
commit c05d30e9d8
6 changed files with 7 additions and 8 deletions

View 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) */

View 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;

View 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) */

View 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.

View 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);

View 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;