WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] This patch is to fix the NIC driven mechanism to make it

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] This patch is to fix the NIC driven mechanism to make it event
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Sun, 30 Oct 2005 22:34:13 +0000
Delivery-date: Sun, 30 Oct 2005 22:32:40 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID 32695e99cfc88f00e881f1bee5a1963877adbc57
# Parent  8e1bfcb901e59e8d33dc185ab8920c7a79a73db6
        This patch is to fix the NIC driven mechanism to make it event
driven. We will also send it to Qemu mailing list.

Signed-off-by: Eddie Dong <eddie.dong@xxxxxxxxx>

diff -r 8e1bfcb901e5 -r 32695e99cfc8 tools/ioemu/hw/ne2000.c
--- a/tools/ioemu/hw/ne2000.c   Sun Oct 30 15:43:05 2005
+++ b/tools/ioemu/hw/ne2000.c   Sun Oct 30 15:47:59 2005
@@ -327,6 +327,7 @@
             break;
         }
     }
+    update_select_wakeup_events();
 }
 
 static uint32_t ne2000_ioport_read(void *opaque, uint32_t addr)
@@ -373,6 +374,7 @@
             break;
         }
     }
+    update_select_wakeup_events();
 #ifdef DEBUG_NE2000
     printf("NE2000: read addr=0x%x val=%02x\n", addr, ret);
 #endif
@@ -476,6 +478,7 @@
         ne2000_mem_writeb(s, s->rsar, val);
         ne2000_dma_update(s, 1);
     }
+    update_select_wakeup_events();
 }
 
 static uint32_t ne2000_asic_ioport_read(void *opaque, uint32_t addr)
@@ -492,6 +495,7 @@
         ret = ne2000_mem_readb(s, s->rsar);
         ne2000_dma_update(s, 1);
     }
+    update_select_wakeup_events();
 #ifdef DEBUG_NE2000
     printf("NE2000: asic read val=0x%04x\n", ret);
 #endif
@@ -510,6 +514,7 @@
     /* 32 bit access */
     ne2000_mem_writel(s, s->rsar, val);
     ne2000_dma_update(s, 4);
+    update_select_wakeup_events();
 }
 
 static uint32_t ne2000_asic_ioport_readl(void *opaque, uint32_t addr)
@@ -520,6 +525,7 @@
     /* 32 bit access */
     ret = ne2000_mem_readl(s, s->rsar);
     ne2000_dma_update(s, 4);
+    update_select_wakeup_events();
 #ifdef DEBUG_NE2000
     printf("NE2000: asic readl val=0x%04x\n", ret);
 #endif
@@ -535,6 +541,7 @@
 {
     NE2000State *s = opaque;
     ne2000_reset(s);
+    update_select_wakeup_events();
     return 0;
 }
 
diff -r 8e1bfcb901e5 -r 32695e99cfc8 tools/ioemu/hw/pcnet.c
--- a/tools/ioemu/hw/pcnet.c    Sun Oct 30 15:43:05 2005
+++ b/tools/ioemu/hw/pcnet.c    Sun Oct 30 15:47:59 2005
@@ -50,7 +50,6 @@
 struct PCNetState_st {
     PCIDevice dev;
     NetDriverState *nd;
-    QEMUTimer *poll_timer;
     int mmio_io_addr, rap, isr, lnkst;
     target_phys_addr_t rdra, tdra;
     uint8_t prom[16];
@@ -640,8 +639,6 @@
 {
     PCNetState *s = opaque;
 
-    qemu_del_timer(s->poll_timer);
-
     if (CSR_TDMD(s)) {
         pcnet_transmit(s);
     }
@@ -660,8 +657,6 @@
             } else
                 CSR_POLL(s) = t;
         }
-        qemu_mod_timer(s->poll_timer, 
-            pcnet_get_next_poll_time(s,qemu_get_clock(vm_clock)));
     }
 }
 
@@ -941,6 +936,7 @@
         }
     }
     pcnet_update_irq(s);
+    update_select_wakeup_events();
 }
 
 static uint32_t pcnet_ioport_readw(void *opaque, uint32_t addr)
@@ -966,6 +962,7 @@
         }
     }
     pcnet_update_irq(s);
+    update_select_wakeup_events();
 #ifdef PCNET_DEBUG_IO
     printf("pcnet_ioport_readw addr=0x%08x val=0x%04x\n", addr, val & 0xffff);
 #endif
@@ -1000,6 +997,7 @@
 #endif        
     }
     pcnet_update_irq(s);
+    update_select_wakeup_events();
 }
 
 static uint32_t pcnet_ioport_readl(void *opaque, uint32_t addr)
@@ -1025,6 +1023,7 @@
         }
     }
     pcnet_update_irq(s);
+    update_select_wakeup_events();
 #ifdef PCNET_DEBUG_IO
     printf("pcnet_ioport_readl addr=0x%08x val=0x%08x\n", addr, val);
 #endif
@@ -1210,8 +1209,6 @@
     pci_register_io_region((PCIDevice *)d, 1, PCNET_PNPMMIO_SIZE, 
                            PCI_ADDRESS_SPACE_MEM, pcnet_mmio_map);
                            
-    d->poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, d);
-
     d->nd = nd;
 
     pcnet_h_reset(d);
diff -r 8e1bfcb901e5 -r 32695e99cfc8 tools/ioemu/target-i386-dm/helper2.c
--- a/tools/ioemu/target-i386-dm/helper2.c      Sun Oct 30 15:43:05 2005
+++ b/tools/ioemu/target-i386-dm/helper2.c      Sun Oct 30 15:47:59 2005
@@ -387,12 +387,6 @@
        }
 }
 
-void
-cpu_timer_handler(CPUState *env)
-{
-       cpu_handle_ioreq(env);
-}
-
 int xc_handle;
 
 static __inline__ void atomic_set_bit(long nr, volatile void *addr)
@@ -413,6 +407,8 @@
         fprintf(logfile, "%s failed.!\n", destroy_cmd);
 }
 
+fd_set wakeup_rfds;
+int    highest_fds;
 int main_loop(void)
 {
        fd_set rfds;
@@ -425,8 +421,9 @@
         extern void main_loop_wait(int);
 
        /* Watch stdin (fd 0) to see when it has input. */
-       FD_ZERO(&rfds);
-
+       FD_ZERO(&wakeup_rfds);
+       FD_SET(evtchn_fd, &wakeup_rfds);
+       highest_fds = evtchn_fd;
        while (1) {
                 if (vm_running) {
                     if (shutdown_requested) {
@@ -441,14 +438,16 @@
                /* Wait up to one seconds. */
                tv.tv_sec = 0;
                tv.tv_usec = 100000;
-               FD_SET(evtchn_fd, &rfds);
 
                env->send_event = 0;
-               retval = select(evtchn_fd+1, &rfds, NULL, NULL, &tv);
+               retval = select(highest_fds+1, &wakeup_rfds, NULL, NULL, &tv);
                if (retval == -1) {
                        perror("select");
                        return 0;
                }
+        rfds = wakeup_rfds;
+        FD_ZERO(&wakeup_rfds);
+        FD_SET(evtchn_fd, &wakeup_rfds);
 
 #if __WORDSIZE == 32
 #define ULONGLONG_MAX   0xffffffffffffffffULL
@@ -460,7 +459,10 @@
 #ifdef APIC_SUPPORT
                ioapic_update_EOI();
 #endif
-               cpu_timer_handler(env);
+        tun_receive_handler(&rfds);
+        if ( FD_ISSET(evtchn_fd, &rfds) ) {
+            cpu_handle_ioreq(env);
+        }
 #ifdef APIC_SUPPORT
                if (ioapic_has_intr())
                     do_ioapic();
diff -r 8e1bfcb901e5 -r 32695e99cfc8 tools/ioemu/vl.c
--- a/tools/ioemu/vl.c  Sun Oct 30 15:43:05 2005
+++ b/tools/ioemu/vl.c  Sun Oct 30 15:47:59 2005
@@ -1528,7 +1528,7 @@
                                 IOCanRWHandler *fd_can_read, 
                                 IOReadHandler *fd_read, void *opaque)
 {
-    qemu_add_fd_read_handler(nd->fd, fd_can_read, fd_read, opaque);
+    qemu_add_fd_event_read_handler(nd->fd, fd_can_read, fd_read, opaque);
 }
 
 static int net_tun_init(NetDriverState *nd)
@@ -1536,11 +1536,13 @@
     int pid, status;
     char *args[3];
     char **parg;
+    extern int highest_fds;
 
     nd->fd = tun_open(nd->ifname, sizeof(nd->ifname));
     if (nd->fd < 0)
         return -1;
 
+    if ( nd->fd > highest_fds ) highest_fds = nd->fd;
     /* try to launch network init script */
     pid = fork();
     if (pid >= 0) {
@@ -1628,6 +1630,7 @@
 } IOHandlerRecord;
 
 static IOHandlerRecord *first_io_handler;
+static IOHandlerRecord *first_eventio_handler;
 
 int qemu_add_fd_read_handler(int fd, IOCanRWHandler *fd_can_read, 
                              IOReadHandler *fd_read, void *opaque)
@@ -1643,6 +1646,23 @@
     ioh->opaque = opaque;
     ioh->next = first_io_handler;
     first_io_handler = ioh;
+    return 0;
+}
+
+int qemu_add_fd_event_read_handler(int fd, IOCanRWHandler *fd_can_read, 
+                             IOReadHandler *fd_read, void *opaque)
+{
+    IOHandlerRecord *ioh;
+
+    ioh = qemu_mallocz(sizeof(IOHandlerRecord));
+    if (!ioh)
+        return -1;
+    ioh->fd = fd;
+    ioh->fd_can_read = fd_can_read;
+    ioh->fd_read = fd_read;
+    ioh->opaque = opaque;
+    ioh->next = first_eventio_handler;
+    first_eventio_handler = ioh;
     return 0;
 }
 
@@ -3257,3 +3277,44 @@
     quit_timers();
     return 0;
 }
+
+extern fd_set wakeup_rfds;
+void tun_receive_handler(fd_set *rfds)
+{
+    IOHandlerRecord *ioh;
+    static uint8_t buf[4096];
+    int n, max_size;
+
+    for (ioh = first_eventio_handler; ioh != NULL; ioh = ioh->next) {
+        if ( FD_ISSET(ioh->fd, rfds) ) {
+            max_size = ioh->fd_can_read(ioh->opaque);
+            if (max_size > 0) {
+                if (max_size > sizeof(buf))
+                    max_size = sizeof(buf);
+                n = read(ioh->fd, buf, max_size);
+                if (n >= 0) {
+                    ioh->fd_read(ioh->opaque, buf, n);
+                } 
+            }
+        }
+    }
+    update_select_wakeup_events();
+}
+
+void update_select_wakeup_events(void)
+{
+    IOHandlerRecord *ioh;
+    int max_size;
+
+    for(ioh = first_eventio_handler; ioh != NULL; ioh = ioh->next) {
+        FD_CLR(ioh->fd, &wakeup_rfds);
+        if (ioh->fd_can_read) {
+             max_size = ioh->fd_can_read(ioh->opaque);
+             if (max_size > 0) {
+                 FD_SET(ioh->fd, &wakeup_rfds);
+             }
+        }
+    }
+}
+
+
diff -r 8e1bfcb901e5 -r 32695e99cfc8 tools/ioemu/vl.h
--- a/tools/ioemu/vl.h  Sun Oct 30 15:43:05 2005
+++ b/tools/ioemu/vl.h  Sun Oct 30 15:47:59 2005
@@ -178,6 +178,8 @@
 
 int qemu_add_fd_read_handler(int fd, IOCanRWHandler *fd_can_read, 
                              IOReadHandler *fd_read, void *opaque);
+int qemu_add_fd_event_read_handler(int fd, IOCanRWHandler *fd_can_read, 
+                             IOReadHandler *fd_read, void *opaque);
 void qemu_del_fd_read_handler(int fd);
 
 /* character device */
@@ -791,5 +793,7 @@
 #define DEFAULT_GDBSTUB_PORT 1234
 
 int gdbserver_start(int port);
+void update_select_wakeup_events(void);
+void tun_receive_handler();
 
 #endif /* VL_H */

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] This patch is to fix the NIC driven mechanism to make it event, Xen patchbot -unstable <=