From baf857d431d62e9c85045657bf0bb80d897c4b25 Mon Sep 17 00:00:00 2001 From: Victor Nakoryakov Date: Fri, 24 Jun 2022 19:49:00 +0300 Subject: [PATCH 1/3] Make benchmarking work on Linux --- benchmarks/dune | 9 ++++++++- benchmarks/mac_osx_time.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/benchmarks/dune b/benchmarks/dune index 00859ffa..737899d1 100644 --- a/benchmarks/dune +++ b/benchmarks/dune @@ -2,7 +2,14 @@ (name benchmark) (public_name bench) (enabled_if - (= %{system} macosx)) + (or + (= %{system} macosx) + ; or one of Linuxes (see https://github.com/ocaml/ocaml/issues/10613) + (= %{system} linux) + (= %{system} linux_elf) + (= %{system} elf) + (= %{system} linux_eabihf) + (= %{system} linux_eabi))) (flags (-open Syntax -open Compilerlibs406)) (foreign_stubs diff --git a/benchmarks/mac_osx_time.c b/benchmarks/mac_osx_time.c index aa80eb2e..58dfef98 100644 --- a/benchmarks/mac_osx_time.c +++ b/benchmarks/mac_osx_time.c @@ -1,16 +1,44 @@ #include #include -/* #include */ + +// +// Platform-specific includes +// +#if (defined(__MACH__) && defined(__APPLE__)) #include +#elif defined(__linux__) +#include +#endif +// +// Platform-specific globals +// +#if (defined(__MACH__) && defined(__APPLE__)) static mach_timebase_info_data_t info; +#endif +// +// Exported functions +// CAMLprim value caml_mach_initialize(value unit) { +#if (defined(__MACH__) && defined(__APPLE__)) mach_timebase_info(&info); +#endif + return Val_unit; } CAMLprim value caml_mach_absolute_time(value unit) { - uint64_t now = mach_absolute_time (); - return caml_copy_int64((now * info.numer) / info.denom); + uint64_t result = 0; + +#if (defined(__MACH__) && defined(__APPLE__)) + uint64_t now = mach_absolute_time(); + result = (now * info.numer) / info.denom +#elif defined(__linux__) + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + result = now.tv_sec * 1000 + now.tv_nsec / 1000000; +#endif + + return caml_copy_int64(result); } From d756af5ebb4954e2368e7f56654bd9c5abb49d85 Mon Sep 17 00:00:00 2001 From: Victor Nakoryakov Date: Fri, 24 Jun 2022 19:50:55 +0300 Subject: [PATCH 2/3] Rename `mac_osx_time.c` to less platform-specific `time.c` --- benchmarks/dune | 2 +- benchmarks/{mac_osx_time.c => time.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename benchmarks/{mac_osx_time.c => time.c} (100%) diff --git a/benchmarks/dune b/benchmarks/dune index 737899d1..5c2ec666 100644 --- a/benchmarks/dune +++ b/benchmarks/dune @@ -14,7 +14,7 @@ (-open Syntax -open Compilerlibs406)) (foreign_stubs (language c) - (names mac_osx_time)) + (names time)) (libraries syntax compilerlibs406)) (data_only_dirs data) diff --git a/benchmarks/mac_osx_time.c b/benchmarks/time.c similarity index 100% rename from benchmarks/mac_osx_time.c rename to benchmarks/time.c From ecc5fce34b6c0061dd450c66a55e0533713247a2 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 24 Jun 2022 20:54:44 +0200 Subject: [PATCH 3/3] Semi missing. --- benchmarks/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/time.c b/benchmarks/time.c index 58dfef98..df29af7b 100644 --- a/benchmarks/time.c +++ b/benchmarks/time.c @@ -33,7 +33,7 @@ CAMLprim value caml_mach_absolute_time(value unit) { #if (defined(__MACH__) && defined(__APPLE__)) uint64_t now = mach_absolute_time(); - result = (now * info.numer) / info.denom + result = (now * info.numer) / info.denom; #elif defined(__linux__) struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now);