diff --git a/.github/workflows/esy.yml b/.github/workflows/esy.yml index f5313b6..11f0d20 100644 --- a/.github/workflows/esy.yml +++ b/.github/workflows/esy.yml @@ -30,14 +30,10 @@ jobs: "dependencies": { "ocaml": "4.12.x", "@opam/mirage-clock": "*", - "@opam/mirage-clock-unix": "*", - "@opam/mirage-clock-solo5": "*", "reason-mobile": "github:EduardoRFS/reason-mobile:generate.json#7ba258319b87943d2eb0d8fb84562d0afeb2d41f" }, "resolutions": { "@opam/mirage-clock": "./mirage-clock.opam", - "@opam/mirage-clock-unix": "./mirage-clock-unix.opam", - "@opam/mirage-clock-solo5": "./mirage-clock-solo5.opam" } }' > esy.json diff --git a/appveyor.yml b/appveyor.yml index f6a3eb6..c03cfbb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,8 +6,8 @@ environment: FORK_BRANCH: master CYG_ROOT: C:\cygwin64 OPAM_SWITCH: 4.08.0+mingw64c - PINS: "mirage-clock.dev:. mirage-clock-unix.dev:." - PACKAGE: "mirage-clock-unix" + PINS: "mirage-clock.dev:." + PACKAGE: "mirage-clock" install: - ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/$env:FORK_USER/ocaml-ci-scripts/$env:FORK_BRANCH/appveyor-install.ps1")) diff --git a/config/discover.ml b/config/discover.ml index 8e8f03d..10937ff 100644 --- a/config/discover.ml +++ b/config/discover.ml @@ -1,16 +1,22 @@ module C = Configurator.V1 let () = - C.main ~name:"mirage-clock-unix" (fun c -> - let is_android = - let defines = + C.main ~name:"mirage-clock" (fun c -> + let android, solo5 = + let android_defines = C.C_define.import c ~includes:[] [ ("__ANDROID__", Switch) ] in - match defines with (_, Switch true) :: _ -> true | _ -> false + let solo5_defines = + C.C_define.import c ~includes:[] [ ("__ocaml_solo5__", Switch) ] + in + match android_defines, solo5_defines with + | (_, Switch true) :: _, _ -> true, false + | _, (_, Switch true) :: _ -> false, true + | _ -> false, false in let ccflags = - match (C.ocaml_config_var c "system", is_android) with - | Some "linux", false -> [ "-lrt" ] + match (C.ocaml_config_var c "system", android, solo5) with + | Some "linux", false, false -> [ "-lrt" ] | _ -> [] in C.Flags.write_sexp "cclib.sexp" ccflags) diff --git a/lib_test/dune b/lib_test/dune index 02f0a22..dd0ee15 100644 --- a/lib_test/dune +++ b/lib_test/dune @@ -1,4 +1,4 @@ (test (name portable) - (package mirage-clock-unix) - (libraries mirage-clock-unix)) + (package mirage-clock) + (libraries mirage-clock)) diff --git a/lib_test/portable.ml b/lib_test/portable.ml index f1e5944..656106a 100644 --- a/lib_test/portable.ml +++ b/lib_test/portable.ml @@ -1,3 +1,5 @@ +open Mirage_clock + let print_time c = let d, ps = Pclock.now_d_ps c in Printf.printf "The time is %d days and %Ld picoseconds since the epoch.\n" d diff --git a/mirage-clock-solo5.opam b/mirage-clock-solo5.opam deleted file mode 100644 index 9387cee..0000000 --- a/mirage-clock-solo5.opam +++ /dev/null @@ -1,29 +0,0 @@ -opam-version: "2.0" -maintainer: "anil@recoil.org" -authors: ["Anil Madhavapeddy" "Daniel C. Bünzli" "Matthew Gray"] -license: "ISC" -tags: "org:mirage" -homepage: "https://github.com/mirage/mirage-clock" -bug-reports: "https://github.com/mirage/mirage-clock/issues" -synopsis: "Paravirtual implementation of the MirageOS Clock interface" -description: """ -This 'freestanding' implementation of the MirageOS CLOCK interface -is designed to be linked against an embedded runtime that provides -a concrete implementation of the clock source. Example implementations -include the [Solo5](https://github.com/solo5/solo5) backend of -MirageOS. -""" -depends: [ - "ocaml" {>= "4.08.0"} - "dune" {>= "2.8"} - "mirage-clock" {= version} -] -conflicts: [ - "mirage-solo5" {< "0.7.0"} - "mirage-xen" {< "7.0.0"} -] -build: [ - ["dune" "subst"] {dev} - ["dune" "build" "-p" name "-j" jobs] -] -dev-repo: "git+https://github.com/mirage/mirage-clock.git" diff --git a/mirage-clock-unix.opam b/mirage-clock-unix.opam deleted file mode 100644 index 204dfc5..0000000 --- a/mirage-clock-unix.opam +++ /dev/null @@ -1,26 +0,0 @@ -opam-version: "2.0" -maintainer: "anil@recoil.org" -authors: ["Anil Madhavapeddy" "Daniel C. Bünzli" "Matthew Gray"] -license: "ISC" -tags: "org:mirage" -homepage: "https://github.com/mirage/mirage-clock" -doc: "https://mirage.github.io/mirage-clock/" -bug-reports: "https://github.com/mirage/mirage-clock/issues" -synopsis: "Unix-based implementation for the MirageOS Clock interface" -description: """ -The Unix implementation of the MirageOS Clock interface uses -`gettimeofday` or `clock_gettime`, depending on -which OS is in use (see [clock_stubs.c](https://github.com/mirage/mirage-clock/blob/master/unix/clock_stubs.c)). -""" -depends: [ - "ocaml" {>= "4.08.0"} - "dune" {>= "2.8"} - "dune-configurator" - "mirage-clock" {= version} -] -build: [ - ["dune" "subst"] {dev} - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name] {with-test} -] -dev-repo: "git+https://github.com/mirage/mirage-clock.git" diff --git a/solo5/clock_stubs.default.c b/solo5/clock_stubs.default.c deleted file mode 100644 index e69de29..0000000 diff --git a/solo5/clock_stubs.solo5.c b/solo5/clock_stubs.solo5.c deleted file mode 100644 index 8424b3b..0000000 --- a/solo5/clock_stubs.solo5.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2010 Anil Madhavapeddy - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "solo5.h" - -#include - -#include -#include -#include -#include - -// caml_get_monotonic_time is already defined in mirage-solo5 - -CAMLprim value -caml_get_wall_clock(value v_unit) -{ - CAMLparam1(v_unit); - CAMLreturn(caml_copy_int64(solo5_clock_wall())); -} diff --git a/solo5/dune b/solo5/dune deleted file mode 100644 index 9223bf4..0000000 --- a/solo5/dune +++ /dev/null @@ -1,26 +0,0 @@ -(library - (name mirage_clock_solo5) - (wrapped false) - (public_name mirage-clock-solo5) - (libraries mirage-clock) - (foreign_stubs - (language c) - (names clock_stubs))) - -(rule - (target clock_stubs.c) - (enabled_if - (<> %{context_name} "solo5")) - (deps - (:src clock_stubs.default.c)) - (action - (copy %{src} %{target}))) - -(rule - (target clock_stubs.c) - (enabled_if - (= %{context_name} "solo5")) - (deps - (:src clock_stubs.solo5.c)) - (action - (copy %{src} %{target}))) diff --git a/solo5/mclock.mli b/solo5/mclock.mli deleted file mode 100644 index fbbd0c2..0000000 --- a/solo5/mclock.mli +++ /dev/null @@ -1,22 +0,0 @@ -(* - * Copyright (c) 2015 Daniel C. Bünzli. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - *) - -(** Monotonic clock for MirageOS using paravirtual interfaces - - Clock returning monotonic time since an arbitrary point. To be used for eg. - profiling. *) - -include Mirage_clock.MCLOCK diff --git a/solo5/pclock.mli b/solo5/pclock.mli deleted file mode 100644 index bdef054..0000000 --- a/solo5/pclock.mli +++ /dev/null @@ -1,21 +0,0 @@ -(* - * Copyright (c) 2015 Daniel C. Bünzli - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - *) - -(** POSIX clock for MirageOS using paravirtual interfaces - - Clock counting time since the Unix epoch. Subject to adjustment by e.g. NTP. *) - -include Mirage_clock.PCLOCK diff --git a/unix/clock_stubs.c b/src/clock_stubs.c similarity index 94% rename from unix/clock_stubs.c rename to src/clock_stubs.c index ae2bef4..9ae8a10 100644 --- a/unix/clock_stubs.c +++ b/src/clock_stubs.c @@ -14,6 +14,28 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#if defined(__ocaml_solo5__) + +#include "solo5.h" + +#include + +#include +#include +#include +#include + +// caml_get_monotonic_time is already defined in mirage-solo5 + +CAMLprim value +caml_get_wall_clock(value v_unit) +{ + CAMLparam1(v_unit); + CAMLreturn(caml_copy_int64(solo5_clock_wall())); +} + +#else + #include #include #include @@ -240,3 +262,5 @@ CAMLprim value ocaml_posix_clock_period_ns (value unit) return caml_copy_int64 (0L); } #endif + +#endif // ocaml_solo5 diff --git a/src/dune b/src/dune index 5133e38..b4c5b86 100644 --- a/src/dune +++ b/src/dune @@ -1,3 +1,21 @@ (library (name mirage_clock) - (public_name mirage-clock)) + (public_name mirage-clock) + (modules mirage_clock pclock mclock) + (libraries + (select pclock.ml from + (unix -> pclock.unix.ml) + (mirage-solo5 -> pclock.solo5.ml) + (mirage-xen -> pclock.solo5.ml) +) + (select mclock.ml from + (unix -> mclock.unix.ml) + (mirage-solo5 -> mclock.solo5.ml) + (mirage-xen -> mclock.solo5.ml) +)) + (foreign_stubs + (language c) + (names clock_stubs)) + (c_library_flags + (:standard + (:include ../config/cclib.sexp)))) diff --git a/solo5/mclock.ml b/src/mclock.solo5.ml similarity index 100% rename from solo5/mclock.ml rename to src/mclock.solo5.ml diff --git a/unix/mclock.ml b/src/mclock.unix.ml similarity index 100% rename from unix/mclock.ml rename to src/mclock.unix.ml diff --git a/src/mirage_clock.ml b/src/mirage_clock.ml index a2cfa25..4afb665 100644 --- a/src/mirage_clock.ml +++ b/src/mirage_clock.ml @@ -1,54 +1,2 @@ -(* - * Copyright (c) 2015 Matt Gray - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - *) -(** Clock devices for MirageOS - - This module define clock devices signatures for MirageOS. - - {e Release %%VERSION%%} *) - -(** {2 POSIX clock} - - Clock counting time since the Unix epoch. Subject to adjustment by e.g. NTP. *) -module type PCLOCK = sig - val now_d_ps : unit -> int * int64 - (** [now_d_ps ()] is [(d, ps)] representing the POSIX time occurring at [d] * - 86'400e12 + [ps] POSIX picoseconds from the epoch 1970-01-01 00:00:00 UTC. - [ps] is in the range \[[0];[86_399_999_999_999_999L]\]. *) - - val current_tz_offset_s : unit -> int option - (** [current_tz_offset_s ()] is the clock's current local time zone offset to - UTC in seconds, if known. This is the duration local time - UTC time in - seconds. *) - - val period_d_ps : unit -> (int * int64) option - (** [period_d_ps ()] is [Some (d, ps)] representing the clock's picosecond - period [d] * 86'400e12 + [ps], if known. [ps] is in the range - \[[0];[86_399_999_999_999_999L]\]. *) -end - -(** {2 Monotonic clock} - - Clock returning monotonic time since an arbitrary point. To be used for e.g. - profiling. *) -module type MCLOCK = sig - val elapsed_ns : unit -> int64 - (** [elapsed_ns ()] is a monotonically increasing count of nanoseconds elapsed - since some arbitrary point *) - - val period_ns : unit -> int64 option - (** [period_ns ()] is [Some ns] representing the clock's nanosecond period - [ns], if known *) -end +module Pclock = Pclock +module Mclock = Mclock diff --git a/src/mirage_clock.mli b/src/mirage_clock.mli new file mode 100644 index 0000000..f87f2b6 --- /dev/null +++ b/src/mirage_clock.mli @@ -0,0 +1,54 @@ +(* + * Copyright (c) 2015 Matt Gray + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + *) +(** Clock devices for MirageOS + + This module define clock devices signatures for MirageOS. + + {e Release %%VERSION%%} *) + +(** {2 POSIX clock} + + Clock counting time since the Unix epoch. Subject to adjustment by e.g. NTP. *) +module Pclock : sig + val now_d_ps : unit -> int * int64 + (** [now_d_ps ()] is [(d, ps)] representing the POSIX time occurring at [d] * + 86'400e12 + [ps] POSIX picoseconds from the epoch 1970-01-01 00:00:00 UTC. + [ps] is in the range \[[0];[86_399_999_999_999_999L]\]. *) + + val current_tz_offset_s : unit -> int option + (** [current_tz_offset_s ()] is the clock's current local time zone offset to + UTC in seconds, if known. This is the duration local time - UTC time in + seconds. *) + + val period_d_ps : unit -> (int * int64) option + (** [period_d_ps ()] is [Some (d, ps)] representing the clock's picosecond + period [d] * 86'400e12 + [ps], if known. [ps] is in the range + \[[0];[86_399_999_999_999_999L]\]. *) +end + +(** {2 Monotonic clock} + + Clock returning monotonic time since an arbitrary point. To be used for e.g. + profiling. *) +module Mclock : sig + val elapsed_ns : unit -> int64 + (** [elapsed_ns ()] is a monotonically increasing count of nanoseconds elapsed + since some arbitrary point *) + + val period_ns : unit -> int64 option + (** [period_ns ()] is [Some ns] representing the clock's nanosecond period + [ns], if known *) +end diff --git a/solo5/pclock.ml b/src/pclock.solo5.ml similarity index 100% rename from solo5/pclock.ml rename to src/pclock.solo5.ml diff --git a/unix/pclock.ml b/src/pclock.unix.ml similarity index 100% rename from unix/pclock.ml rename to src/pclock.unix.ml diff --git a/unix/dune b/unix/dune deleted file mode 100644 index e03be8e..0000000 --- a/unix/dune +++ /dev/null @@ -1,13 +0,0 @@ -(library - (name mirage_clock_unix) - (wrapped false) - (public_name mirage-clock-unix) - (libraries mirage-clock unix) - (foreign_stubs - (language c) - (flags - (:standard \ -Wall -g -O2)) - (names clock_stubs)) - (c_library_flags - (:standard - (:include ../config/cclib.sexp)))) diff --git a/unix/mclock.mli b/unix/mclock.mli deleted file mode 100644 index dab1720..0000000 --- a/unix/mclock.mli +++ /dev/null @@ -1,21 +0,0 @@ -(* - * Copyright (c) 2015 Daniel C. Bünzli. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - *) - -include Mirage_clock.MCLOCK -(** Monotonic clock for Unix using MirageOS interfaces - - Clock returning monotonic time since an arbitrary point. To be used for eg. - profiling. *) diff --git a/unix/pclock.mli b/unix/pclock.mli deleted file mode 100644 index f01b8ee..0000000 --- a/unix/pclock.mli +++ /dev/null @@ -1,20 +0,0 @@ -(* - * Copyright (c) 2015 Daniel C. Bünzli - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - *) - -include Mirage_clock.PCLOCK -(** POSIX clock for MirageOS using Unix interfaces - - Clock counting time since the Unix epoch. Subject to adjustment by e.g. NTP. *)