From: ramsdell@mitre.org (John D. Ramsdell)
To: Steven Smith <sos22-xen@srcf.ucam.org>
Cc: xen-devel@lists.xensource.com, ramsdell@mitre.org,
Steven Smith <sos22@cam.ac.uk>, Grzegorz Milos <gm281@cam.ac.uk>
Subject: Re: [PATCH] Mini-OS to use evtchn_port_t for ports and other improvements
Date: 27 Jul 2006 08:56:13 -0400 [thread overview]
Message-ID: <ogt64hjkxzm.fsf@divan.mitre.org> (raw)
In-Reply-To: <20060727094920.GA4241@cam.ac.uk>
[-- Attachment #1: Type: text/plain, Size: 1585 bytes --]
Steven Smith <sos22-xen@srcf.ucam.org> writes:
> > > Why maybe_bind? ...
> That's not a bad idea, but I'd rather leave this until we have an
> example of some actual code which needs it.
Maybe bind has been eliminated.
>
> > > > + evtchn_port_t port = op.u.bind_interdomain.local_port;
> > > > + clear_evtchn(port); /* Without, handler gets invoked now! */
> > > Invoking the handler as soon as you bind the interdomain channel is
> > > a mostly-deliberate part of the interface. If the other end makes
> > > notifications before you get around to binding they can get lost,
> > > and forcing the channel to fire as soon as you bind to it avoids
> > > some potential lost wakeups.
> > It's easy to simulate the case of a handler call on binding with
> > clear_evtchn included, but a pain to handle the case in which one
> > wants the handler to be invoked only when a notification arrives,
> > when it is omitted.
> I think you have a point here. Consider my objection withdrawn.
I added the clear_evtchn back in. Here is the patch freshly minted
patch.
John
The enclosed patch modifies Mini-OS so it uses evtchn_port_t for
ports, instead of the current mixture of u32's and int's. It provides
a name for the type of an event channel handler in events.h. It
modifies evtchn_alloc_unbound so that it can be used to set up an
event channel to a domain other than zero. It adds
evtchn_bind_interdomain to support the other half of event channel set
up. Finally, it adds a routine that translates grant table operation
status values to their string equivalent.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: event channel patch --]
[-- Type: text/x-patch, Size: 10119 bytes --]
The enclosed patch modifies Mini-OS so it uses evtchn_port_t for
ports, instead of the current mixture of u32's and int's. It provides
a name for the type of an event channel handler in events.h. It
modifies evtchn_alloc_unbound so that it can be used to set up an
event channel to a domain other than zero. It adds
evtchn_bind_interdomain to support the other half of event channel set
up. Finally, adds a routine that translates grant table operation
status values to their string equivalent.
Signed-off-by: John D. Ramsdell <ramsdell@mitre.org>
Only in xen-unstable/extras/mini-os/console: console.o
diff -ur oxen-unstable/extras/mini-os/console/xencons_ring.c xen-unstable/extras/mini-os/console/xencons_ring.c
--- oxen-unstable/extras/mini-os/console/xencons_ring.c 2006-07-24 01:09:39.000000000 -0400
+++ xen-unstable/extras/mini-os/console/xencons_ring.c 2006-07-26 05:22:01.000000000 -0400
@@ -53,7 +53,7 @@
-static void handle_input(int port, struct pt_regs *regs, void *ign)
+static void handle_input(evtchn_port_t port, struct pt_regs *regs, void *ign)
{
struct xencons_interface *intf = xencons_interface();
XENCONS_RING_IDX cons, prod;
Only in xen-unstable/extras/mini-os/console: xencons_ring.o
diff -ur oxen-unstable/extras/mini-os/events.c xen-unstable/extras/mini-os/events.c
--- oxen-unstable/extras/mini-os/events.c 2006-07-24 01:09:39.000000000 -0400
+++ xen-unstable/extras/mini-os/events.c 2006-07-27 08:44:32.000000000 -0400
@@ -26,20 +26,20 @@
/* this represents a event handler. Chaining or sharing is not allowed */
typedef struct _ev_action_t {
- void (*handler)(int, struct pt_regs *, void *);
+ evtchn_handler_t handler;
void *data;
u32 count;
} ev_action_t;
static ev_action_t ev_actions[NR_EVS];
-void default_handler(int port, struct pt_regs *regs, void *data);
+void default_handler(evtchn_port_t port, struct pt_regs *regs, void *data);
/*
* Demux events to different handlers.
*/
-int do_event(u32 port, struct pt_regs *regs)
+int do_event(evtchn_port_t port, struct pt_regs *regs)
{
ev_action_t *action;
if (port >= NR_EVS) {
@@ -60,8 +60,8 @@
}
-int bind_evtchn( u32 port, void (*handler)(int, struct pt_regs *, void *),
- void *data )
+evtchn_port_t bind_evtchn(evtchn_port_t port, evtchn_handler_t handler,
+ void *data)
{
if(ev_actions[port].handler != default_handler)
printk("WARN: Handler for port %d already registered, replacing\n",
@@ -77,7 +77,7 @@
return port;
}
-void unbind_evtchn( u32 port )
+void unbind_evtchn(evtchn_port_t port)
{
if (ev_actions[port].handler == default_handler)
printk("WARN: No handler for port %d when unbinding\n", port);
@@ -86,8 +86,7 @@
ev_actions[port].data = NULL;
}
-int bind_virq( u32 virq, void (*handler)(int, struct pt_regs *, void *data),
- void *data)
+int bind_virq(uint32_t virq, evtchn_handler_t handler, void *data)
{
evtchn_op_t op;
@@ -105,11 +104,6 @@
return 0;
}
-void unbind_virq( u32 port )
-{
- unbind_evtchn(port);
-}
-
#if defined(__x86_64__)
/* Allocate 4 pages for the irqstack */
#define STACK_PAGES 4
@@ -142,32 +136,48 @@
}
}
-void default_handler(int port, struct pt_regs *regs, void *ignore)
+void default_handler(evtchn_port_t port, struct pt_regs *regs, void *ignore)
{
printk("[Port %d] - event received\n", port);
}
+/* Create a port available to the pal for exchanging notifications.
+ Returns the result of the hypervisor call. */
+
/* Unfortunate confusion of terminology: the port is unbound as far
as Xen is concerned, but we automatically bind a handler to it
from inside mini-os. */
-int evtchn_alloc_unbound(void (*handler)(int, struct pt_regs *regs,
- void *data),
- void *data)
-{
- u32 port;
- evtchn_op_t op;
- int err;
- op.cmd = EVTCHNOP_alloc_unbound;
- op.u.alloc_unbound.dom = DOMID_SELF;
- op.u.alloc_unbound.remote_dom = 0;
-
- err = HYPERVISOR_event_channel_op(&op);
- if (err) {
- printk("Failed to alloc unbound evtchn: %d.\n", err);
- return -1;
- }
- port = op.u.alloc_unbound.port;
- bind_evtchn(port, handler, data);
- return port;
+int evtchn_alloc_unbound(domid_t pal, evtchn_handler_t handler,
+ void *data, evtchn_port_t *port)
+{
+ evtchn_op_t op;
+ op.cmd = EVTCHNOP_alloc_unbound;
+ op.u.alloc_unbound.dom = DOMID_SELF;
+ op.u.alloc_unbound.remote_dom = pal;
+ int err = HYPERVISOR_event_channel_op(&op);
+ if (err)
+ return err;
+ *port = bind_evtchn(op.u.alloc_unbound.port, handler, data);
+ return err;
+}
+
+/* Connect to a port so as to allow the exchange of notifications with
+ the pal. Returns the result of the hypervisor call. */
+
+int evtchn_bind_interdomain(domid_t pal, evtchn_port_t remote_port,
+ evtchn_handler_t handler, void *data,
+ evtchn_port_t *local_port)
+{
+ evtchn_op_t op;
+ op.cmd = EVTCHNOP_bind_interdomain;
+ op.u.bind_interdomain.remote_dom = pal;
+ op.u.bind_interdomain.remote_port = remote_port;
+ int err = HYPERVISOR_event_channel_op(&op);
+ if (err)
+ return err;
+ evtchn_port_t port = op.u.bind_interdomain.local_port;
+ clear_evtchn(port); /* Without, handler gets invoked now! */
+ *local_port = bind_evtchn(port, handler, data);
+ return err;
}
Only in xen-unstable/extras/mini-os: events.o
diff -ur oxen-unstable/extras/mini-os/gnttab.c xen-unstable/extras/mini-os/gnttab.c
--- oxen-unstable/extras/mini-os/gnttab.c 2006-07-24 01:09:39.000000000 -0400
+++ xen-unstable/extras/mini-os/gnttab.c 2006-07-27 08:48:15.000000000 -0400
@@ -137,6 +137,18 @@
return gref;
}
+static const char *gnttabop_error_msgs[] = GNTTABOP_error_msgs;
+
+const char *
+gnttabop_error(int16_t status)
+{
+ status = -status;
+ if (status < 0 || status >= ARRAY_SIZE(gnttabop_error_msgs))
+ return "bad status";
+ else
+ return gnttabop_error_msgs[status];
+}
+
void
init_gnttab(void)
{
@@ -156,3 +168,10 @@
gnttab_table = map_frames(frames, NR_GRANT_FRAMES);
printk("gnttab_table mapped at %p.\n", gnttab_table);
}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * End:
+ */
Only in xen-unstable/extras/mini-os: gnttab.c~
Only in xen-unstable/extras/mini-os: gnttab.o
Only in xen-unstable/extras/mini-os: hypervisor.o
diff -ur oxen-unstable/extras/mini-os/include/events.h xen-unstable/extras/mini-os/include/events.h
--- oxen-unstable/extras/mini-os/include/events.h 2006-07-24 01:09:39.000000000 -0400
+++ xen-unstable/extras/mini-os/include/events.h 2006-07-27 08:44:15.000000000 -0400
@@ -22,20 +22,22 @@
#include<traps.h>
#include <xen/event_channel.h>
+typedef void (*evtchn_handler_t)(evtchn_port_t, struct pt_regs *, void *);
+
/* prototypes */
-int do_event(u32 port, struct pt_regs *regs);
-int bind_virq( u32 virq, void (*handler)(int, struct pt_regs *, void *data),
- void *data);
-int bind_evtchn( u32 virq, void (*handler)(int, struct pt_regs *, void *data),
- void *data );
-void unbind_evtchn( u32 port );
+int do_event(evtchn_port_t port, struct pt_regs *regs);
+int bind_virq(uint32_t virq, evtchn_handler_t handler, void *data);
+evtchn_port_t bind_evtchn(evtchn_port_t virq, evtchn_handler_t handler,
+ void *data);
+void unbind_evtchn(evtchn_port_t port);
void init_events(void);
-void unbind_virq( u32 port );
-int evtchn_alloc_unbound(void (*handler)(int, struct pt_regs *regs,
- void *data),
- void *data);
+int evtchn_alloc_unbound(domid_t pal, evtchn_handler_t handler,
+ void *data, evtchn_port_t *port);
+int evtchn_bind_interdomain(domid_t pal, evtchn_port_t remote_port,
+ evtchn_handler_t handler, void *data,
+ evtchn_port_t *local_port);
-static inline int notify_remote_via_evtchn(int port)
+static inline int notify_remote_via_evtchn(evtchn_port_t port)
{
evtchn_op_t op;
op.cmd = EVTCHNOP_send;
Only in xen-unstable/extras/mini-os/include: events.h~
diff -ur oxen-unstable/extras/mini-os/include/gnttab.h xen-unstable/extras/mini-os/include/gnttab.h
--- oxen-unstable/extras/mini-os/include/gnttab.h 2006-07-24 01:09:39.000000000 -0400
+++ xen-unstable/extras/mini-os/include/gnttab.h 2006-07-26 05:22:01.000000000 -0400
@@ -10,5 +10,6 @@
grant_ref_t gnttab_grant_transfer(domid_t domid, unsigned long pfn);
unsigned long gnttab_end_transfer(grant_ref_t gref);
int gnttab_end_access(grant_ref_t ref);
+const char *gnttabop_error(int16_t status);
#endif /* !__GNTTAB_H__ */
Only in xen-unstable/extras/mini-os/include: xen
Only in xen-unstable/extras/mini-os: kernel.o
Only in xen-unstable/extras/mini-os/lib: math.o
Only in xen-unstable/extras/mini-os/lib: printf.o
Only in xen-unstable/extras/mini-os/lib: string.o
Only in xen-unstable/extras/mini-os/lib: xmalloc.o
Only in xen-unstable/extras/mini-os: libminios.a
Only in xen-unstable/extras/mini-os: mini-os.elf
Only in xen-unstable/extras/mini-os: mini-os.gz
Only in xen-unstable/extras/mini-os: mm.o
Only in xen-unstable/extras/mini-os: sched.o
diff -ur oxen-unstable/extras/mini-os/time.c xen-unstable/extras/mini-os/time.c
--- oxen-unstable/extras/mini-os/time.c 2006-07-24 01:09:41.000000000 -0400
+++ xen-unstable/extras/mini-os/time.c 2006-07-26 05:22:01.000000000 -0400
@@ -215,7 +215,7 @@
/*
* Just a dummy
*/
-static void timer_handler(int ev, struct pt_regs *regs, void *ign)
+static void timer_handler(evtchn_port_t ev, struct pt_regs *regs, void *ign)
{
static int i;
Only in xen-unstable/extras/mini-os: time.o
Only in xen-unstable/extras/mini-os: traps.o
Only in xen-unstable/extras/mini-os: x86_32.o
diff -ur oxen-unstable/extras/mini-os/xenbus/xenbus.c xen-unstable/extras/mini-os/xenbus/xenbus.c
--- oxen-unstable/extras/mini-os/xenbus/xenbus.c 2006-07-24 01:09:41.000000000 -0400
+++ xen-unstable/extras/mini-os/xenbus/xenbus.c 2006-07-26 05:22:01.000000000 -0400
@@ -112,7 +112,8 @@
}
}
-static void xenbus_evtchn_handler(int port, struct pt_regs *regs, void *ign)
+static void xenbus_evtchn_handler(evtchn_port_t port, struct pt_regs *regs,
+ void *ign)
{
wake_up(&xb_waitq);
}
Only in xen-unstable/extras/mini-os/xenbus: xenbus.o
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
next prev parent reply other threads:[~2006-07-27 12:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-23 12:33 [PATCH] Mini-OS to use evtchn_port_t for ports and other improvements John D. Ramsdell
2006-07-25 10:27 ` Steven Smith
2006-07-26 0:14 ` John D. Ramsdell
2006-07-27 9:49 ` Steven Smith
2006-07-27 12:56 ` John D. Ramsdell [this message]
2006-07-26 10:00 ` John D. Ramsdell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ogt64hjkxzm.fsf@divan.mitre.org \
--to=ramsdell@mitre.org \
--cc=gm281@cam.ac.uk \
--cc=sos22-xen@srcf.ucam.org \
--cc=sos22@cam.ac.uk \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.