All of lore.kernel.org
 help / color / mirror / Atom feed
* interdomain event channel using libxc
@ 2006-12-01 13:38 Stephan Creutz
  2006-12-01 14:17 ` Keir Fraser
  2007-11-12 17:06 ` Francesco Tamberi
  0 siblings, 2 replies; 5+ messages in thread
From: Stephan Creutz @ 2006-12-01 13:38 UTC (permalink / raw)
  To: xen-devel


[-- Attachment #1.1: Type: text/plain, Size: 4072 bytes --]

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;
}

[-- Attachment #1.2: Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-11-12 17:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-01 13:38 interdomain event channel using libxc Stephan Creutz
2006-12-01 14:17 ` Keir Fraser
2006-12-01 14:28   ` Keir Fraser
2006-12-04 17:59     ` Stephan Creutz
2007-11-12 17:06 ` Francesco Tamberi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.