]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: time: replace calls to tv_ms_elapsed() with a linear subtract
authorWilly Tarreau <w@1wt.eu>
Thu, 27 Apr 2023 07:21:20 +0000 (09:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 28 Apr 2023 14:08:08 +0000 (16:08 +0200)
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.

include/haproxy/mux_quic.h
src/backend.c
src/check.c
src/cli.c
src/flt_spoe.c
src/http_ana.c
src/log.c
src/mux_h1.c
src/mux_h2.c
src/session.c
src/stream.c

index 44862317bcd6d054fbf47e1e71a516eda4a63ec4..ac87aee8cda7c03a937de11f9e16e34ceb4f3026 100644 (file)
@@ -101,7 +101,7 @@ static inline struct stconn *qc_attach_sc(struct qcs *qcs, struct buffer *buf)
        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;
index ac89c38205f6c037d3a0fce457ebd6c60e6f76da..085bb1bf759eef506beb94c21fe089a2e07eadec 100644 (file)
@@ -2024,7 +2024,7 @@ void back_try_conn_req(struct stream *s)
                        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 @@ void back_try_conn_req(struct stream *s)
                        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 @@ void back_try_conn_req(struct stream *s)
                        /* ... 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 @@ void back_try_conn_req(struct stream *s)
 
                /* 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 @@ void back_handle_st_req(struct stream *s)
        }
 
        /* 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 @@ void back_handle_st_rdy(struct stream *s)
 
                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);
        }
 
index e7590020fe071aacb95090db97f5e5ff5871cca7..a8aeb9a15f49a80afb4647ce743cab5a8ca9b0e7 100644 (file)
@@ -492,7 +492,7 @@ void set_server_check_status(struct check *check, short status, const char *desc
                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);
        }
 
index caa837e427bbbbc14163fd41e74dd33decdd5a67..412cbfb292268b7afa9683b670ecea3b09c1c444 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -2626,7 +2626,7 @@ read_again:
 
        /* 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 @@ int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
                                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 */
index 1f88ab0a3e4762562ee15e44eda8ea3cb6c3adea..2c43e12c57a547b903326b6e93e5ff069d325b51 100644 (file)
@@ -264,9 +264,9 @@ static inline void
 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);
 }
 
index c16cfc3ee2d13a683ea9af69733c0176859aa06f..d97d4424721a423ac3631090faff354304021148 100644 (file)
@@ -782,7 +782,7 @@ int http_process_tarpit(struct stream *s, struct channel *req, int an_bit)
         * 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 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
 
   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;
index 8af8a494892ba8463df2932f0d544c8986fb01ca..175aea09ad94a128e9fae586b87e61115071fac3 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -2018,7 +2018,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
                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 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
 
        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;
 
index a3f7fc0959ea0d81b24690d410ebabf7c3edb4c0..9a986504c6e4ad178c205cc0749e37d2560ae6c9 100644 (file)
@@ -3017,7 +3017,7 @@ static int h1_process(struct h1c * h1c)
                }
 
                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);
index 08e9e8a4c602600bb72bf1c7b4b522f99cc93d70..41246793771894e2f014dfae0ffa68abc96303ae 100644 (file)
@@ -1573,7 +1573,7 @@ static struct h2s *h2c_frt_stream_new(struct h2c *h2c, int id, struct buffer *in
         * 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;
index c53141d9eb4cb38e576bde7943c084ffc6341403..382bef003889f8e97a1fe3818a2d66feca8c0fe3 100644 (file)
@@ -432,7 +432,7 @@ int conn_complete_session(struct connection *conn)
 {
        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;
index 058e43b8a025034b0040231498b0379ff832e478..94a429a985a6812bbfa05e095d08094b7860449a 100644 (file)
@@ -902,7 +902,7 @@ static void back_establish(struct stream *s)
        /* 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 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
        }
 
        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 @@ void stream_update_time_stats(struct stream *s)
                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;