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

@ -1325,11 +1325,8 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done)
timediff_t interval_ms;
struct pollfd pfd[2];
int poll_cnt;
curl_off_t total_dl = 0;
curl_off_t total_ul = 0;
ssize_t snread;
#endif
struct curltime now;
bool keepon = TRUE;
char buffer[4 * 1024];
struct TELNET *tn;
@ -1511,8 +1508,9 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done)
} /* switch */
if(data->set.timeout) {
now = curlx_now();
if(curlx_timediff_ms(now, conn->created) >= data->set.timeout) {
Curl_pgrs_now_set(data);
if(curlx_timediff_ms(data->progress.now, conn->created) >=
data->set.timeout) {
failf(data, "Time-out");
result = CURLE_OPERATION_TIMEDOUT;
keepon = FALSE;
@ -1581,8 +1579,7 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done)
break;
}
total_dl += nread;
Curl_pgrsSetDownloadCounter(data, total_dl);
Curl_pgrs_download_inc(data, nread);
result = telrcv(data, tn, (unsigned char *)buffer, nread);
if(result) {
keepon = FALSE;
@ -1622,8 +1619,7 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done)
keepon = FALSE;
break;
}
total_ul += snread;
Curl_pgrsSetUploadCounter(data, total_ul);
Curl_pgrs_upload_inc(data, (size_t)snread);
}
else if(snread < 0)
keepon = FALSE;
@ -1632,8 +1628,9 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done)
} /* poll switch statement */
if(data->set.timeout) {
now = curlx_now();
if(curlx_timediff_ms(now, conn->created) >= data->set.timeout) {
Curl_pgrs_now_set(data);
if(curlx_timediff_ms(data->progress.now, conn->created) >=
data->set.timeout) {
failf(data, "Time-out");
result = CURLE_OPERATION_TIMEDOUT;
keepon = FALSE;