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

Re: [PATCH v2 2/4] tools/ocaml/libs/xc: add binding to xc_evtchn_status


  • To: Edwin Torok <edvin.torok@xxxxxxxxxx>
  • From: Christian Lindig <christian.lindig@xxxxxxxxxx>
  • Date: Fri, 2 Dec 2022 12:59:43 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kCNMn91rUFBoREjyeIr1z8a4VlB1peWbRnROpK7YngY=; b=QneEVNGkM/X8SaWYAVUGCUkNLO1o2G81/OlORW/p9ZWL6acSKuFmY461s09xF+g5xbH8pNIhBDiWhz99fsjIzsY3iXZT2B1DKpdbnthwLiiVvGxeYirFdV861Bzj5PW/0zaHGR7KSQ1Sr3yoN0iAmobaObHmsKuMU/el6fUqtk5opK3CADOWQufVAlPLDgKHiWOpOBAL8H2LXr9ohlpdP0pQVN9BlX32fHsoZjB8gSzFdPsn9Sr/lYytwk9zha/Lal0yYu2+iFk6DtZCyQLARgucUe2SmHKbFmlW8cfQdHDJXlzn1jOKZjKHAIwCSNDJEQmQCNzccyfBELzmBJJtKQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J8+fxDGBsIjiMb3TULqSTJvaeptItVPEbvlrRDwsD3x1xgDmREt7BNLi3pvQwyPlRCjBf5zzNoqDeS1yeDGS2bi1a9a8vjLm8HOTw0nDfCYo+PNylwt/JYtdyGvr4/C85wxeK4GyWvsIdmRC/TmkTBhRh/Kv+4FaVg5FPngckkW62DaTX/G91aZh2qrDutMns0a1jHNIX18yu04y2Ao+J8Saawd0ph71okrQwNA6K0FNDDCCuFWOCbCCZxplqwncT0VmKWcpx2P3eV2bBS3+hwEOtCgxzBJbl61s4MnlhlwCm2drNazF5Fb23RfXVaKU+B9J2TF/jxMs+sy01Ee0Sg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Anthony Perard <anthony.perard@xxxxxxxxxx>
  • Delivery-date: Fri, 02 Dec 2022 12:59:53 +0000
  • Ironport-data: A9a23:toGvWK38VhOFvoqAq/bD5fFwkn2cJEfYwER7XKvMYLTBsI5bp2NTy 2MbWGHUbqmPa2LyLdh3bISxoUxV6MTRztJmSgJvpC1hF35El5HIVI+TRqvS04F+DeWYFR46s J9OAjXkBJppJpMJjk71atANlVEliefTAOK5ULSfUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tq3qMDEULOf82cc3lk8tuTS9nuDgNyo4GlC5wZmP6gR1LPjvyJ94Kw3dPnZw0TQGuG4LsbiL 87fwbew+H/u/htFIrtJRZ6iLyXm6paLVeS/oiI+t5qK23CulQRrukoPD9IOaF8/ttm8t4sZJ OOhF3CHYVxB0qXkwIzxWvTDes10FfUuFLTveRBTvSEPpqFvnrSFL/hGVSkL0YMkFulfW1xJ9 ccZLSg3dBGAotmw3byRRPRtr5F2RCXrFNt3VnBI6xj8VapjZK+ZBqLA6JlfwSs6gd1IEbDGf c0FZDFzbRPGJRpSJlMQD5F4l+Ct7pX9W2QA9BTJ+uxouC6Kk1IZPLvFabI5fvSBRd9UhVqZr 2SA+2X/DhAVHNee1SCE4jSngeqncSbTCNxISeDoqKECbFu7+DA5ERopW3iHmLqhp0+xQNkCN 2BL9X97xUQ13AnxJjXnZDWorXjBshMCVt54F+wh9BrL2qfS+xyeBGUPUnhGctNOnMM/WzECz FKCmNLtQzt1v9W9Vna15rqS6zSoNkAowXQqYCYFSU4A/IPlqYRr0hbXFI88Tuiyk8H/Hiz2z 3aSti8iir4PjMkNkaKm4VTAhDHqrZ/MJuIo2jjqsquexlsRTOaYi0aAsDA3Md4owF6lc2S8
  • Ironport-hdrordr: A9a23:omvoMaPijBrZg8BcT7T255DYdb4zR+YMi2TDj3oBOiC9t/bo4P xHnJwgpGTJYUUqKSMdcLG7Sfy9qBbnnqKdjrNhQotKMDOWwVdAabsSnbcKoAeQVBEWlNQtq5 uIGpIWYLedYjkb/KGKhjVQUexQseVvmJrYxNs2pE0dNz2CHpsQkzuRfTzrb3GeKjM2fabRIK DspvZvln6NaH4TZsS+CmIlWfLfq9DwlJzgaQMbHBI8rC2Dlymh5rLCCB6T0g0FXz4n+8ZAzU H11yDp7KCqs/W20T/ZznTS6Il/ksbgzNwrPr3ptuElbhn8gAOhZIBsQJ2HpSs0p/yL4Esnl9 Pdyi1QWvhb2jf8b2uxqRvo1xLYyzA++1rr1FOei2uLm72aeNt2MbsGuWqXGiGpp3bJEbpHvZ 5j7ia8jd56HBnAlCPy65zhUAxrrFO9pT4YnesanxVkIMAjgOs6l+Ii1XIQNK1FMDPx6YghHu UrJtrb/uxqfVSTaG2clnVzwfS3N05DQSuucwwngIi4wjJWlHd2ww8z38oEhEoN85o7Vt1t+/ nECKJ1j7tDJ/VmMZ6VPN1xH/dfN1a9Gy4kcVjiemgPLZt3Y04lfqSHvYnc54mRCdQ1JdUJ6d qxAW+xcwYJCgHT4Ia1re92Gyv2MSyAte6E8LAa23FIgMy/eFOiC1z3dLkPqbrlnxxNOLydZx 5EUKgmTsMK2gPVaMx0N4qUYegAFZHLO/dl6urTHWj++/4iJuDRx5jmmd7oVczQLQo=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZBjy4uYcsvtJBLk2Ois95vQpMr65aj2kA
  • Thread-topic: [PATCH v2 2/4] tools/ocaml/libs/xc: add binding to xc_evtchn_status


