Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/usermode use O_ASYNC + SIGIO instead of polling for...



details:   https://anonhg.NetBSD.org/src/rev/53adde5f0a81
branches:  trunk
changeset: 772334:53adde5f0a81
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Dec 30 11:06:18 2011 +0000

description:
use O_ASYNC + SIGIO instead of polling for input

diffstat:

 sys/arch/usermode/dev/vncfb.c      |  22 ++++++++++------------
 sys/arch/usermode/usermode/thunk.c |  18 ++++++++++++++++--
 2 files changed, 26 insertions(+), 14 deletions(-)

diffs (130 lines):

diff -r 453998af8b16 -r 53adde5f0a81 sys/arch/usermode/dev/vncfb.c
--- a/sys/arch/usermode/dev/vncfb.c     Fri Dec 30 11:05:07 2011 +0000
+++ b/sys/arch/usermode/dev/vncfb.c     Fri Dec 30 11:06:18 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vncfb.c,v 1.3 2011/12/30 09:31:44 jmcneill Exp $ */
+/* $NetBSD: vncfb.c,v 1.4 2011/12/30 11:06:18 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -35,7 +35,7 @@
 #include "opt_wsemul.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vncfb.c,v 1.3 2011/12/30 09:31:44 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vncfb.c,v 1.4 2011/12/30 11:06:18 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -80,7 +80,7 @@
 
        int                     sc_kbd_enable;
 
-       callout_t               sc_callout;
+       void                    *sc_ih;
        void                    *sc_sih;
 };
 
@@ -103,7 +103,7 @@
 static void    vncfb_init_screen(void *, struct vcons_screen *, int, long *);
 
 static void    vncfb_update(struct vncfb_softc *, int, int, int, int);
-static void    vncfb_poll(void *);
+static int     vncfb_intr(void *);
 static void    vncfb_softintr(void *);
 
 static int     vncfb_kbd_enable(void *, int);
@@ -188,9 +188,6 @@
            (sc->sc_depth / 8), KM_SLEEP);
        KASSERT(sc->sc_framebuf != NULL);
 
-       callout_init(&sc->sc_callout, 0);
-       callout_setfunc(&sc->sc_callout, vncfb_poll, sc);
-
        aprint_naive("\n");
        aprint_normal(": %ux%u %ubpp (port %u)\n",
            sc->sc_width, sc->sc_height, sc->sc_depth, taa->u.vnc.port);
@@ -208,7 +205,7 @@
                panic("couldn't open rfb server");
 
        sc->sc_sih = softint_establish(SOFTINT_SERIAL, vncfb_softintr, sc);
-       callout_schedule(&sc->sc_callout, 1);
+       sc->sc_ih = sigio_intr_establish(vncfb_intr, sc);
 
        vcons_init(&sc->sc_vd, sc, &vncfb_defaultscreen, &vncfb_accessops);
        sc->sc_vd.init_screen = vncfb_init_screen;
@@ -455,14 +452,17 @@
 vncfb_update(struct vncfb_softc *sc, int x, int y, int w, int h)
 {
        thunk_rfb_update(&sc->sc_rfb, x, y, w, h);
+       softint_schedule(sc->sc_sih);
 }
 
-static void
-vncfb_poll(void *priv)
+static int
+vncfb_intr(void *priv)
 {
        struct vncfb_softc *sc = priv;
 
        softint_schedule(sc->sc_sih);
+
+       return 0;
 }
 
 static void
@@ -486,8 +486,6 @@
                        break;
                }
        }
-
-       callout_schedule(&sc->sc_callout, 1);
 }
 
 static int
diff -r 453998af8b16 -r 53adde5f0a81 sys/arch/usermode/usermode/thunk.c
--- a/sys/arch/usermode/usermode/thunk.c        Fri Dec 30 11:05:07 2011 +0000
+++ b/sys/arch/usermode/usermode/thunk.c        Fri Dec 30 11:06:18 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.59 2011/12/30 11:05:07 reinoud Exp $ */
+/* $NetBSD: thunk.c,v 1.60 2011/12/30 11:06:18 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __NetBSD__
-__RCSID("$NetBSD: thunk.c,v 1.59 2011/12/30 11:05:07 reinoud Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.60 2011/12/30 11:06:18 jmcneill Exp $");
 #endif
 
 #include <sys/types.h>
@@ -1077,6 +1077,7 @@
                struct sockaddr_in sin;
                struct pollfd fds[1];
                socklen_t sinlen;
+               int flags;
 
                /* poll for connections */
                fds[0].fd = rfb->sockfd;
@@ -1103,6 +1104,19 @@
                }
 
                rfb->connected = true;
+
+               /* enable sigio on input */
+               flags = fcntl(rfb->clientfd, F_GETFL, 0);
+               fcntl(rfb->clientfd, F_SETFL, flags | O_ASYNC);
+               error = fcntl(rfb->clientfd, F_SETOWN, getpid());
+               if (error) {
+                       fprintf(stdout, "rfb: setown failed: %s\n",
+                           strerror(errno));
+                       close(rfb->clientfd);
+                       rfb->clientfd = -1;
+                       return -1;
+               }
+
                rfb->nupdates = 0;
                thunk_rfb_update(rfb, 0, 0, rfb->width, rfb->height);
        }



Home | Main Index | Thread Index | Old Index