Code Monkey home page Code Monkey logo

mirage-clock's Introduction

mirage-clock -- libraries and module types for portable clocks

This library implements portable support for an operating system timesource that is compatible with the MirageOS library interfaces found in: https://github.com/mirage/mirage

It implements an MCLOCK module that represents a monotonic timesource since an arbitrary point, and PCLOCK which counts time since the Unix epoch.

The following sources are used:

  • The Unix version uses gettimeofday or clock_gettime, depending on which OS is in use (see clock_stubs.c).
  • The freestanding version uses the paravirtual clock source from the hypervisor.

mirage-clock's People

Contributors

avsm avatar craigfe avatar dbuenzli avatar dinosaure avatar djs55 avatar eduardorfs avatar hannesm avatar mato avatar mattgray avatar olleolleolle avatar samoht avatar talex5 avatar thelortex avatar yomimono avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mirage-clock's Issues

OSX build is broken, trying to link with -lrt

#12 applies -lrt to all builds in unix, causing errors in OSX

I've converted to this repo to topkg, which made fixing this issue easier (I couldn't figure out how to apply the fix only to Linux using Oasis). A PR for that is on it's way shortly.

#=== ERROR while installing mirage-clock-unix.dev~mirage ======================#
# opam-version 1.2.2
# os           darwin
# command      make unix-build
# path         /Users/mgray/.opam/horseos/build/mirage-clock-unix.dev~mirage
# compiler     system (4.03.0)
# exit-code    2
# env-file     /Users/mgray/.opam/horseos/build/mirage-clock-unix.dev~mirage/mirage-clock-unix-92783-c743ac.env
# stdout-file  /Users/mgray/.opam/horseos/build/mirage-clock-unix.dev~mirage/mirage-clock-unix-92783-c743ac.out
# stderr-file  /Users/mgray/.opam/horseos/build/mirage-clock-unix.dev~mirage/mirage-clock-unix-92783-c743ac.err
### stdout ###
# pkg_lwt_unix: ........................................ /Users/mgray/.opam/horseos/lib/lwt
# [...]
# ocaml setup.ml -build
# ocamlopt.opt unix.cmxa -I /Users/mgray/.opam/horseos/lib/ocamlbuild /Users/mgray/.opam/horseos/lib/ocamlbuild/ocamlbuildlib.cmxa myocamlbuild.ml /Users/mgray/.opam/horseos/lib/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
# /Users/mgray/.opam/horseos/bin/ocamlfind ocamlc -g -ccopt -O2 -ccopt -g -ccopt -Wall -c unix/clock_stubs.c
# mv clock_stubs.o unix/clock_stubs.o
# /Users/mgray/.opam/horseos/bin/ocamlfind ocamlmklib -o unix/mirage-clock-unix_stubs -lrt unix/clock_stubs.o
# + /Users/mgray/.opam/horseos/bin/ocamlfind ocamlmklib -o unix/mirage-clock-unix_stubs -lrt unix/clock_stubs.o
# ld: library not found for -lrt
# clang: error: linker command failed with exit code 1 (use -v to see invocation)
# Command exited with code 2.
### stderr ###
# E: Failure("Command ''/Users/mgray/.opam/horseos/bin/ocamlbuild' unix/libmirage-clock-unix_stubs.a unix/dllmirage-clock-unix_stubs.so unix/mirage-clock-unix.cma unix/mirage-clock-unix.cmxa unix/mirage-clock-unix.a unix/mirage-clock-unix.cmxs lib_test/portable.native -tag debug' terminated with error code 10")
# make: *** [unix-build] Error 1

integer overflow on 32bits platform within posix_clock_gettime_s_ns

hit this bug while testing some mirage application on cubietruck

i think the problem comes from this c stub function

which, on 32bits platform, returns negative values, and causes Ptime.v to raise an exception when called upon from mirage-logs report function

as the logs package is widely used among various mirage libraries, I think this bug would effectively prevent any application from working properly on 32bits platform when targeting unix

mirage-clock-freestanding passes through several layers, including floating point

