lib: keep timestamp in easy handle

Use `data->progress.now` as the timestamp of proecssing a transfer.
Update it on significant events and refrain from calling `curlx_now()`
in many places.

The problem this addresses is
a) calling curlx_now() has costs, depending on platform. Calling it
   every time results in 25% increase `./runtest` duration on macOS.
b) we used to pass a `struct curltime *` around to save on calls, but
   when some method directly use `curx_now()` and some use the passed
   pointer, the transfer experienes non-linear time. This results in
   timeline checks to report events in the wrong order.

By keeping a timestamp in the easy handle and updating it there, no
longer invoking `curlx_now()` in the "lower" methods, the transfer
can observer a steady clock progression.

Add documentation in docs/internals/TIME-KEEPING.md

Reported-by: Viktor Szakats
Fixes #19935
Closes #19961
This commit is contained in:
Stefan Eissing 2025-12-15 14:28:09 +01:00 committed by Daniel Stenberg
parent 425a2aa1af
commit 2de22a00c7
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
67 changed files with 598 additions and 458 deletions

View file

@ -2500,7 +2500,7 @@ static CURLcode myssh_block_statemach(struct Curl_easy *data,
if(result)
break;
left_ms = Curl_timeleft_ms(data, NULL, FALSE);
left_ms = Curl_timeleft_ms(data, FALSE);
if(left_ms < 0) {
failf(data, "Operation timed out");
return CURLE_OPERATION_TIMEDOUT;

View file

@ -3121,13 +3121,13 @@ static CURLcode ssh_block_statemach(struct Curl_easy *data,
bool disconnect)
{
CURLcode result = CURLE_OK;
struct curltime dis = curlx_now();
struct curltime start = data->progress.now;
while((sshc->state != SSH_STOP) && !result) {
bool block;
timediff_t left_ms = 1000;
struct curltime now = curlx_now();
Curl_pgrs_now_set(data); /* timeout disconnect */
result = ssh_statemachine(data, sshc, sshp, &block);
if(result)
break;
@ -3137,13 +3137,13 @@ static CURLcode ssh_block_statemach(struct Curl_easy *data,
if(result)
break;
left_ms = Curl_timeleft_ms(data, NULL, FALSE);
left_ms = Curl_timeleft_ms(data, FALSE);
if(left_ms < 0) {
failf(data, "Operation timed out");
return CURLE_OPERATION_TIMEDOUT;
}
}
else if(curlx_timediff_ms(now, dis) > 1000) {
else if(curlx_timediff_ms(data->progress.now, start) > 1000) {
/* disconnect timeout */
failf(data, "Disconnect timed out");
result = CURLE_OK;