MINOR: clock: do not use now.tv_sec anymore

Instead we're using ns_to_sec(tv_to_ns(&now)) which allows the tv_sec
part to disappear. At this point, "now" is only used as a timeval in
clock.c where it is updated.
diff --git a/include/haproxy/backend.h b/include/haproxy/backend.h
index e0ec1e4..d0bcdf1 100644
--- a/include/haproxy/backend.h
+++ b/include/haproxy/backend.h
@@ -28,6 +28,7 @@
 #include <haproxy/proxy-t.h>
 #include <haproxy/server-t.h>
 #include <haproxy/stream-t.h>
+#include <haproxy/time.h>
 
 int assign_server(struct stream *s);
 int assign_server_address(struct stream *s);
@@ -64,7 +65,7 @@
 /* set the time of last session on the backend */
 static inline void be_set_sess_last(struct proxy *be)
 {
-	be->be_counters.last_sess = now.tv_sec;
+	be->be_counters.last_sess = ns_to_sec(tv_to_ns(&now));
 }
 
 /* This function returns non-zero if the designated server will be
diff --git a/include/haproxy/server.h b/include/haproxy/server.h
index 96c7a04..1b5dffb 100644
--- a/include/haproxy/server.h
+++ b/include/haproxy/server.h
@@ -183,7 +183,7 @@
 /* set the time of last session on the designated server */
 static inline void srv_set_sess_last(struct server *s)
 {
-	s->counters.last_sess = now.tv_sec;
+	s->counters.last_sess = ns_to_sec(tv_to_ns(&now));
 }
 
 /* returns the current server throttle rate between 0 and 100% */
diff --git a/src/backend.c b/src/backend.c
index 7b8e12d..b28b531 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -64,7 +64,7 @@
 int be_lastsession(const struct proxy *be)
 {
 	if (be->be_counters.last_sess)
-		return now.tv_sec - be->be_counters.last_sess;
+		return ns_to_sec(tv_to_ns(&now)) - be->be_counters.last_sess;
 
 	return -1;
 }
@@ -2505,7 +2505,7 @@
  */
 void set_backend_down(struct proxy *be)
 {
-	be->last_change = now.tv_sec;
+	be->last_change = ns_to_sec(tv_to_ns(&now));
 	_HA_ATOMIC_INC(&be->down_trans);
 
 	if (!(global.mode & MODE_STARTING)) {
@@ -2578,10 +2578,10 @@
 }
 
 int be_downtime(struct proxy *px) {
-	if (px->lbprm.tot_weight && px->last_change < now.tv_sec)  // ignore negative time
+	if (px->lbprm.tot_weight && px->last_change < ns_to_sec(tv_to_ns(&now)))  // ignore negative time
 		return px->down_time;
 
-	return now.tv_sec - px->last_change + px->down_time;
+	return ns_to_sec(tv_to_ns(&now)) - px->last_change + px->down_time;
 }
 
 /*
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 2472a21..f2ed7e6 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -660,7 +660,7 @@
 	peers->remote = p;
 	p->conf.file = strdup(file);
 	p->conf.line = linenum;
-	p->last_change = now.tv_sec;
+	p->last_change = ns_to_sec(tv_to_ns(&now));
 	p->xprt  = xprt_get(XPRT_RAW);
 	p->sock_init_arg = NULL;
 	HA_SPIN_INIT(&p->lock);
@@ -838,7 +838,7 @@
 		cfg_peers = curpeers;
 		curpeers->conf.file = strdup(file);
 		curpeers->conf.line = linenum;
-		curpeers->last_change = now.tv_sec;
+		curpeers->last_change = ns_to_sec(tv_to_ns(&now));
 		curpeers->id = strdup(args[1]);
 		curpeers->disabled = 0;
 	}
diff --git a/src/check.c b/src/check.c
index 1d67dfd..5dd3b89 100644
--- a/src/check.c
+++ b/src/check.c
@@ -1029,9 +1029,9 @@
 		      s->queue.length);
 
 	if ((s->cur_state == SRV_ST_STARTING) &&
-	    now.tv_sec < s->last_change + s->slowstart &&
-	    now.tv_sec >= s->last_change) {
-		ratio = MAX(1, 100 * (now.tv_sec - s->last_change) / s->slowstart);
+	    ns_to_sec(tv_to_ns(&now)) < s->last_change + s->slowstart &&
+	    ns_to_sec(tv_to_ns(&now)) >= s->last_change) {
+		ratio = MAX(1, 100 * (ns_to_sec(tv_to_ns(&now)) - s->last_change) / s->slowstart);
 		chunk_appendf(buf, "; throttle=%d%%", ratio);
 	}
 
diff --git a/src/cli.c b/src/cli.c
index 5af4804..1b440b4 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -454,7 +454,7 @@
 	init_new_proxy(fe);
 	fe->next = proxies_list;
 	proxies_list = fe;
-	fe->last_change = now.tv_sec;
+	fe->last_change = ns_to_sec(tv_to_ns(&now));
 	fe->id = strdup("GLOBAL");
 	fe->cap = PR_CAP_FE|PR_CAP_INT;
 	fe->maxconn = 10;                 /* default to 10 concurrent connections */
diff --git a/src/flt_spoe.c b/src/flt_spoe.c
index 71c10a9..b53f654 100644
--- a/src/flt_spoe.c
+++ b/src/flt_spoe.c
@@ -3019,7 +3019,7 @@
 
 	/* conf->agent_fe was already initialized during the config
 	 * parsing. Finish initialization. */
-        conf->agent_fe.last_change = now.tv_sec;
+        conf->agent_fe.last_change = ns_to_sec(tv_to_ns(&now));
         conf->agent_fe.cap = PR_CAP_FE;
         conf->agent_fe.mode = PR_MODE_TCP;
         conf->agent_fe.maxconn = 0;
diff --git a/src/log.c b/src/log.c
index 60c7daa..82a4fa2 100644
--- a/src/log.c
+++ b/src/log.c
@@ -3760,7 +3760,7 @@
 		px->conf.file = strdup(file);
 		px->conf.line = linenum;
 		px->mode = PR_MODE_SYSLOG;
-		px->last_change = now.tv_sec;
+		px->last_change = ns_to_sec(tv_to_ns(&now));
 		px->cap = PR_CAP_FE;
 		px->maxconn = 10;
 		px->timeout.client = TICK_ETERNITY;
diff --git a/src/mworker-prog.c b/src/mworker-prog.c
index 502c549..1909d4a 100644
--- a/src/mworker-prog.c
+++ b/src/mworker-prog.c
@@ -79,7 +79,7 @@
 				continue;
 			}
 
-			child->timestamp = now.tv_sec;
+			child->timestamp = ns_to_sec(tv_to_ns(&now));
 
 			ret = fork();
 			if (ret < 0) {
diff --git a/src/peers.c b/src/peers.c
index 725f704..f9c3ed8 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -3247,7 +3247,7 @@
 /* Pre-configures a peers frontend to accept incoming connections */
 void peers_setup_frontend(struct proxy *fe)
 {
-	fe->last_change = now.tv_sec;
+	fe->last_change = ns_to_sec(tv_to_ns(&now));
 	fe->cap = PR_CAP_FE | PR_CAP_BE;
 	fe->mode = PR_MODE_PEERS;
 	fe->maxconn = 0;
diff --git a/src/proxy.c b/src/proxy.c
index f2eb6a8..3a3bb30 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -1650,7 +1650,7 @@
 	}
 
 	init_new_proxy(curproxy);
-	curproxy->last_change = now.tv_sec;
+	curproxy->last_change = ns_to_sec(tv_to_ns(&now));
 	curproxy->id = strdup(name);
 	curproxy->cap = cap;
 
@@ -2839,7 +2839,7 @@
 		dump_server_addr(&srv->check.addr, srv_check_addr);
 		dump_server_addr(&srv->agent.addr, srv_agent_addr);
 
-		srv_time_since_last_change = now.tv_sec - srv->last_change;
+		srv_time_since_last_change = ns_to_sec(tv_to_ns(&now)) - srv->last_change;
 		bk_f_forced_id = px->options & PR_O_FORCED_ID ? 1 : 0;
 		srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0;
 
diff --git a/src/queue.c b/src/queue.c
index 73bd3c2..f6044c5 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -114,10 +114,10 @@
 		       s->proxy->beconn * s->maxconn / s->proxy->fullconn);
 
 	if ((s->cur_state == SRV_ST_STARTING) &&
-	    now.tv_sec < s->last_change + s->slowstart &&
-	    now.tv_sec >= s->last_change) {
+	    ns_to_sec(tv_to_ns(&now)) < s->last_change + s->slowstart &&
+	    ns_to_sec(tv_to_ns(&now)) >= s->last_change) {
 		unsigned int ratio;
-		ratio = 100 * (now.tv_sec - s->last_change) / s->slowstart;
+		ratio = 100 * (ns_to_sec(tv_to_ns(&now)) - s->last_change) / s->slowstart;
 		max = MAX(1, max * ratio / 100);
 	}
 	return max;
