From: Ian Campbell Subject: Re: [Xen-API] [PATCH 10 of 15] libxc/ocaml: Add simple binding for xentoollog (output only) Date: Fri, 30 Nov 2012 09:50:42 +0000 Message-ID: <1354269042.6269.85.camel@zakaz.uk.xensource.com> References: <2b433b1523e4295bb1ed.1353432210@cosworth.uk.xensource.com> <7EA643C653F17F4C80DE959E978F10EDFA101107B2@LONPMAILBOX01.citrite.net> <1354212199.6269.67.camel@zakaz.uk.xensource.com> <5DC583C2-ED2D-4305-9AC5-74F8F57F300D@recoil.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <5DC583C2-ED2D-4305-9AC5-74F8F57F300D@recoil.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Anil Madhavapeddy Cc: "xen-devel@lists.xen.org" , Rob Hoes , David Scott , "xen-api@lists.xen.org" List-Id: xen-devel@lists.xenproject.org On Thu, 2012-11-29 at 18:20 +0000, Anil Madhavapeddy wrote: > On 29 Nov 2012, at 18:03, Ian Campbell wrote: > > > > Another idea might be to make the bindings use the async interfaces > > wherever possible by default, by definition anything potentially > > blocking has supports this and that would avoid the need for > > enter/leave, but at the expense of making the ocaml callers ugly > > perhaps? Or maybe this sort of thing ends up looking very natural in > > ocaml? Depends on your application's event mechanism I suspect. > > > > Last half witted idea: everything could be async but the bindings > > include the loop to wait for the async event, i.e. effectively making > > the call sync again. This sounds silly but it might allow better control > > over the placement of enter/leave vs callbacks, since you would just > > drop it over libxl_event_wait? > > Making everything explicitly async and non-blocking is by far the > preferred solution in terms of stability, as it largely removes the > need to worry about the GC interface and thread interactions. > > There are several libraries to wrap async interfaces in convenient > synchronous programming, most notably Lwt (http://ocsigen.org/lwt). I'll have to take your word for that ;-) > With this interface, all the OCaml callbacks are implemented in > OCaml, and it just needs a select/epoll or equivalent to wake up > sleeping threads when an IO event occurs. On the libxl side you'd want to be using the ao_how thing described in libxl.h[0] and probably the event loop stuff in libxl_event.h[1]. My gut feeling is that you'd want to go the libxl_osevent_register_hooks route to integrate libxl into lwt's event loop rather than the libxl_osevent_{before,after}poll option. [0] http://xenbits.xen.org/hg/xen-unstable.hg/file/1c69c938f641/tools/libxl/libxl.h#l377 [1] http://xenbits.xen.org/hg/xen-unstable.hg/file/1c69c938f641/tools/libxl/libxl_event.h Ian. > > Dave has already done some bindings to Lwt, so I've CCed him... > > -anil >