[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MirageOS-devel] Help using V1.CLOCK



Thanks, Dave.

On Tue, Sep 2, 2014 at 1:09 PM, Dave Scott <Dave.Scott@xxxxxxxxxx> wrote:
> Hi,
>
> On 2 Sep 2014, at 20:48, Jacob Mitchell <jacob.d.mitchell@xxxxxxxxx> wrote:
>
>> Goal: print the current time to the console; repeat until termination.
>>
>> I think I'm close, but when I call "make" the compiled main.ml file
>> results in an "Unbound value clock" error. Refer to
>> https://gist.github.com/anonymous/90f4107cf5008b12d356 for my source
>> code, the main.ml file, and the build log.
>>
>> Any pointers? I haven't found any tests or sample code to demonstrate
>> how to use non-polymorphic first-class modules like CLOCK, TIME, and
>> RANDOM.
>
> It looks to me like a mismatch between the generated code (in main.ml) and 
> the mirage-clock code. The other devices (block, network, console) have a 
> âconnectâ function to connect to an instance, but the clock[1] is a 
> singleton. So I think we just need to omit all references to âclockâ (the 
> instance) in the generated fragment:
>
>>>>>
> module M1 = Unikernel.Main(Console)(Clock)
>
> let t1 () =
>   clock () >>= function
>   | `Error e -> fail (Failure "clock")
>   | `Ok clock ->
>   console1 () >>= function
>   | `Error e -> fail (Failure "console1")
>   | `Ok console1 ->
>   M1.start console1 clock
> <<<<
>

The problem may extend to first-class modules that aren't DEVICEs
(e.g. RANDOM). I ran into the same sort of error when I tried printing
a random int on each line instead of the current time. The code I
tried follows:

>>>> (config.ml)
open Mirage

let main =
  foreign "Unikernel.Main" (console @-> random @-> job)

let () =
  register "console" [ main $ default_console $ default_random ]
<<<<


>>>> (unikernel.ml)
open V1
open Lwt

module Main (C: CONSOLE)(RAND: RANDOM) = struct

let start console random =
  RAND.self_init () ;
  while true do
    C.log console (Printf.sprintf "%d" (RAND.int 2))
  done ;
  return ()
end
<<<<


>>>> build error (under UNIX mode)
File "main.ml", line 20, characters 2-8:
Error: Unbound value random
Command exited with code 2.
make: *** [main.native] Error 10
<<<<


>>>> generated main.ml (excerpt)
module M1 = Unikernel.Main(Console)(Random)

let t1 () =
  console1 () >>= function
  | `Error e -> fail (Failure "console1")
  | `Ok console1 ->
  random () >>= function
  | `Error e -> fail (Failure "random")
  | `Ok random ->
  M1.start console1 random
<<<<

> Iâll take a quick look.
>
> Cheers,
> Dave
>
> [1] https://github.com/mirage/mirage-clock/blob/master/unix/clock.mli

_______________________________________________
MirageOS-devel mailing list
MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.