Vincent Hanquez
2010-Aug-10 11:46 UTC
[Xen-devel] [PATCH 0/5] xl ocaml: drop lock in the bindings
This patchserie enable dropping the ocaml lock in the xl bindings. also fix the META file generation to have a proper version number in ocaml libraries. Vincent Hanquez (5): Put a valid version number in the META files. Wrap init context procedure into a macro. Introduce a gc structure. use new functions to get elements out of ocaml values. use new gc functions to deep copy structure and only free once the gc. always drop the caml lock during any xl operations. tools/ocaml/common.make | 2 +- tools/ocaml/libs/xl/xl_stubs.c | 194 ++++++++++++++++++++++++--------------- 2 files changed, 120 insertions(+), 76 deletions(-) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Aug-10 11:46 UTC
[Xen-devel] [PATCH 1/5] Put a valid version number in the META files.
Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com> --- tools/ocaml/common.make | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Aug-10 11:46 UTC
[Xen-devel] [PATCH 2/5] Wrap init context procedure into a macro. Introduce a gc structure.
Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com> --- tools/ocaml/libs/xl/xl_stubs.c | 103 +++++++++++++++++++++------------------ 1 files changed, 55 insertions(+), 48 deletions(-) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Aug-10 11:46 UTC
[Xen-devel] [PATCH 3/5] use new functions to get elements out of ocaml values.
Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com> --- tools/ocaml/libs/xl/xl_stubs.c | 66 +++++++++++++++++++++++++-------------- 1 files changed, 42 insertions(+), 24 deletions(-) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Aug-10 11:46 UTC
[Xen-devel] [PATCH 4/5] use new gc functions to deep copy structure and only free once the gc.
Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com> --- tools/ocaml/libs/xl/xl_stubs.c | 25 +++++++++++++++++++++---- 1 files changed, 21 insertions(+), 4 deletions(-) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Aug-10 11:46 UTC
[Xen-devel] [PATCH 5/5] always drop the caml lock during any xl operations.
Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com> --- tools/ocaml/libs/xl/xl_stubs.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Stefano Stabellini
2010-Aug-10 14:29 UTC
Re: [Xen-devel] [PATCH 0/5] xl ocaml: drop lock in the bindings
On Tue, 10 Aug 2010, Vincent Hanquez wrote:> This patchserie enable dropping the ocaml lock in the xl bindings. > also fix the META file generation to have a proper version number in ocaml libraries. > > Vincent Hanquez (5): > Put a valid version number in the META files. > Wrap init context procedure into a macro. Introduce a gc structure. > use new functions to get elements out of ocaml values. > use new gc functions to deep copy structure and only free once the > gc. > always drop the caml lock during any xl operations. > > tools/ocaml/common.make | 2 +- > tools/ocaml/libs/xl/xl_stubs.c | 194 ++++++++++++++++++++++++--------------- > 2 files changed, 120 insertions(+), 76 deletions(-) > >If you are sending a patch series using an automated tool, I would appreciate if you could use inline patches, so that I can save the messages and use hg import on them. I don''t mind attachments if they contain the comments as long with the diffs. Thanks in advance, Stefano _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Aug-10 15:12 UTC
[Xen-devel] [PATCH 0/5] xl ocaml: drop lock in the bindings
This patchserie enable dropping the ocaml lock in the xl bindings. also fix the META file generation to have a proper version number in ocaml libraries. Resent with inline patches. Vincent Hanquez (5): Put a valid version number in the META files. Wrap init context procedure into a macro. Introduce a gc structure. use new functions to get elements out of ocaml values. use new gc functions to deep copy structure and only free once the gc. always drop the caml lock during any xl operations. tools/ocaml/common.make | 2 +- tools/ocaml/libs/xl/xl_stubs.c | 194 ++++++++++++++++++++++++--------------- 2 files changed, 120 insertions(+), 76 deletions(-) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Aug-10 15:12 UTC
[Xen-devel] [PATCH 1/5] Put a valid version number in the META files.
Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com> --- tools/ocaml/common.make | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/tools/ocaml/common.make b/tools/ocaml/common.make index a2085d7..064d4f6 100644 --- a/tools/ocaml/common.make +++ b/tools/ocaml/common.make @@ -20,7 +20,7 @@ OCAMLCFLAGS += -g $(OCAMLINCLUDE) -w F -warn-error F #LDFLAGS = -cclib -L./ DESTDIR ?= / -VERSION := echo 0.0 +VERSION := 4.1 OCAMLABI = $(shell $(OCAMLC) -version) OCAMLLIBDIR = $(shell $(OCAMLC) -where) -- 1.7.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Aug-10 15:12 UTC
[Xen-devel] [PATCH 2/5] Wrap init context procedure into a macro. Introduce a gc structure.
Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com> --- tools/ocaml/libs/xl/xl_stubs.c | 103 +++++++++++++++++++++------------------ 1 files changed, 55 insertions(+), 48 deletions(-) diff --git a/tools/ocaml/libs/xl/xl_stubs.c b/tools/ocaml/libs/xl/xl_stubs.c index fc0c20d..42f2637 100644 --- a/tools/ocaml/libs/xl/xl_stubs.c +++ b/tools/ocaml/libs/xl/xl_stubs.c @@ -34,6 +34,11 @@ struct caml_logger { char log_buf[2048]; }; +typedef struct caml_gc { + int offset; + void *ptrs[64]; +} caml_gc; + void log_vmessage(struct xentoollog_logger *logger, xentoollog_level level, int errnoval, const char *context, const char *format, va_list al) { @@ -47,6 +52,8 @@ void log_destroy(struct xentoollog_logger *logger) { } +#define INIT_STRUCT() libxl_ctx ctx; struct caml_logger lg; struct caml_gc gc; gc.offset = 0; + #define INIT_CTX() \ lg.logger.vmessage = log_vmessage; \ lg.logger.destroy = log_destroy; \ @@ -65,7 +72,7 @@ void failwith_xl(char *fname, struct caml_logger *lg) caml_raise_with_string(*caml_named_value("xl.error"), s); } -static int string_string_tuple_array_val (char ***c_val, value v) +static int string_string_tuple_array_val (caml_gc *gc, char ***c_val, value v) { CAMLparam1(v); CAMLlocal1(a); @@ -86,7 +93,7 @@ static int string_string_tuple_array_val (char ***c_val, value v) CAMLreturn(0); } -static int domain_create_info_val (libxl_domain_create_info *c_val, value v) +static int domain_create_info_val (caml_gc *gc, libxl_domain_create_info *c_val, value v) { CAMLparam1(v); CAMLlocal1(a); @@ -100,8 +107,8 @@ static int domain_create_info_val (libxl_domain_create_info *c_val, value v) a = Field(v, 5); for (i = 0; i < 16; i++) c_val->uuid[i] = Int_val(Field(a, i)); - string_string_tuple_array_val(&(c_val->xsdata), Field(v, 6)); - string_string_tuple_array_val(&(c_val->platformdata), Field(v, 7)); + string_string_tuple_array_val(gc, &(c_val->xsdata), Field(v, 6)); + string_string_tuple_array_val(gc, &(c_val->platformdata), Field(v, 7)); c_val->poolid = Int32_val(Field(v, 8)); c_val->poolname = String_val(Field(v, 9)); @@ -109,7 +116,7 @@ static int domain_create_info_val (libxl_domain_create_info *c_val, value v) CAMLreturn(0); } -static int domain_build_info_val (libxl_domain_build_info *c_val, value v) +static int domain_build_info_val (caml_gc *gc, libxl_domain_build_info *c_val, value v) { CAMLparam1(v); CAMLlocal1(infopriv); @@ -143,7 +150,7 @@ static int domain_build_info_val (libxl_domain_build_info *c_val, value v) CAMLreturn(0); } -static int device_disk_val(libxl_device_disk *c_val, value v) +static int device_disk_val(caml_gc *gc, libxl_device_disk *c_val, value v) { CAMLparam1(v); @@ -158,7 +165,7 @@ static int device_disk_val(libxl_device_disk *c_val, value v) CAMLreturn(0); } -static int device_nic_val(libxl_device_nic *c_val, value v) +static int device_nic_val(caml_gc *gc, libxl_device_nic *c_val, value v) { CAMLparam1(v); int i; @@ -185,7 +192,7 @@ out: CAMLreturn(ret); } -static int device_console_val(libxl_device_console *c_val, value v) +static int device_console_val(caml_gc *gc, libxl_device_console *c_val, value v) { CAMLparam1(v); @@ -196,7 +203,7 @@ static int device_console_val(libxl_device_console *c_val, value v) CAMLreturn(0); } -static int device_vkb_val(libxl_device_vkb *c_val, value v) +static int device_vkb_val(caml_gc *gc, libxl_device_vkb *c_val, value v) { CAMLparam1(v); @@ -206,7 +213,7 @@ static int device_vkb_val(libxl_device_vkb *c_val, value v) CAMLreturn(0); } -static int device_vfb_val(libxl_device_vfb *c_val, value v) +static int device_vfb_val(caml_gc *gc, libxl_device_vfb *c_val, value v) { CAMLparam1(v); @@ -225,7 +232,7 @@ static int device_vfb_val(libxl_device_vfb *c_val, value v) CAMLreturn(0); } -static int device_pci_val(libxl_device_pci *c_val, value v) +static int device_pci_val(caml_gc *gc, libxl_device_pci *c_val, value v) { CAMLparam1(v); @@ -238,7 +245,7 @@ static int device_pci_val(libxl_device_pci *c_val, value v) CAMLreturn(0); } -static int sched_credit_val(libxl_sched_credit *c_val, value v) +static int sched_credit_val(caml_gc *gc, libxl_sched_credit *c_val, value v) { CAMLparam1(v); c_val->weight = Int_val(Field(v, 0)); @@ -246,7 +253,7 @@ static int sched_credit_val(libxl_sched_credit *c_val, value v) CAMLreturn(0); } -static int domain_build_state_val(libxl_domain_build_state *c_val, value v) +static int domain_build_state_val(caml_gc *gc, libxl_domain_build_state *c_val, value v) { CAMLparam1(v); @@ -315,12 +322,12 @@ static value Val_physinfo(libxl_physinfo *c_val) value stub_xl_domain_make(value info) { CAMLparam1(info); - libxl_ctx ctx; struct caml_logger lg; uint32_t domid; libxl_domain_create_info c_info; int ret; + INIT_STRUCT(); - domain_create_info_val (&c_info, info); + domain_create_info_val (&gc, &c_info, info); INIT_CTX(); @@ -340,13 +347,13 @@ value stub_xl_domain_build(value info, value domid) { CAMLparam2(info, domid); CAMLlocal1(result); - libxl_ctx ctx; struct caml_logger lg; libxl_domain_build_info c_info; libxl_domain_build_state c_state; int ret; int c_domid; + INIT_STRUCT(); - domain_build_info_val (&c_info, info); + domain_build_info_val (&gc, &c_info, info); c_domid = Int_val(domid); INIT_CTX(); @@ -365,10 +372,10 @@ value stub_xl_disk_add(value info, value domid) { CAMLparam2(info, domid); libxl_device_disk c_info; - libxl_ctx ctx; struct caml_logger lg; int ret; + INIT_STRUCT(); - device_disk_val(&c_info, info); + device_disk_val(&gc, &c_info, info); c_info.domid = Int_val(domid); INIT_CTX(); @@ -383,10 +390,10 @@ value stub_xl_disk_remove(value info, value domid) { CAMLparam2(info, domid); libxl_device_disk c_info; - libxl_ctx ctx; struct caml_logger lg; int ret; + INIT_STRUCT(); - device_disk_val(&c_info, info); + device_disk_val(&gc, &c_info, info); c_info.domid = Int_val(domid); INIT_CTX(); @@ -400,11 +407,11 @@ value stub_xl_disk_remove(value info, value domid) value stub_xl_nic_add(value info, value domid) { CAMLparam2(info, domid); - libxl_ctx ctx; struct caml_logger lg; libxl_device_nic c_info; int ret; + INIT_STRUCT(); - device_nic_val(&c_info, info); + device_nic_val(&gc, &c_info, info); c_info.domid = Int_val(domid); INIT_CTX(); @@ -418,11 +425,11 @@ value stub_xl_nic_add(value info, value domid) value stub_xl_nic_remove(value info, value domid) { CAMLparam2(info, domid); - libxl_ctx ctx; struct caml_logger lg; libxl_device_nic c_info; int ret; + INIT_STRUCT(); - device_nic_val(&c_info, info); + device_nic_val(&gc, &c_info, info); c_info.domid = Int_val(domid); INIT_CTX(); @@ -436,13 +443,13 @@ value stub_xl_nic_remove(value info, value domid) value stub_xl_console_add(value info, value state, value domid) { CAMLparam3(info, state, domid); - libxl_ctx ctx; struct caml_logger lg; libxl_device_console c_info; libxl_domain_build_state c_state; int ret; + INIT_STRUCT(); - device_console_val(&c_info, info); - domain_build_state_val(&c_state, state); + device_console_val(&gc, &c_info, info); + domain_build_state_val(&gc, &c_state, state); c_info.domid = Int_val(domid); c_info.build_state = &c_state; @@ -457,11 +464,11 @@ value stub_xl_console_add(value info, value state, value domid) value stub_xl_vkb_add(value info, value domid) { CAMLparam2(info, domid); - libxl_ctx ctx; struct caml_logger lg; libxl_device_vkb c_info; int ret; + INIT_STRUCT(); - device_vkb_val(&c_info, info); + device_vkb_val(&gc, &c_info, info); c_info.domid = Int_val(domid); INIT_CTX(); @@ -476,8 +483,8 @@ value stub_xl_vkb_add(value info, value domid) value stub_xl_vkb_clean_shutdown(value domid) { CAMLparam1(domid); - libxl_ctx ctx; struct caml_logger lg; int ret; + INIT_STRUCT(); INIT_CTX(); ret = libxl_device_vkb_clean_shutdown(&ctx, Int_val(domid)); @@ -491,8 +498,8 @@ value stub_xl_vkb_clean_shutdown(value domid) value stub_xl_vkb_hard_shutdown(value domid) { CAMLparam1(domid); - libxl_ctx ctx; struct caml_logger lg; int ret; + INIT_STRUCT(); INIT_CTX(); ret = libxl_device_vkb_hard_shutdown(&ctx, Int_val(domid)); @@ -506,11 +513,11 @@ value stub_xl_vkb_hard_shutdown(value domid) value stub_xl_vfb_add(value info, value domid) { CAMLparam2(info, domid); - libxl_ctx ctx; struct caml_logger lg; libxl_device_vfb c_info; int ret; + INIT_STRUCT(); - device_vfb_val(&c_info, info); + device_vfb_val(&gc, &c_info, info); c_info.domid = Int_val(domid); INIT_CTX(); @@ -525,8 +532,8 @@ value stub_xl_vfb_add(value info, value domid) value stub_xl_vfb_clean_shutdown(value domid) { CAMLparam1(domid); - libxl_ctx ctx; struct caml_logger lg; int ret; + INIT_STRUCT(); INIT_CTX(); ret = libxl_device_vfb_clean_shutdown(&ctx, Int_val(domid)); @@ -540,8 +547,8 @@ value stub_xl_vfb_clean_shutdown(value domid) value stub_xl_vfb_hard_shutdown(value domid) { CAMLparam1(domid); - libxl_ctx ctx; struct caml_logger lg; int ret; + INIT_STRUCT(); INIT_CTX(); ret = libxl_device_vfb_hard_shutdown(&ctx, Int_val(domid)); @@ -555,11 +562,11 @@ value stub_xl_vfb_hard_shutdown(value domid) value stub_xl_pci_add(value info, value domid) { CAMLparam2(info, domid); - libxl_ctx ctx; struct caml_logger lg; libxl_device_pci c_info; int ret; + INIT_STRUCT(); - device_pci_val(&c_info, info); + device_pci_val(&gc, &c_info, info); INIT_CTX(); ret = libxl_device_pci_add(&ctx, Int_val(domid), &c_info); @@ -573,11 +580,11 @@ value stub_xl_pci_add(value info, value domid) value stub_xl_pci_remove(value info, value domid) { CAMLparam2(info, domid); - libxl_ctx ctx; struct caml_logger lg; libxl_device_pci c_info; int ret; + INIT_STRUCT(); - device_pci_val(&c_info, info); + device_pci_val(&gc, &c_info, info); INIT_CTX(); ret = libxl_device_pci_remove(&ctx, Int_val(domid), &c_info); @@ -591,8 +598,8 @@ value stub_xl_pci_remove(value info, value domid) value stub_xl_pci_shutdown(value domid) { CAMLparam1(domid); - libxl_ctx ctx; struct caml_logger lg; int ret; + INIT_STRUCT(); INIT_CTX(); ret = libxl_device_pci_shutdown(&ctx, Int_val(domid)); @@ -606,8 +613,8 @@ value stub_xl_pci_shutdown(value domid) value stub_xl_button_press(value domid, value button) { CAMLparam2(domid, button); - libxl_ctx ctx; struct caml_logger lg; int ret; + INIT_STRUCT(); INIT_CTX(); ret = libxl_button_press(&ctx, Int_val(domid), Int_val(button) + POWER_BUTTON); @@ -622,9 +629,9 @@ value stub_xl_physinfo(value unit) { CAMLparam1(unit); CAMLlocal1(physinfo); - libxl_ctx ctx; struct caml_logger lg; libxl_physinfo c_physinfo; int ret; + INIT_STRUCT(); INIT_CTX(); ret = libxl_get_physinfo(&ctx, &c_physinfo); @@ -640,9 +647,9 @@ value stub_xl_sched_credit_domain_get(value domid) { CAMLparam1(domid); CAMLlocal1(scinfo); - libxl_ctx ctx; struct caml_logger lg; libxl_sched_credit c_scinfo; int ret; + INIT_STRUCT(); INIT_CTX(); ret = libxl_sched_credit_domain_get(&ctx, Int_val(domid), &c_scinfo); @@ -657,11 +664,11 @@ value stub_xl_sched_credit_domain_get(value domid) value stub_xl_sched_credit_domain_set(value domid, value scinfo) { CAMLparam2(domid, scinfo); - libxl_ctx ctx; struct caml_logger lg; libxl_sched_credit c_scinfo; int ret; + INIT_STRUCT(); - sched_credit_val(&c_scinfo, scinfo); + sched_credit_val(&gc, &c_scinfo, scinfo); INIT_CTX(); ret = libxl_sched_credit_domain_set(&ctx, Int_val(domid), &c_scinfo); @@ -689,8 +696,8 @@ value stub_xl_send_trigger(value domid, value trigger, value vcpuid) value stub_xl_send_sysrq(value domid, value sysrq) { CAMLparam2(domid, sysrq); - libxl_ctx ctx; struct caml_logger lg; int ret; + INIT_STRUCT(); INIT_CTX(); ret = libxl_send_sysrq(&ctx, Int_val(domid), Int_val(sysrq)); @@ -703,8 +710,8 @@ value stub_xl_send_sysrq(value domid, value sysrq) value stub_xl_send_debug_keys(value keys) { CAMLparam1(keys); - libxl_ctx ctx; struct caml_logger lg; int ret; + INIT_STRUCT(); INIT_CTX(); ret = libxl_send_debug_keys(&ctx, String_val(keys)); -- 1.7.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Aug-10 15:12 UTC
[Xen-devel] [PATCH 3/5] use new functions to get elements out of ocaml values.
Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com> --- tools/ocaml/libs/xl/xl_stubs.c | 66 +++++++++++++++++++++++++-------------- 1 files changed, 42 insertions(+), 24 deletions(-) diff --git a/tools/ocaml/libs/xl/xl_stubs.c b/tools/ocaml/libs/xl/xl_stubs.c index 42f2637..7ba9272 100644 --- a/tools/ocaml/libs/xl/xl_stubs.c +++ b/tools/ocaml/libs/xl/xl_stubs.c @@ -65,6 +65,18 @@ void log_destroy(struct xentoollog_logger *logger) #define FREE_CTX() \ libxl_ctx_free(&ctx) +static void * gc_calloc(caml_gc *gc, size_t nmemb, size_t size) +{ + void *ptr; + ptr = calloc(nmemb, size); + return ptr; +} + +static char * dup_String_val(caml_gc *gc, value s) +{ + return String_val(s); +} + void failwith_xl(char *fname, struct caml_logger *lg) { char *s; @@ -81,13 +93,13 @@ static int string_string_tuple_array_val (caml_gc *gc, char ***c_val, value v) for (i = 0, a = Field(v, 5); a != Val_emptylist; a = Field(a, 1)) { i++; } - array = calloc((i + 1) * 2, sizeof(char *)); + array = gc_calloc(gc, (i + 1) * 2, sizeof(char *)); if (!array) return 1; for (i = 0, a = Field(v, 5); a != Val_emptylist; a = Field(a, 1), i++) { value b = Field(a, 0); - array[i * 2] = String_val(Field(b, 0)); - array[i * 2 + 1] = String_val(Field(b, 1)); + array[i * 2] = dup_String_val(gc, Field(b, 0)); + array[i * 2 + 1] = dup_String_val(gc, Field(b, 1)); } *c_val = array; CAMLreturn(0); @@ -103,7 +115,7 @@ static int domain_create_info_val (caml_gc *gc, libxl_domain_create_info *c_val, c_val->hap = Bool_val(Field(v, 1)); c_val->oos = Bool_val(Field(v, 2)); c_val->ssidref = Int32_val(Field(v, 3)); - c_val->name = String_val(Field(v, 4)); + c_val->name = dup_String_val(gc, Field(v, 4)); a = Field(v, 5); for (i = 0; i < 16; i++) c_val->uuid[i] = Int_val(Field(a, i)); @@ -111,7 +123,7 @@ static int domain_create_info_val (caml_gc *gc, libxl_domain_create_info *c_val, string_string_tuple_array_val(gc, &(c_val->platformdata), Field(v, 7)); c_val->poolid = Int32_val(Field(v, 8)); - c_val->poolname = String_val(Field(v, 9)); + c_val->poolname = dup_String_val(gc, Field(v, 9)); CAMLreturn(0); } @@ -127,7 +139,7 @@ static int domain_build_info_val (caml_gc *gc, libxl_domain_build_info *c_val, v c_val->target_memkb = Int64_val(Field(v, 3)); c_val->video_memkb = Int64_val(Field(v, 4)); c_val->shadow_memkb = Int64_val(Field(v, 5)); - c_val->kernel.path = String_val(Field(v, 6)); + c_val->kernel.path = dup_String_val(gc, Field(v, 6)); c_val->hvm = Tag_val(Field(v, 7)) == 0; infopriv = Field(Field(v, 7), 0); if (c_val->hvm) { @@ -136,15 +148,15 @@ static int domain_build_info_val (caml_gc *gc, libxl_domain_build_info *c_val, v c_val->u.hvm.acpi = Bool_val(Field(infopriv, 2)); c_val->u.hvm.nx = Bool_val(Field(infopriv, 3)); c_val->u.hvm.viridian = Bool_val(Field(infopriv, 4)); - c_val->u.hvm.timeoffset = String_val(Field(infopriv, 5)); + c_val->u.hvm.timeoffset = dup_String_val(gc, Field(infopriv, 5)); c_val->u.hvm.timer_mode = Int_val(Field(infopriv, 6)); c_val->u.hvm.hpet = Int_val(Field(infopriv, 7)); c_val->u.hvm.vpt_align = Int_val(Field(infopriv, 8)); } else { c_val->u.pv.slack_memkb = Int64_val(Field(infopriv, 0)); - c_val->u.pv.cmdline = String_val(Field(infopriv, 1)); - c_val->u.pv.ramdisk.path = String_val(Field(infopriv, 2)); - c_val->u.pv.features = String_val(Field(infopriv, 3)); + c_val->u.pv.cmdline = dup_String_val(gc, Field(infopriv, 1)); + c_val->u.pv.ramdisk.path = dup_String_val(gc, Field(infopriv, 2)); + c_val->u.pv.features = dup_String_val(gc, Field(infopriv, 3)); } CAMLreturn(0); @@ -155,9 +167,9 @@ static int device_disk_val(caml_gc *gc, libxl_device_disk *c_val, value v) CAMLparam1(v); c_val->backend_domid = Int_val(Field(v, 0)); - c_val->physpath = String_val(Field(v, 1)); + c_val->physpath = dup_String_val(gc, Field(v, 1)); c_val->phystype = (Int_val(Field(v, 2))) + PHYSTYPE_QCOW; - c_val->virtpath = String_val(Field(v, 3)); + c_val->virtpath = dup_String_val(gc, Field(v, 3)); c_val->unpluggable = Bool_val(Field(v, 4)); c_val->readwrite = Bool_val(Field(v, 5)); c_val->is_cdrom = Bool_val(Field(v, 6)); @@ -173,7 +185,7 @@ static int device_nic_val(caml_gc *gc, libxl_device_nic *c_val, value v) c_val->backend_domid = Int_val(Field(v, 0)); c_val->devid = Int_val(Field(v, 1)); c_val->mtu = Int_val(Field(v, 2)); - c_val->model = String_val(Field(v, 3)); + c_val->model = dup_String_val(gc, Field(v, 3)); if (Wosize_val(Field(v, 4)) != 6) { ret = 1; @@ -183,9 +195,9 @@ static int device_nic_val(caml_gc *gc, libxl_device_nic *c_val, value v) c_val->mac[i] = Int_val(Field(Field(v, 4), i)); /* not handling c_val->ip */ - c_val->bridge = String_val(Field(v, 5)); - c_val->ifname = String_val(Field(v, 6)); - c_val->script = String_val(Field(v, 7)); + c_val->bridge = dup_String_val(gc, Field(v, 5)); + c_val->ifname = dup_String_val(gc, Field(v, 6)); + c_val->script = dup_String_val(gc, Field(v, 7)); c_val->nictype = (Int_val(Field(v, 8))) + NICTYPE_IOEMU; out: @@ -220,14 +232,14 @@ static int device_vfb_val(caml_gc *gc, libxl_device_vfb *c_val, value v) c_val->backend_domid = Int_val(Field(v, 0)); c_val->devid = Int_val(Field(v, 1)); c_val->vnc = Bool_val(Field(v, 2)); - c_val->vnclisten = String_val(Field(v, 3)); - c_val->vncpasswd = String_val(Field(v, 4)); + c_val->vnclisten = dup_String_val(gc, Field(v, 3)); + c_val->vncpasswd = dup_String_val(gc, Field(v, 4)); c_val->vncdisplay = Int_val(Field(v, 5)); - c_val->keymap = String_val(Field(v, 6)); + c_val->keymap = dup_String_val(gc, Field(v, 6)); c_val->sdl = Bool_val(Field(v, 7)); c_val->opengl = Bool_val(Field(v, 8)); - c_val->display = String_val(Field(v, 9)); - c_val->xauthority = String_val(Field(v, 10)); + c_val->display = dup_String_val(gc, Field(v, 9)); + c_val->xauthority = dup_String_val(gc, Field(v, 10)); CAMLreturn(0); } @@ -682,11 +694,14 @@ value stub_xl_sched_credit_domain_set(value domid, value scinfo) value stub_xl_send_trigger(value domid, value trigger, value vcpuid) { CAMLparam3(domid, trigger, vcpuid); - libxl_ctx ctx; struct caml_logger lg; int ret; + char *c_trigger; + INIT_STRUCT(); + + c_trigger = dup_String_val(&gc, trigger); INIT_CTX(); - ret = libxl_send_trigger(&ctx, Int_val(domid), String_val(trigger), Int_val(vcpuid)); + ret = libxl_send_trigger(&ctx, Int_val(domid), c_trigger, Int_val(vcpuid)); if (ret != 0) failwith_xl("send_trigger", &lg); FREE_CTX(); @@ -711,10 +726,13 @@ value stub_xl_send_debug_keys(value keys) { CAMLparam1(keys); int ret; + char *c_keys; INIT_STRUCT(); + c_keys = dup_String_val(&gc, keys); + INIT_CTX(); - ret = libxl_send_debug_keys(&ctx, String_val(keys)); + ret = libxl_send_debug_keys(&ctx, c_keys); if (ret != 0) failwith_xl("send_debug_keys", &lg); FREE_CTX(); -- 1.7.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Aug-10 15:12 UTC
[Xen-devel] [PATCH 4/5] use new gc functions to deep copy structure and only free once the gc.
Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com> --- tools/ocaml/libs/xl/xl_stubs.c | 25 +++++++++++++++++++++---- 1 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/ocaml/libs/xl/xl_stubs.c b/tools/ocaml/libs/xl/xl_stubs.c index 7ba9272..8134e8e 100644 --- a/tools/ocaml/libs/xl/xl_stubs.c +++ b/tools/ocaml/libs/xl/xl_stubs.c @@ -63,18 +63,38 @@ void log_destroy(struct xentoollog_logger *logger) failwith_xl("cannot init context", &lg); #define FREE_CTX() \ + gc_free(&gc); \ libxl_ctx_free(&ctx) static void * gc_calloc(caml_gc *gc, size_t nmemb, size_t size) { void *ptr; ptr = calloc(nmemb, size); + if (!ptr) + caml_raise_out_of_memory(); + gc->ptrs[gc->offset++] = ptr; return ptr; } static char * dup_String_val(caml_gc *gc, value s) { - return String_val(s); + int len; + char *c; + len = caml_string_length(s); + c = calloc(len + 1, sizeof(char)); + if (!c) + caml_raise_out_of_memory(); + gc->ptrs[gc->offset++] = c; + memcpy(c, String_val(s), len); + return c; +} + +static void gc_free(caml_gc *gc) +{ + int i; + for (i = 0; i < gc->offset; i++) { + free(gc->ptrs[i]); + } } void failwith_xl(char *fname, struct caml_logger *lg) @@ -349,9 +369,6 @@ value stub_xl_domain_make(value info) FREE_CTX(); - free(c_info.xsdata); - free(c_info.platformdata); - CAMLreturn(Val_int(domid)); } -- 1.7.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Aug-10 15:12 UTC
[Xen-devel] [PATCH 5/5] always drop the caml lock during any xl operations.
Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com> --- tools/ocaml/libs/xl/xl_stubs.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/tools/ocaml/libs/xl/xl_stubs.c b/tools/ocaml/libs/xl/xl_stubs.c index 8134e8e..2f8401d 100644 --- a/tools/ocaml/libs/xl/xl_stubs.c +++ b/tools/ocaml/libs/xl/xl_stubs.c @@ -58,12 +58,14 @@ void log_destroy(struct xentoollog_logger *logger) lg.logger.vmessage = log_vmessage; \ lg.logger.destroy = log_destroy; \ lg.logger.progress = NULL; \ + caml_enter_blocking_section(); \ ret = libxl_ctx_init(&ctx, LIBXL_VERSION, (struct xentoollog_logger *) &lg); \ if (ret != 0) \ failwith_xl("cannot init context", &lg); #define FREE_CTX() \ gc_free(&gc); \ + caml_leave_blocking_section(); \ libxl_ctx_free(&ctx) static void * gc_calloc(caml_gc *gc, size_t nmemb, size_t size) -- 1.7.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Aug-10 15:14 UTC
Re: [Xen-devel] [PATCH 0/5] xl ocaml: drop lock in the bindings
On 10/08/10 15:29, Stefano Stabellini wrote:> If you are sending a patch series using an automated tool, I would > appreciate if you could use inline patches, so that I can save the > messages and use hg import on them. > I don''t mind attachments if they contain the comments as long with the > diffs. > Thanks in advance,I''ve resent with inlines patches. -- Vincent _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Stefano Stabellini
2010-Aug-10 15:36 UTC
Re: [Xen-devel] [PATCH 0/5] xl ocaml: drop lock in the bindings
On Tue, 10 Aug 2010, Vincent Hanquez wrote:> On 10/08/10 15:29, Stefano Stabellini wrote: > > If you are sending a patch series using an automated tool, I would > > appreciate if you could use inline patches, so that I can save the > > messages and use hg import on them. > > I don''t mind attachments if they contain the comments as long with the > > diffs. > > Thanks in advance, > > I''ve resent with inlines patches. >thanks :) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel