public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* bug fix for hp-timing.h (aarch64)
@ 2023-01-11 22:49 Wilco Dijkstra
  2023-01-12 14:38 ` Tang, Jun
  2023-01-12 15:11 ` Zack Weinberg
  0 siblings, 2 replies; 13+ messages in thread
From: Wilco Dijkstra @ 2023-01-11 22:49 UTC (permalink / raw)
  To: zack, juntangc; +Cc: 'GNU C Library'

Hi Zack,

> -   (Diff) = ((End) - (Start)) * (UINT64_C(1000000000) / freq); \
> +   (Diff) = (((End) - (Start)) * UINT64_C(1000000000)) / freq; \
>
> This avoids using floating-point arithmetic but should still do the rescale correctly.
> (The multiplier and divisor are both guaranteed to be less than 2**32, so, as long
> as we do the multiplication in 64-bit arithmetic, we cannot lose bits via overflow.)

However this will overflow after about 16 seconds - and that's short even for basic
benchmarking. Since this code is not performance critical, using floating point here
is reasonable.

Cheers,
Wilco

^ permalink raw reply	[flat|nested] 13+ messages in thread
* bug fix for hp-timing.h (aarch64)
@ 2023-01-11 16:44 Tang, Jun
  2023-01-11 17:22 ` Zack Weinberg
  0 siblings, 1 reply; 13+ messages in thread
From: Tang, Jun @ 2023-01-11 16:44 UTC (permalink / raw)
  To: libc-alpha; +Cc: Pop, Sebastian

[-- Attachment #1: Type: text/plain, Size: 909 bytes --]

On Graviton 3 the frequency is 1050000000 and the original function hp-timing.h no longer gives the correct answer. The following patch can fix the bug:

```
diff --git a/sysdeps/aarch64/hp-timing.h b/sysdeps/aarch64/hp-timing.h
index c8469e3011..c5a1204d2c 100644
--- a/sysdeps/aarch64/hp-timing.h
+++ b/sysdeps/aarch64/hp-timing.h
@@ -41,7 +41,7 @@ typedef uint64_t hp_timing_t;
#define HP_TIMING_DIFF(Diff, Start, End)                       \
({  hp_timing_t freq;                                          \
     __asm__ __volatile__ ("mrs %0, cntfrq_el0" : "=r" (freq)); \
-   (Diff) = ((End) - (Start)) * (UINT64_C(1000000000) / freq); \
+   (Diff) = (hp_timing_t)((End) - (Start)) * ((1000000000.0) / freq);  \
})
 #endif /* hp-timing.h */
```

I have also submitted a bug report with the proposed changes at -
https://sourceware.org/bugzilla/show_bug.cgi?id=29329

Regards,

Jun

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-01-31 14:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-11 22:49 bug fix for hp-timing.h (aarch64) Wilco Dijkstra
2023-01-12 14:38 ` Tang, Jun
2023-01-12 18:07   ` Wilco Dijkstra
2023-01-12 18:54     ` Zack Weinberg
2023-01-12 20:32       ` Wilco Dijkstra
2023-01-12 20:51         ` Noah Goldstein
2023-01-16 16:33           ` Wilco Dijkstra
2023-01-16 17:01             ` Noah Goldstein
2023-01-16 18:35               ` Wilco Dijkstra
2023-01-12 15:11 ` Zack Weinberg
  -- strict thread matches above, loose matches on Subject: below --
2023-01-11 16:44 Tang, Jun
2023-01-11 17:22 ` Zack Weinberg
2023-01-31 14:47   ` Tang, Jun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).