Hi, I have two processes each running in separate domains. One of them should notify the other process about an event. To achieve this I use an interdomain event channel by using functions which I found in libxc (or libxen). To demonstrate the problem I have two minimal programs (see below). The first one is running in Dom0, it allocates a port, print it to the console and waits per select for a notification. The second one reads the first parameter (which is the remote port), establishes an interdomain event channel and notifies the program running in Dom0. When I run these programs (the Dom0 program first and the DomU one next) nothing happens. The process in Dom0 is blocked in select until the timeout occures. No error messages are displayed (which has nothing to say, except my own ignorance). What I am doing or getting wrong? Can somebody help me, please? Regards, Stephan Creutz P.S.: I am using XEN 3.0.3 and sorry for my bad english. Program running in Dom0: #include <stdio.h> #include <time.h> #include <sys/select.h> #include <xen/xenctrl.h> static int xc_handle = -1; static void event_channel(uint32_t domid) { int xce_handle = xc_evtchn_open(); if (xce_handle == -1) { fprintf(stderr, "opening event channel failed\n"); return; } int port = xc_evtchn_alloc_unbound(xc_handle, DOMID_SELF, domid); if (port == -1) fprintf(stderr, "port allocation failed\n"); else printf("allocated port: %d\n", port); fd_set rfds; FD_ZERO(&rfds); int evtchn_fd = xc_evtchn_fd(xce_handle); FD_SET(evtchn_fd, &rfds); struct timeval select_timeout = { .tv_sec = 10, .tv_usec = 0 }; if (xc_evtchn_unmask(xce_handle, (evtchn_port_t)port) == -1) fprintf(stderr, "unmasking failed\n"); printf(">>> select\n"); int ret = select(evtchn_fd + 1, &rfds, NULL, NULL, &select_timeout); if (ret == -1) perror("select()"); else if (ret && FD_ISSET(evtchn_fd, &rfds)) { printf(">>> event <<<\n"); evtchn_port_t next_port; if ((next_port = xc_evtchn_pending(xce_handle)) = (evtchn_port_t)-1) perror("xc_evtchn_pending"); if (xc_evtchn_unmask(xce_handle, next_port) == -1) fprintf(stderr, "unable to umask\n"); } else fprintf(stderr, "select timeout\n"); xc_evtchn_close(xce_handle); printf("eventchannel closed\n"); } int main(void) { xc_handle = xc_interface_open(); if (xc_handle == -1) { fprintf(stderr, "connection to hypervisor failed\n"); return 1; } xc_dominfo_t dominfo[2]; int number_of_domains = xc_domain_getinfo(xc_handle, 0, 2, dominfo); if (number_of_domains < 2) { fprintf(stderr, "there is only one domain, but need two\n"); goto error; } event_channel(dominfo[1].domid); error: xc_interface_close(xc_handle); return 0; } Program running in DomU: #include <stdio.h> #include <stdlib.h> #include <time.h> #include <xen/xenctrl.h> static int xc_handle = -1; static const uint32_t domid = 0; int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "usage: %s <remote-port>\n", argv[0]); return 1; } xc_handle = xc_interface_open(); if (xc_handle == -1) { fprintf(stderr, "connection to hypervisor failed\n"); return 1; } int xce_handle = xc_evtchn_open(); if (xce_handle == -1) { fprintf(stderr, "opening of event channel failed\n"); goto error; } evtchn_port_t remote_port = (evtchn_port_t)atoi(argv[1]); evtchn_port_t local_port; local_port = xc_evtchn_bind_interdomain(xce_handle, domid, remote_port); if (local_port == (evtchn_port_t)-1) fprintf(stderr, "binding to interdomain channel failed\n"); if (xc_evtchn_notify(xce_handle, local_port) == -1) fprintf(stderr, "notify failed\n"); struct timespec nano_timespec = { .tv_sec = 5, .tv_nsec = 0 }; nanosleep(&nano_timespec, NULL); if (xc_evtchn_unbind(xce_handle, local_port) == -1) fprintf(stderr, "unbind failed\n"); xc_evtchn_close(xce_handle); error: xc_interface_close(xc_handle); return 0; } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On 1/12/06 13:38, "Stephan Creutz" <stephan.creutz@inf.tu-dresden.de> wrote:> To demonstrate the problem I have two minimal programs (see below). The > first one is running in Dom0, it allocates a port, print it to the > console and waits per select for a notification. The second one reads > the first parameter (which is the remote port), establishes an > interdomain event channel and notifies the program running in Dom0. When > I run these programs (the Dom0 program first and the DomU one next) > nothing happens. The process in Dom0 is blocked in select until the > timeout occures. No error messages are displayed (which has nothing to > say, except my own ignorance). > > What I am doing or getting wrong? Can somebody help me, please?The problem is quite subtle. The libxc function xc_alloc_unbound_port() is intended to allocate an unbound port in *another* domain. It''s used only during creation of new domains. To allocate a *local* unbound port you need to define yourself a function along the lines of xc_evtchn_bind_interdomain() but using IOCTL_EVTCHN_BIND_UNBOUND_PORT rather than IOCTL_EVTCHN_BIND_INTERDOMAIN. Probably such a function should be included in libxc, and the existing xc_alloc_unbound_port() function should be given a clearer name. :-) -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On 1/12/06 14:17, "Keir Fraser" <keir@xensource.com> wrote:> Probably such a function should be included in libxc, and the existing > xc_alloc_unbound_port() function should be given a clearer name. :-)I just added a new function to xen-unstable that does what you want. It''s called xc_evtchn_bind_unbound_port() and is introduced in changeset 12694. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Stephan Creutz
2006-Dec-04 17:59 UTC
Re: [Xen-devel] interdomain event channel using libxc
On Fri, 01 Dec 2006 14:28:31 +0000 Keir Fraser <keir@xensource.com> wrote:> On 1/12/06 14:17, "Keir Fraser" <keir@xensource.com> wrote: > > > Probably such a function should be included in libxc, and the > > existing xc_alloc_unbound_port() function should be given a clearer > > name. :-) > > I just added a new function to xen-unstable that does what you want. > It''s called xc_evtchn_bind_unbound_port() and is introduced in > changeset 12694.Thank you very much, Keir. Stephan _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Francesco Tamberi
2007-Nov-12 17:06 UTC
Re: [Xen-devel] interdomain event channel using libxc
Hi, This stub works well for me, but suppose I have to "move" the domU code at "kernel level" (i.e. as a module) which hypercalls should I invoke and in what order? This is a "stupid" scheme of what I mean to do: domU --> kernel level, using hypercalls dom0 --> user level (see code below), using libxc Thanks -- f Stephan Creutz wrote:> > Hi, > > [... cut] > > Program running in Dom0: > > #include <stdio.h> > #include <time.h> > #include <sys/select.h> > #include <xen/xenctrl.h> > > static int xc_handle = -1; > > static void event_channel(uint32_t domid) > { > int xce_handle = xc_evtchn_open(); > if (xce_handle == -1) { > fprintf(stderr, "opening event channel failed\n"); > return; > } > > int port = xc_evtchn_alloc_unbound(xc_handle, DOMID_SELF, domid); > if (port == -1) > fprintf(stderr, "port allocation failed\n"); > else > printf("allocated port: %d\n", port); > > fd_set rfds; > > FD_ZERO(&rfds); > int evtchn_fd = xc_evtchn_fd(xce_handle); > FD_SET(evtchn_fd, &rfds); > > struct timeval select_timeout = { > .tv_sec = 10, > .tv_usec = 0 > }; > > if (xc_evtchn_unmask(xce_handle, (evtchn_port_t)port) == -1) > fprintf(stderr, "unmasking failed\n"); > > printf(">>> select\n"); > int ret = select(evtchn_fd + 1, &rfds, NULL, NULL, &select_timeout); > > if (ret == -1) > perror("select()"); > else if (ret && FD_ISSET(evtchn_fd, &rfds)) { > printf(">>> event <<<\n"); > evtchn_port_t next_port; > if ((next_port = xc_evtchn_pending(xce_handle)) => (evtchn_port_t)-1) > perror("xc_evtchn_pending"); > if (xc_evtchn_unmask(xce_handle, next_port) == -1) > fprintf(stderr, "unable to umask\n"); > } else > fprintf(stderr, "select timeout\n"); > > xc_evtchn_close(xce_handle); > printf("eventchannel closed\n"); > } > > int main(void) > { > xc_handle = xc_interface_open(); > if (xc_handle == -1) { > fprintf(stderr, "connection to hypervisor failed\n"); > return 1; > } > > xc_dominfo_t dominfo[2]; > int number_of_domains = xc_domain_getinfo(xc_handle, 0, 2, dominfo); > if (number_of_domains < 2) { > fprintf(stderr, "there is only one domain, but need two\n"); > goto error; > } > > event_channel(dominfo[1].domid); > > error: > xc_interface_close(xc_handle); > return 0; > } > > Program running in DomU: > > #include <stdio.h> > #include <stdlib.h> > #include <time.h> > #include <xen/xenctrl.h> > > static int xc_handle = -1; > static const uint32_t domid = 0; > > int main(int argc, char **argv) > { > if (argc < 2) { > fprintf(stderr, "usage: %s <remote-port>\n", argv[0]); > return 1; > } > > xc_handle = xc_interface_open(); > if (xc_handle == -1) { > fprintf(stderr, "connection to hypervisor failed\n"); > return 1; > } > > int xce_handle = xc_evtchn_open(); > if (xce_handle == -1) { > fprintf(stderr, "opening of event channel failed\n"); > goto error; > } > > evtchn_port_t remote_port = (evtchn_port_t)atoi(argv[1]); > evtchn_port_t local_port; > local_port = xc_evtchn_bind_interdomain(xce_handle, domid, > remote_port); if (local_port == (evtchn_port_t)-1) > fprintf(stderr, "binding to interdomain channel failed\n"); > > if (xc_evtchn_notify(xce_handle, local_port) == -1) > fprintf(stderr, "notify failed\n"); > > struct timespec nano_timespec = { > .tv_sec = 5, > .tv_nsec = 0 > }; > nanosleep(&nano_timespec, NULL); > if (xc_evtchn_unbind(xce_handle, local_port) == -1) > fprintf(stderr, "unbind failed\n"); > xc_evtchn_close(xce_handle); > > error: > xc_interface_close(xc_handle); > return 0; > } >-- View this message in context: http://www.nabble.com/interdomain-event-channel-using-libxc-tf2738572.html#a13709427 Sent from the Xen - Dev mailing list archive at Nabble.com. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel