MINOR: time: replace calls to tv_ms_elapsed() with a linear subtract

Instead of operating on {sec, usec} now we convert both operands to
ns then subtract them and convert to ms. This is a first step towards
dropping timeval from these timestamps.

Interestingly, tv_ms_elapsed() and tv_ms_remain() are no longer used at
all and could be removed.
diff --git a/include/haproxy/mux_quic.h b/include/haproxy/mux_quic.h
index 4486231..ac87aee 100644
--- a/include/haproxy/mux_quic.h
+++ b/include/haproxy/mux_quic.h
@@ -101,7 +101,7 @@
 	se_expect_no_data(qcs->sd);
 
 	/* TODO duplicated from mux_h2 */
-	sess->t_idle = tv_ms_elapsed(&sess->tv_accept, &now) - sess->t_handshake;
+	sess->t_idle = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&sess->tv_accept)) - sess->t_handshake;
 
 	if (!sc_new_from_endp(qcs->sd, sess, buf))
 		return NULL;
diff --git a/src/backend.c b/src/backend.c
index ac89c38..085bb1b 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -2024,7 +2024,7 @@
 			sc_shutdown(sc);
 			sc->flags |= SC_FL_ERROR;
 
-			s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
+			s->logs.t_queue = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&s->logs.tv_accept));
 
 			/* we may need to know the position in the queue for logging */
 			pendconn_cond_unlink(s->pend_pos);
@@ -2060,7 +2060,7 @@
 			if (unlikely(!(s->flags & SF_ASSIGNED)))
 				sc->state = SC_ST_REQ;
 			else {
-				s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
+				s->logs.t_queue = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&s->logs.tv_accept));
 				sc->state = SC_ST_ASS;
 			}
 			DBG_TRACE_STATE("dequeue connection request", STRM_EV_STRM_PROC|STRM_EV_CS_ST, s);
@@ -2072,7 +2072,7 @@
 			/* ... and timeout expired */
 			s->conn_exp = TICK_ETERNITY;
 			s->flags &= ~SF_CONN_EXP;
-			s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
+			s->logs.t_queue = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&s->logs.tv_accept));
 
 			/* we may need to know the position in the queue for logging */
 			pendconn_cond_unlink(s->pend_pos);
@@ -2094,7 +2094,7 @@
 
 		/* Connection remains in queue, check if we have to abort it */
 		if (back_may_abort_req(req, s)) {
-			s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
+			s->logs.t_queue = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&s->logs.tv_accept));
 
 			/* we may need to know the position in the queue for logging */
 			pendconn_cond_unlink(s->pend_pos);
@@ -2219,7 +2219,7 @@
 	}
 
 	/* The server is assigned */
-	s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
+	s->logs.t_queue = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&s->logs.tv_accept));
 	sc->state = SC_ST_ASS;
 	be_set_sess_last(s->be);
 	DBG_TRACE_STATE("connection request assigned to a server", STRM_EV_STRM_PROC|STRM_EV_CS_ST, s);
@@ -2442,7 +2442,7 @@
 
 		if (tv_iszero(&s->logs.tv_request))
 			s->logs.tv_request = now;
-		s->logs.t_queue   = tv_ms_elapsed(&s->logs.tv_accept, &now);
+		s->logs.t_queue = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&s->logs.tv_accept));
 		be_set_sess_last(s->be);
 	}
 
diff --git a/src/check.c b/src/check.c
index e759002..a8aeb9a 100644
--- a/src/check.c
+++ b/src/check.c
@@ -492,7 +492,7 @@
 		check->duration = -1;
 	else if (!tv_iszero(&check->start)) {
 		/* set_server_check_status() may be called more than once */
-		check->duration = tv_ms_elapsed(&check->start, &now);
+		check->duration = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&check->start));
 		tv_zero(&check->start);
 	}
 
diff --git a/src/cli.c b/src/cli.c
index caa837e..412cbfb 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -2626,7 +2626,7 @@
 
 	/* If there is data available for analysis, log the end of the idle time. */
 	if (c_data(req) && s->logs.t_idle == -1)
-		s->logs.t_idle = tv_ms_elapsed(&s->logs.tv_accept, &now) - s->logs.t_handshake;
+		s->logs.t_idle = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&s->logs.tv_accept)) - s->logs.t_handshake;
 
 	to_forward = pcli_parse_request(s, req, &errmsg, &next_pid);
 	if (to_forward > 0) {
@@ -2762,7 +2762,7 @@
 				sess_change_server(s, NULL);
 		}
 
-		s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);
+		s->logs.t_close = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&s->logs.tv_accept));
 		stream_process_counters(s);
 
 		/* don't count other requests' data */
diff --git a/src/flt_spoe.c b/src/flt_spoe.c
index 1f88ab0..2c43e12 100644
--- a/src/flt_spoe.c
+++ b/src/flt_spoe.c
@@ -264,9 +264,9 @@
 spoe_update_stat_time(struct timeval *tv, long *t)
 {
 	if (*t == -1)
-		*t = tv_ms_elapsed(tv, &now);
+		*t = ns_to_ms(tv_to_ns(&now) - tv_to_ns(tv));
 	else
-		*t += tv_ms_elapsed(tv, &now);
+		*t += ns_to_ms(tv_to_ns(&now) - tv_to_ns(tv));
 	tv_zero(tv);
 }
 
