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.
This commit is contained in:
Willy Tarreau 2023-04-27 09:21:20 +02:00
parent 591fa59da7
commit 76d343d3d3
11 changed files with 22 additions and 22 deletions

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

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

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

View File

@ -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 */

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

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

View File

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

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

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

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

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