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

Re: camlSys__entry vs. FreeBSD kmod

On 11 Jul 2012, at 14:34, PALI Gabor Janos wrote:

> On Wed, Jul 11, 2012 at 03:20:20PM +0200, PALI Gabor Janos wrote:
>> ...
>> caml_startup(NULL);
>> main_closure = caml_named_value("main");
>> if (!main_closure) bail_out();
>> caml_callback(*main_closure, Val_int(42));
>> ...
> Sorry, I have to correct myself: caml_startup() needs some sensible argument,
> i.e. a NULL-terminated array of strings.  This is { "kmod", NULL } for now.

Yes, that's correct, and so is your approach of calling a closure back
from C into OCaml.   The main-loop of the Xen kernel looks like this:

>   caml_startup(argv);
>   v_main = caml_named_value("OS.Main.run");
>   ASSERT(v_main != NULL);
>   while (caml_completed == 0) {
>     evtchn_poll();
>     caml_completed = Bool_val(caml_callback(*v_main, Val_unit));
>   }

We first initialise the runtime, which runs one iteration of the
program.  However, this may leave a number of blocked cooperative threads,
and we do not yet have a return value.

The main thread loop, in the 'run' function:
... will register the "OS.Main.run" callback when it is invoked, and 
this callback will poll all the threads, and then return a boolean 
indicating if they have all finished or not (and this is the caml_completed
loop in the C runtime).

So we'll need to do something similar with the kFreeBSD backend: the logic
is in the OS.Main.run module in mirage-platform (which implements an OS
module for either POSIX or Xen at the moment, and will have an extra
directory for kFreeBSD with your kernel-specific bindings in it).

Summary: the callbacks working and executing code in the kernel is a very 
good thing! :)




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