let's take a brief look at how now_d_ps () on solo5 works:

  • Pclock.ml calls to unix_gettime (external time : unit -> float)
  • this is implemented by mirage-solo5/lib/bindings/clock_stubs.c, calling to gettimeofday (struct timeval*, NULL) and caml_copy_double((double) tp.tv_sec + (double) tp.tv_usec / 1e6)
  • gettimeofday is implemented by ocaml-freestanding (in nolibc/sysdeps_solo5.c), calling out to int64 solo5_clock_wall (and conversion: tv->tv_sec = now / NSEC_PER_SEC; tv->tv_usec = (now % NSEC_PER_SEC) / 1000ULL;)
  • solo5_clock_wall is provided by ukvm and virtio in time.c, using pvclock or tscclock

My main concern is that our base is nanoseconds since epoch as an unsigned int64 in C, we nevertheless convert them to a struct with two unsigned int64, just to convert them to a OCaml double, to again convert them (in this library) to an int and an int64. We could save several conversions on the way, and just use the solo5_clock_wall directly (or name it differently and provide same implementation with Xen minios).

opam install --build-test fails

Hello, here's the output I got from opam:

> opam install --build-test mirage-clock-lwt
The following actions will be performed:
  ∗  install conf-m4          1               [required by ocamlfind]
  ∗  install result           1.2             [required by lwt]
  ∗  install ocamlbuild       0.11.0          [required by mirage-clock-lwt]
  ∗  install ocamlfind        1.7.1           [required by mirage-clock-lwt]
  ∗  install uchar            0.0.1           [required by fmt]
  ∗  install topkg            0.9.0           [required by mirage-clock-lwt]
  ∗  install ppx_tools        5.0             [required by lwt]
  ∗  install fmt              0.8.2           [required by mirage-device]
  ∗  install lwt              2.7.0           [required by mirage-clock-lwt]
  ∗  install mirage-device    1.0.0           [required by mirage-clock]
  ∗  install mirage-clock     1.2.0           [required by mirage-clock-lwt]
  ∗  install mirage-clock-lwt 1.2.0 
===== ∗  12 =====
Do you want to continue ? [Y/n] y

=-=- Gathering sources =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[fmt] Archive in cache
[lwt] Archive in cache
[mirage-clock] Archive in cache
[mirage-clock-lwt] Archive in cache
[mirage-device] Archive in cache
[ocamlbuild] Archive in cache
[ocamlfind] Archive in cache
[ppx_tools] Archive in cache
[result] Archive in cache
[topkg] Archive in cache
[uchar] Archive in cache

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
∗  installed conf-m4.1
∗  installed result.1.2
∗  installed ocamlfind.1.7.1
∗  installed ppx_tools.5.0
∗  installed ocamlbuild.0.11.0
∗  installed uchar.0.0.1
∗  installed topkg.0.9.0
∗  installed fmt.0.8.2
∗  installed mirage-device.1.0.0
∗  installed mirage-clock.1.2.0
∗  installed lwt.2.7.0
[ERROR] The compilation of mirage-clock-lwt failed at "ocaml pkg/pkg.ml test".

#=== ERROR while installing mirage-clock-lwt.1.2.0 ============================#
# opam-version 1.2.2
# os           linux
# command      ocaml pkg/pkg.ml test
# path         /home/bertrand/.opam/mirage-issue/build/mirage-clock-lwt.1.2.0
# compiler     4.04.0
# exit-code    1
# env-file     /home/bertrand/.opam/mirage-issue/build/mirage-clock-lwt.1.2.0/mirage-clock-lwt-7288-a08ad8.env
# stdout-file  /home/bertrand/.opam/mirage-issue/build/mirage-clock-lwt.1.2.0/mirage-clock-lwt-7288-a08ad8.out
# stderr-file  /home/bertrand/.opam/mirage-issue/build/mirage-clock-lwt.1.2.0/mirage-clock-lwt-7288-a08ad8.err
### stderr ###
# pkg.ml: [ERROR] _build/_topkg-mirage-clock.tests: no such file. Did you forget to build the package ?

mirage-clock-xen is misnamed

it is used for solo5 as well. maybe clock-freestanding? (but it depends on some external C symbols, namely: caml_get_monotonic_time and unix_gettimeofday, provided by mirage-platform)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.