diff --git a/src/http_ana.c b/src/http_ana.c
index c16cfc3..d97d442 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -782,7 +782,7 @@
 	 * It will not cause trouble to the logs because we can exclude
 	 * the tarpitted connections by filtering on the 'PT' status flags.
 	 */
-	s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
+	s->logs.t_queue = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&s->logs.tv_accept));
 
 	http_reply_and_close(s, txn->status, (!(s->scf->flags & SC_FL_ERROR) ? http_error_message(s) : NULL));
 	http_set_term_flags(s);
@@ -1585,7 +1585,7 @@
 
   end:
 	/* we want to have the response time before we start processing it */
-	s->logs.t_data = tv_ms_elapsed(&s->logs.tv_accept, &now);
+	s->logs.t_data = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&s->logs.tv_accept));
 
 	/* end of job, return OK */
 	rep->analysers &= ~an_bit;
diff --git a/src/log.c b/src/log.c
index 8af8a49..175aea0 100644
--- a/src/log.c
+++ b/src/log.c
@@ -2018,7 +2018,7 @@
 		tmp_strm_log.t_queue = -1;
 		tmp_strm_log.t_connect = -1;
 		tmp_strm_log.t_data = -1;
-		tmp_strm_log.t_close = tv_ms_elapsed(&sess->tv_accept, &now);
+		tmp_strm_log.t_close = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&sess->tv_accept));
 		tmp_strm_log.bytes_in = 0;
 		tmp_strm_log.bytes_out = 0;
 		tmp_strm_log.prx_queue_pos = 0;
@@ -2059,7 +2059,7 @@
 
 	t_request = -1;
 	if (tv_isge(&logs->tv_request, &logs->tv_accept))
-		t_request = tv_ms_elapsed(&logs->tv_accept, &logs->tv_request);
+		t_request = ns_to_ms(tv_to_ns(&logs->tv_request) - tv_to_ns(&logs->tv_accept));
 
 	tmplog = dst;
 
diff --git a/src/mux_h1.c b/src/mux_h1.c
index a3f7fc0..9a98650 100644
--- a/src/mux_h1.c
+++ b/src/mux_h1.c
@@ -3017,7 +3017,7 @@
 		}
 
 		if (h1s->sess->t_idle == -1)
-			h1s->sess->t_idle = tv_ms_elapsed(&h1s->sess->tv_accept, &now) - h1s->sess->t_handshake;
+			h1s->sess->t_idle = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&h1s->sess->tv_accept)) - h1s->sess->t_handshake;
 
 		/* Get the stream rxbuf */
 		buf = h1_get_buf(h1c, &h1s->rxbuf);
diff --git a/src/mux_h2.c b/src/mux_h2.c
index 08e9e8a..4124679 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -1573,7 +1573,7 @@
 	 * request) and the idle time, which is the delay since the previous
 	 * request. We can set the value now, it will be copied by stream_new().
 	 */
-	sess->t_idle = tv_ms_elapsed(&sess->tv_accept, &now) - sess->t_handshake;
+	sess->t_idle = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&sess->tv_accept)) - sess->t_handshake;
 
 	if (!sc_new_from_endp(h2s->sd, sess, input))
 		goto out_close;
diff --git a/src/session.c b/src/session.c
index c53141d..382bef0 100644
--- a/src/session.c
+++ b/src/session.c
@@ -432,7 +432,7 @@
 {
 	struct session *sess = conn->owner;
 
-	sess->t_handshake = tv_ms_elapsed(&sess->tv_accept, &now);
+	sess->t_handshake = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&sess->tv_accept));
 
 	if (conn->flags & CO_FL_ERROR)
 		goto fail;
diff --git a/src/stream.c b/src/stream.c
index 058e43b..94a429a 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -902,7 +902,7 @@
 	/* First, centralize the timers information, and clear any irrelevant
 	 * timeout.
 	 */
-	s->logs.t_connect = tv_ms_elapsed(&s->logs.tv_accept, &now);
+	s->logs.t_connect = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&s->logs.tv_accept));
 	s->conn_exp = TICK_ETERNITY;
 	s->flags &= ~SF_CONN_EXP;
 
@@ -2595,7 +2595,7 @@
 	}
 
 	if (!(s->flags & SF_IGNORE)) {
-		s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);
+		s->logs.t_close = ns_to_ms(tv_to_ns(&now) - tv_to_ns(&s->logs.tv_accept));
 
 		stream_process_counters(s);
 
@@ -2661,7 +2661,7 @@
 		return;
 
 	if (tv_isge(&s->logs.tv_request, &s->logs.tv_accept))
-		t_request = tv_ms_elapsed(&s->logs.tv_accept, &s->logs.tv_request);
+		t_request = ns_to_ms(tv_to_ns(&s->logs.tv_request) - tv_to_ns(&s->logs.tv_accept));
 
 	t_data    -= t_connect;
 	t_connect -= t_queue;