> On 2 Dec 2022, at 10:55, Edwin Török <edvin.torok@xxxxxxxxxx> wrote:
> 
> There is no API or ioctl to query event channel status, it is only
> present in xenctrl.h
> 
> The C union is mapped to an OCaml variant exposing just the value from the
> correct union tag.
> 
> The information provided here is similar to 'lsevtchn', but rather than
> parsing its output it queries the underlying API directly.
> 
> Signed-off-by: Edwin Török <edvin.torok@xxxxxxxxxx>

Acked-by: Christian Lindig <christian.lindig@xxxxxxxxxx>

> ---
> Changes since v1:
> * drop paragraph about where this is used
> * add comment about max port
> * use Xeneventchn.virq_t instead of int, add a dependency: xc -> eventchn
> * initialize struct without memset-ing first
> * use 2 CAMLreturn, I found an example in the OCaml stdlib that does that so 
> should be future-proof 
> https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Focaml%2Focaml%2Fblob%2F663e8d219f566095e3a9497c5bae07b6a95cae39%2Fotherlibs%2Funix%2Fdup_win32.c%23L52-L77&amp;data=05%7C01%7Cchristian.lindig%40citrix.com%7C7d476fd71ea14746b08f08dad453d946%7C335836de42ef43a2b145348c2ee9ca5b%7C0%7C0%7C638055753844059822%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=c97tdCv0VPS7UBPoLJXf3geZKQq0AkhjWuA1wq2ZUW0%3D&amp;reserved=0
> * use Tag_some, defining it if needed
> * fix typo on failwith
> ---
> tools/ocaml/libs/Makefile           |  2 +-
> tools/ocaml/libs/xc/META.in         |  2 +-
> tools/ocaml/libs/xc/Makefile        |  2 +-
> tools/ocaml/libs/xc/xenctrl.ml      | 15 +++++++
> tools/ocaml/libs/xc/xenctrl.mli     | 15 +++++++
> tools/ocaml/libs/xc/xenctrl_stubs.c | 67 +++++++++++++++++++++++++++++
> 6 files changed, 100 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/ocaml/libs/Makefile b/tools/ocaml/libs/Makefile
> index 7e7c27e2d5..15f45a6d66 100644
> --- a/tools/ocaml/libs/Makefile
> +++ b/tools/ocaml/libs/Makefile
> @@ -4,7 +4,7 @@ include $(XEN_ROOT)/tools/Rules.mk
> SUBDIRS= \
>       mmap \
>       xentoollog \
> -     xc eventchn \
> +     eventchn xc\
>       xb xs xl
> 
> .PHONY: all
> diff --git a/tools/ocaml/libs/xc/META.in b/tools/ocaml/libs/xc/META.in
> index 2ff4dcb6bf..6a273936a3 100644
> --- a/tools/ocaml/libs/xc/META.in
> +++ b/tools/ocaml/libs/xc/META.in
> @@ -1,5 +1,5 @@
> version = "@VERSION@"
> description = "Xen Control Interface"
> -requires = "unix,xenmmap"
> +requires = "unix,xenmmap,xeneventchn"
> archive(byte) = "xenctrl.cma"
> archive(native) = "xenctrl.cmxa"
> diff --git a/tools/ocaml/libs/xc/Makefile b/tools/ocaml/libs/xc/Makefile
> index 3b76e9ad7b..1d9fecb06e 100644
> --- a/tools/ocaml/libs/xc/Makefile
> +++ b/tools/ocaml/libs/xc/Makefile
> @@ -4,7 +4,7 @@ include $(OCAML_TOPLEVEL)/common.make
> 
> CFLAGS += -I../mmap $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest)
> CFLAGS += $(APPEND_CFLAGS)
> -OCAMLINCLUDE += -I ../mmap
> +OCAMLINCLUDE += -I ../mmap -I ../eventchn
> 
> OBJS = xenctrl
> INTF = xenctrl.cmi
> diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml
> index 2ed7454b16..5dac47991e 100644
> --- a/tools/ocaml/libs/xc/xenctrl.ml
> +++ b/tools/ocaml/libs/xc/xenctrl.ml
> @@ -267,6 +267,21 @@ external evtchn_alloc_unbound: handle -> domid -> domid 
> -> int
>   = "stub_xc_evtchn_alloc_unbound"
> external evtchn_reset: handle -> domid -> unit = "stub_xc_evtchn_reset"
> 
> +(* FIFO has theoretical maximum of 2^28 ports, fits in an int *)
> +type evtchn_interdomain = { dom: domid; port: int}
> +
> +type evtchn_stat =
> +  | EVTCHNSTAT_unbound of domid
> +  | EVTCHNSTAT_interdomain of evtchn_interdomain
> +  | EVTCHNSTAT_pirq of int
> +  | EVTCHNSTAT_virq of Xeneventchn.virq_t
> +  | EVTCHNSTAT_ipi
> +
> +type evtchn_status = { vcpu: int; status: evtchn_stat }
> +
> +external evtchn_status: handle -> domid -> int -> evtchn_status option =
> +  "stub_xc_evtchn_status"
> +
> external readconsolering: handle -> string = "stub_xc_readconsolering"
> 
> external send_debug_keys: handle -> string -> unit = "stub_xc_send_debug_keys"
> diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.mli
> index 0f80aafea0..6c9206bc74 100644
> --- a/tools/ocaml/libs/xc/xenctrl.mli
> +++ b/tools/ocaml/libs/xc/xenctrl.mli
> @@ -206,6 +206,21 @@ external shadow_allocation_get : handle -> domid -> int
> external evtchn_alloc_unbound : handle -> domid -> domid -> int
>   = "stub_xc_evtchn_alloc_unbound"
> external evtchn_reset : handle -> domid -> unit = "stub_xc_evtchn_reset"
> +
> +type evtchn_interdomain = { dom: domid; port: int}
> +
> +type evtchn_stat =
> +  | EVTCHNSTAT_unbound of domid
> +  | EVTCHNSTAT_interdomain of evtchn_interdomain
> +  | EVTCHNSTAT_pirq of int
> +  | EVTCHNSTAT_virq of Xeneventchn.virq_t
> +  | EVTCHNSTAT_ipi
> +
> +type evtchn_status = { vcpu: int; status: evtchn_stat }
> +
> +external evtchn_status: handle -> domid -> int -> evtchn_status option =
> +  "stub_xc_evtchn_status"
> +
> external readconsolering : handle -> string = "stub_xc_readconsolering"
> external send_debug_keys : handle -> string -> unit = 
> "stub_xc_send_debug_keys"
> external physinfo : handle -> physinfo = "stub_xc_physinfo"
> diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c 
> b/tools/ocaml/libs/xc/xenctrl_stubs.c
> index d30585f21c..a492ea17fd 100644
> --- a/tools/ocaml/libs/xc/xenctrl_stubs.c
> +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
> @@ -44,6 +44,10 @@
> #define Val_none (Val_int(0))
> #endif
> 
> +#ifndef Tag_some
> +#define Tag_some 0
> +#endif
> +
> #define string_of_option_array(array, index) \
>     ((Field(array, index) == Val_none) ? NULL : String_val(Field(Field(array, 
> index), 0)))
> 
> @@ -641,6 +645,69 @@ CAMLprim value stub_xc_evtchn_reset(value xch, value 
> domid)
>     CAMLreturn(Val_unit);
> }
> 
> +CAMLprim value stub_xc_evtchn_status(value xch, value domid, value port)
> +{
> +    CAMLparam3(xch, domid, port);
> +    CAMLlocal4(result, result_status, stat, interdomain);
> +    xc_evtchn_status_t status = {
> +        .dom = _D(domid),
> +        .port = Int_val(port),
> +    };
> +    int rc;
> +
> +    caml_enter_blocking_section();
> +    rc = xc_evtchn_status(_H(xch), &status);
> +    caml_leave_blocking_section();
> +
> +    if ( rc < 0 )
> +        failwith_xc(_H(xch));
> +
> +    if ( status.status == EVTCHNSTAT_closed )
> +        CAMLreturn(Val_none);

Could this case be handled in the switch, too?

> +
> +    switch ( status.status )
> +    {
> +    case EVTCHNSTAT_unbound:
> +        stat = caml_alloc(1, 0); /* 1st non-constant constructor */
> +        Store_field(stat, 0, Val_int(status.u.unbound.dom));
> +        break;
> +
> +    case EVTCHNSTAT_interdomain:
> +        interdomain = caml_alloc_tuple(2);
> +        Store_field(interdomain, 0, Val_int(status.u.interdomain.dom));
> +        Store_field(interdomain, 1, Val_int(status.u.interdomain.port));
> +        stat = caml_alloc(1, 1); /*  2nd non-constant constructor */
> +        Store_field(stat, 0, interdomain);
> +        break;
> +    case EVTCHNSTAT_pirq:
> +        stat = caml_alloc(1, 2); /* 3rd non-constant constructor */
> +        Store_field(stat, 0, Val_int(status.u.pirq));
> +        break;
> +
> +    case EVTCHNSTAT_virq:
> +        stat = caml_alloc(1, 3); /* 4th non-constant constructor */
> +        Store_field(stat, 0, Val_int(status.u.virq));
> +        break;
> +
> +    case EVTCHNSTAT_ipi:
> +        stat = Val_int(0); /* 1st constant constructor */
> +        break;
> +
> +    default:
> +        caml_failwith("Unknown evtchn status");
> +
> +    }
> +    result_status = caml_alloc_tuple(2);
> +    Store_field(result_status, 0, Val_int(status.vcpu));
> +    Store_field(result_status, 1, stat);
> +
> +    /* caml_alloc_some is missing in older versions of OCaml
> +     */
> +    result = caml_alloc_small(1, Tag_some);
> +    Store_field(result, 0, result_status);
> +
> +    CAMLreturn(result);
> +}
> 
> CAMLprim value stub_xc_readconsolering(value xch)
> {
> -- 
> 2.34.1
> 


 


Rackspace

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