time-keeping: keep timestamp in multi, always update

Always use curlx_now() when calling Curl_pgrs_now(data). Tests with the
"manual" updates to now proved differ more then 100ms in parallel testing.

Add `curlx_nowp()` to set current time into a struct curltime.
Add `curlx_ptimediff_ms() and friends, passing pointers.

Update documentation.

Closes #19998
This commit is contained in:
Stefan Eissing 2025-12-18 13:55:07 +01:00 committed by Daniel Stenberg
parent 308c347c8b
commit b4be1f271e
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
61 changed files with 471 additions and 502 deletions

View file

@ -35,6 +35,7 @@
#include "multiif.h"
#include "cf-https-connect.h"
#include "http2.h"
#include "progress.h"
#include "select.h"
#include "vquic/vquic.h"
@ -149,7 +150,7 @@ static void cf_hc_baller_init(struct cf_hc_baller *b,
struct Curl_cfilter *save = cf->next;
cf->next = NULL;
b->started = data->progress.now;
b->started = *Curl_pgrs_now(data);
switch(b->alpn_id) {
case ALPN_h3:
transport = TRNSPRT_QUIC;
@ -212,12 +213,12 @@ static CURLcode baller_connected(struct Curl_cfilter *cf,
if(reply_ms >= 0)
CURL_TRC_CF(data, cf, "connect+handshake %s: %dms, 1st data: %dms",
winner->name,
(int)curlx_timediff_ms(data->progress.now,
winner->started), reply_ms);
(int)curlx_ptimediff_ms(Curl_pgrs_now(data),
&winner->started), reply_ms);
else
CURL_TRC_CF(data, cf, "deferred handshake %s: %dms",
winner->name, (int)curlx_timediff_ms(data->progress.now,
winner->started));
winner->name, (int)curlx_ptimediff_ms(Curl_pgrs_now(data),
&winner->started));
/* install the winning filter below this one. */
cf->next = winner->cf;
@ -265,7 +266,7 @@ static bool time_to_start_next(struct Curl_cfilter *cf,
ctx->ballers[idx].name);
return TRUE;
}
elapsed_ms = curlx_timediff_ms(now, ctx->started);
elapsed_ms = curlx_ptimediff_ms(&now, &ctx->started);
if(elapsed_ms >= ctx->hard_eyeballs_timeout_ms) {
CURL_TRC_CF(data, cf, "hard timeout of %" FMT_TIMEDIFF_T "ms reached, "
"starting %s",
@ -308,7 +309,7 @@ static CURLcode cf_hc_connect(struct Curl_cfilter *cf,
for(i = 0; i < ctx->baller_count; i++)
DEBUGASSERT(!ctx->ballers[i].cf);
CURL_TRC_CF(data, cf, "connect, init");
ctx->started = data->progress.now;
ctx->started = *Curl_pgrs_now(data);
cf_hc_baller_init(&ctx->ballers[0], cf, data, ctx->ballers[0].transport);
if(ctx->baller_count > 1) {
Curl_expire(data, ctx->soft_eyeballs_timeout_ms, EXPIRE_ALPN_EYEBALLS);
@ -327,7 +328,7 @@ static CURLcode cf_hc_connect(struct Curl_cfilter *cf,
}
}
if(time_to_start_next(cf, data, 1, data->progress.now)) {
if(time_to_start_next(cf, data, 1, *Curl_pgrs_now(data))) {
cf_hc_baller_init(&ctx->ballers[1], cf, data, ctx->ballers[1].transport);
}
@ -468,7 +469,7 @@ static struct curltime cf_get_max_baller_time(struct Curl_cfilter *cf,
struct Curl_cfilter *cfb = ctx->ballers[i].cf;
memset(&t, 0, sizeof(t));
if(cfb && !cfb->cft->query(cfb, data, query, NULL, &t)) {
if((t.tv_sec || t.tv_usec) && curlx_timediff_us(t, tmax) > 0)
if((t.tv_sec || t.tv_usec) && curlx_ptimediff_us(&t, &tmax) > 0)
tmax = t;
}
}