diff --git a/src/resolvers.c b/src/resolvers.c
index ac0b015..443a688 100644
--- a/src/resolvers.c
+++ b/src/resolvers.c
@@ -3234,7 +3234,7 @@
 
 void resolvers_setup_proxy(struct proxy *px)
 {
-	px->last_change = now.tv_sec;
+	px->last_change = ns_to_sec(tv_to_ns(&now));
 	px->cap = PR_CAP_FE | PR_CAP_BE;
 	px->maxconn = 0;
 	px->conn_retries = 1;
diff --git a/src/server.c b/src/server.c
index 8172f8f..f8162b1 100644
--- a/src/server.c
+++ b/src/server.c
@@ -138,16 +138,16 @@
 
 int srv_downtime(const struct server *s)
 {
-	if ((s->cur_state != SRV_ST_STOPPED) || s->last_change >= now.tv_sec)		// ignore negative time
+	if ((s->cur_state != SRV_ST_STOPPED) || s->last_change >= ns_to_sec(tv_to_ns(&now)))		// ignore negative time
 		return s->down_time;
 
-	return now.tv_sec - s->last_change + s->down_time;
+	return ns_to_sec(tv_to_ns(&now)) - s->last_change + s->down_time;
 }
 
 int srv_lastsession(const struct server *s)
 {
 	if (s->counters.last_sess)
-		return now.tv_sec - s->counters.last_sess;
+		return ns_to_sec(tv_to_ns(&now)) - s->counters.last_sess;
 
 	return -1;
 }
@@ -1867,7 +1867,7 @@
 	struct proxy *px = sv->proxy;
 	unsigned w;
 
-	if (now.tv_sec < sv->last_change || now.tv_sec >= sv->last_change + sv->slowstart) {
+	if (ns_to_sec(tv_to_ns(&now)) < sv->last_change || ns_to_sec(tv_to_ns(&now)) >= sv->last_change + sv->slowstart) {
 		/* go to full throttle if the slowstart interval is reached */
 		if (sv->next_state == SRV_ST_STARTING)
 			sv->next_state = SRV_ST_RUNNING;
@@ -1877,7 +1877,7 @@
 	 * It must also start immediately, at least at the minimal step when leaving maintenance.
 	 */
 	if ((sv->next_state == SRV_ST_STARTING) && (px->lbprm.algo & BE_LB_PROP_DYN))
-		w = (px->lbprm.wdiv * (now.tv_sec - sv->last_change) + sv->slowstart) / sv->slowstart;
+		w = (px->lbprm.wdiv * (ns_to_sec(tv_to_ns(&now)) - sv->last_change) + sv->slowstart) / sv->slowstart;
 	else
 		w = px->lbprm.wdiv;
 
@@ -2358,7 +2358,7 @@
 	event_hdl_sub_list_init(&srv->e_subs);
 
 	srv->next_state = SRV_ST_RUNNING; /* early server setup */
-	srv->last_change = now.tv_sec;
+	srv->last_change = ns_to_sec(tv_to_ns(&now));
 
 	srv->check.obj_type = OBJ_TYPE_CHECK;
 	srv->check.status = HCHK_STATUS_INI;
@@ -4685,7 +4685,7 @@
 		if (srv->next_state == SRV_ST_STARTING) {
 			task_schedule(srv->warmup,
 			              tick_add(now_ms,
-			                       MS_TO_TICKS(MAX(1000, (now.tv_sec - srv->last_change)) / 20)));
+			                       MS_TO_TICKS(MAX(1000, (ns_to_sec(tv_to_ns(&now)) - srv->last_change)) / 20)));
 		}
 	}
 
@@ -5752,14 +5752,14 @@
 	if (srv_prev_state != s->cur_state) {
 		if (srv_prev_state == SRV_ST_STOPPED) {
 			/* server was down and no longer is */
-			if (s->last_change < now.tv_sec)                        // ignore negative times
-				s->down_time += now.tv_sec - s->last_change;
+			if (s->last_change < ns_to_sec(tv_to_ns(&now)))                        // ignore negative times
+				s->down_time += ns_to_sec(tv_to_ns(&now)) - s->last_change;
 		}
 		else if (s->cur_state == SRV_ST_STOPPED) {
 			/* server was up and is currently down */
 			s->counters.down_trans++;
 		}
-		s->last_change = now.tv_sec;
+		s->last_change = ns_to_sec(tv_to_ns(&now));
 	}
 
 	/* check if backend stats must be updated due to the server state change */
