Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu cycles: on arm64 use clock_gettime and PMCCNTR_EL0 for freestanding #238

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/native/entropy_cpu_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,23 @@ static inline uint32_t read_virtual_count (void)
#endif /* arm */

#if defined (__aarch64__)
#define isb() __asm__ __volatile__("isb" : : : "memory")
#if defined(__ocaml_freestanding__) || defined(__ocaml_solo5__)
static inline uint64_t read_virtual_count(void)
{
uint64_t c;
isb();
__asm__ __volatile__("mrs %0, cntvct_el0":"=r"(c));
__asm__ __volatile__("mrs %0, PMCCNTR_EL0":"=r"(c));
return c;
}
#else
/* see https://github.com/mirage/mirage-crypto/issues/216 */
#include <time.h>
static inline uint64_t read_virtual_count (void)
{
struct timespec now;
clock_gettime (CLOCK_MONOTONIC, &now);
return now.tv_nsec;
}
#endif /* __ocaml_freestanding__ || __ocaml_solo5__ */
#endif /* aarch64 */

#if defined (__powerpc64__)
Expand Down
Loading