From 76d343d3d371fb89053598db79e1f7a3e8c8a750 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 27 Apr 2023 09:21:20 +0200 Subject: [PATCH] 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. --- include/haproxy/mux_quic.h | 2 +- src/backend.c | 12 ++++++------ src/check.c | 2 +- src/cli.c | 4 ++-- src/flt_spoe.c | 4 ++-- src/http_ana.c | 4 ++-- src/log.c | 4 ++-- src/mux_h1.c | 2 +- src/mux_h2.c | 2 +- src/session.c | 2 +- src/stream.c | 6 +++--- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/haproxy/mux_quic.h b/include/haproxy/mux_quic.h index 44862317b..ac87aee8c 100644 --- a/include/haproxy/mux_quic.h +++ b/include/haproxy/mux_quic.h @@ -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; diff --git a/src/backend.c b/src/backend.c index ac89c3820..085bb1bf7 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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); } diff --git a/src/check.c b/src/check.c index e7590020f..a8aeb9a15 100644 --- a/src/check.c +++ b/src/check.c @@ -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); } diff --git a/src/cli.c b/src/cli.c index caa837e42..412cbfb29 100644 --- 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 */ diff --git a/src/flt_spoe.c b/src/flt_spoe.c index 1f88ab0a3..2c43e12c5 100644 --- a/src/flt_spoe.c +++ b/src/flt_spoe.c @@ -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); } diff --git a/src/http_ana.c b/src/http_ana.c index c16cfc3ee..d97d44247 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -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; diff --git a/src/log.c b/src/log.c index 8af8a4948..175aea09a 100644 --- 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; diff --git a/src/mux_h1.c b/src/mux_h1.c index a3f7fc095..9a986504c 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -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); diff --git a/src/mux_h2.c b/src/mux_h2.c index 08e9e8a4c..412467937 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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; diff --git a/src/session.c b/src/session.c index c53141d9e..382bef003 100644 --- a/src/session.c +++ b/src/session.c @@ -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; diff --git a/src/stream.c b/src/stream.c index 058e43b8a..94a429a98 100644 --- a/src/stream.c +++ b/src/stream.c @@ -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;