@@ -5769,9 +5769,9 @@
 		/* backend was down and is back up again:
 		 * no helper function, updating last_change and backend downtime stats
 		 */
-		if (s->proxy->last_change < now.tv_sec)         // ignore negative times
-			s->proxy->down_time += now.tv_sec - s->proxy->last_change;
-		s->proxy->last_change = now.tv_sec;
+		if (s->proxy->last_change < ns_to_sec(tv_to_ns(&now)))         // ignore negative times
+			s->proxy->down_time += ns_to_sec(tv_to_ns(&now)) - s->proxy->last_change;
+		s->proxy->last_change = ns_to_sec(tv_to_ns(&now));
 	}
 }
 
diff --git a/src/server_state.c b/src/server_state.c
index 677de88..da5b102 100644
--- a/src/server_state.c
+++ b/src/server_state.c
@@ -321,7 +321,7 @@
 			srv_adm_set_drain(srv);
 	}
 
-	srv->last_change = now.tv_sec - srv_last_time_change;
+	srv->last_change = ns_to_sec(tv_to_ns(&now)) - srv_last_time_change;
 	srv->check.status = srv_check_status;
 	srv->check.result = srv_check_result;
 
diff --git a/src/sink.c b/src/sink.c
index af0e891..b10ea2b 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -289,7 +289,7 @@
 /* Pre-configures a ring proxy to emit connections */
 void sink_setup_proxy(struct proxy *px)
 {
-	px->last_change = now.tv_sec;
+	px->last_change = ns_to_sec(tv_to_ns(&now));
 	px->cap = PR_CAP_BE;
 	px->maxconn = 0;
 	px->conn_retries = 1;
diff --git a/src/stats.c b/src/stats.c
index d673cee..9979c7b 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -2345,7 +2345,7 @@
 				metric = mkf_str(FO_STATUS, fld_status);
 				break;
 			case ST_F_LASTCHG:
-				metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
+				metric = mkf_u32(FN_AGE, ns_to_sec(tv_to_ns(&now)) - sv->last_change);
 				break;
 			case ST_F_WEIGHT:
 				metric = mkf_u32(FN_AVG, (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv);
@@ -2800,7 +2800,7 @@
 				metric = mkf_u64(FN_COUNTER, px->down_trans);
 				break;
 			case ST_F_LASTCHG:
-				metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
+				metric = mkf_u32(FN_AGE, ns_to_sec(tv_to_ns(&now)) - px->last_change);
 				break;
 			case ST_F_DOWNTIME:
 				if (px->srv)
@@ -3555,7 +3555,7 @@
 {
 	struct appctx *appctx = __sc_appctx(sc);
 	struct show_stat_ctx *ctx = appctx->svcctx;
-	unsigned int up = (now.tv_sec - start_time.tv_sec);
+	unsigned int up = (ns_to_sec(tv_to_ns(&now)) - start_time.tv_sec);
 	char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
 	const char *scope_ptr = stats_scope_ptr(appctx, sc);
 	unsigned long long bps;
diff --git a/src/stream.c b/src/stream.c
index 82a06ed..4e0ece3 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -3372,7 +3372,7 @@
 
 		chunk_appendf(&trash,
 			     " age=%s)\n",
-			     human_time(now.tv_sec - strm->logs.accept_date.tv_sec, 1));
+			     human_time(ns_to_sec(tv_to_ns(&now)) - strm->logs.accept_date.tv_sec, 1));
 
 		if (strm->txn)
 			chunk_appendf(&trash,
@@ -3699,7 +3699,7 @@
 		chunk_appendf(&trash,
 			     " ts=%02x epoch=%#x age=%s calls=%u rate=%u cpu=%llu lat=%llu",
 		             curr_strm->task->state, curr_strm->stream_epoch,
-		             human_time(now.tv_sec - ns_to_sec(curr_strm->logs.accept_ts), 1),
+		             human_time(ns_to_sec(tv_to_ns(&now)) - ns_to_sec(curr_strm->logs.accept_ts), 1),
 		             curr_strm->task->calls, read_freq_ctr(&curr_strm->call_rate),
 		             (unsigned long long)curr_strm->cpu_time, (unsigned long long)curr_strm->lat_time);