mirror of
https://passt.top/passt
synced 2025-06-07 16:35:33 +02:00
util: Some corrections for timespec_diff_us
The comment for timespec_diff_us() claims it will wrap after 2^64µs. This is incorrect for two reasons: * It returns a long long, which is probably 64-bits, but might not be * It returns a signed value, so even if it is 64 bits it will wrap after 2^63µs Correct the comment and use an explicitly 64-bit type to avoid that imprecision. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
fbb0c9523e
commit
95569e4aa4
2 changed files with 3 additions and 3 deletions
4
util.c
4
util.c
|
@ -244,9 +244,9 @@ void sock_probe_mem(struct ctx *c)
|
|||
* @a: Minuend timestamp
|
||||
* @b: Subtrahend timestamp
|
||||
*
|
||||
* Return: difference in microseconds (wraps after 2^64 / 10^6s ~= 585k years)
|
||||
* Return: difference in microseconds (wraps after 2^63 / 10^6s ~= 292k years)
|
||||
*/
|
||||
long long timespec_diff_us(const struct timespec *a, const struct timespec *b)
|
||||
int64_t timespec_diff_us(const struct timespec *a, const struct timespec *b)
|
||||
{
|
||||
if (a->tv_nsec < b->tv_nsec) {
|
||||
return (b->tv_nsec - a->tv_nsec) / 1000 +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue