Skip to contentSkip to conversation

Make DMA timer driven

PATCH In review Anthony Liguori 3 participants 4 messages Oct 23, 2008 – Oct 24, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make DMA timer driven

The current DMA routines are driven by a call in main_loop_wait() after every select. The effect of this is that the DMA runs at a 10ms frequency depending on whether IO is pending.

This patch converts the DMA code from using this implicit 10ms frequency to having an explicit 10ms frequency using a QEMUTimer. This means boards no longer have to stub out DMA_run() functions.

The only two architectures implementing DMA_run() are cris and i386. For cris, I converted it to a simple repeating timer. I've only compile tested this so I'd appreciate if you could test it Edgar (or point me to an image).

For x86, I've made sure to only fire the DMA timer if there is a DMA channel that is runnable. The effect of this is that unless you're using sb16 or a floppy disk, the DMA timer never fires.

You probably should test this malc. My own benchmarks actually show slight improvement by it's possible the change in timing could affect your demos.

hw/an5206.c +0 -4
index 862d0cf..10f8b18 100644
@@ -24,10 +24,6 @@ void irq_info(void)
 {
 }
 
-void DMA_run (void)
-{
-}
-
 /* Board init.  */
 
 static void an5206_init(ram_addr_t ram_size, int vga_ram_size,
hw/dma.c +40 -2

116 lines not on this page · raw message

hw/etraxfs_dma.c +10 -6
index f95f4f7..1c8fb83 100644
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <sys/time.h>
 #include "hw.h"
+#include "qemu-timer.h"
 
 #include "etraxfs_dma.h"
 
@@ -190,6 +191,8 @@ struct fs_dma_ctrl
 
 	int nr_channels;
 	struct fs_dma_channel *channels;
+
+        QEMUTimer *dma_timer;
 };
 
 static inline uint32_t channel_reg(struct fs_dma_ctrl *ctrl, int c, int reg)
@@ -710,11 +713,11 @@ void etraxfs_dmac_connect_client(void *opaque, int c,
 }
 
 
-static void *etraxfs_dmac;
-void DMA_run(void)
+static void DMA_run(void *opaque)
 {
-	if (etraxfs_dmac)
-		etraxfs_dmac_run(etraxfs_dmac);
+    struct fs_dma_ctrl *etraxfs_dmac = opaque;
+    qemu_mod_timer(etraxfs_dmac->dma_timer, qemu_get_clock(vm_clock) + 10);
+    etraxfs_dmac_run(etraxfs_dmac);
 }
 
 void *etraxfs_dmac_init(CPUState *env, 
@@ -727,6 +730,9 @@ void *etraxfs_dmac_init(CPUState *env,
 	if (!ctrl)
 		return NULL;
 
+        ctrl->dma_timer = qemu_new_timer(vm_clock, DMA_run, ctrl);
+        qemu_mod_timer(ctrl->dma_timer, qemu_get_clock(vm_clock) + 10);
+
 	ctrl->base = base;
 	ctrl->env = env;
 	ctrl->nr_channels = nr_channels;
@@ -745,8 +751,6 @@ void *etraxfs_dmac_init(CPUState *env,
 					      ctrl->channels[i].regmap);
 	}
 
-	/* Hax, we only support one DMA controller at a time.  */
-	etraxfs_dmac = ctrl;
 	return ctrl;
   err:
 	qemu_free(ctrl->channels);
hw/integratorcp.c +0 -4
index 1ae5d2a..9a415b7 100644
@@ -15,10 +15,6 @@
 #include "arm-misc.h"
 #include "net.h"
 
-void DMA_run (void)
-{
-}
-
 typedef struct {
     uint32_t flash_offset;
     uint32_t cm_osc;
hw/isa.h +0 -1
index 222e4f3..a8c1a56 100644
@@ -19,7 +19,6 @@ int DMA_write_memory (int nchan, void *buf, int pos, int size);
 void DMA_hold_DREQ (int nchan);
 void DMA_release_DREQ (int nchan);
 void DMA_schedule(int nchan);
-void DMA_run (void);
 void DMA_init (int high_page_enable);
 void DMA_register_channel (int nchan,
                            DMA_transfer_handler transfer_handler,
hw/shix.c +0 -5
index 3cc41fb..334ef4c 100644
@@ -35,11 +35,6 @@
 #define BIOS_FILENAME "shix_bios.bin"
 #define BIOS_ADDRESS 0xA0000000
 
-void DMA_run(void)
-{
-    /* XXXXX */
-}
-
 void irq_info(void)
 {
     /* XXXXX */
hw/sun4m.c +0 -1
index dd0433a..3e8b17a 100644
@@ -146,7 +146,6 @@ int DMA_write_memory (int nchan, void *buf, int pos, int size)
 void DMA_hold_DREQ (int nchan) {}
 void DMA_release_DREQ (int nchan) {}
 void DMA_schedule(int nchan) {}
-void DMA_run (void) {}
 void DMA_init (int high_page_enable) {}
 void DMA_register_channel (int nchan,
                            DMA_transfer_handler transfer_handler,
hw/sun4u.c +0 -1
index a70ad20..057d598 100644
@@ -79,7 +79,6 @@ int DMA_write_memory (int nchan, void *buf, int pos, int size)
 void DMA_hold_DREQ (int nchan) {}
 void DMA_release_DREQ (int nchan) {}
 void DMA_schedule(int nchan) {}
-void DMA_run (void) {}
 void DMA_init (int high_page_enable) {}
 void DMA_register_channel (int nchan,
                            DMA_transfer_handler transfer_handler,
vl.c +0 -2
index c0e43ac..1bd0914 100644
@@ -7968,8 +7968,6 @@ void main_loop_wait(int timeout)
         if (likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER)))
         qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL],
                         qemu_get_clock(vm_clock));
-        /* run dma transfers, if any */
-        DMA_run();
     }
 
     /* real time timers */
#1 lore raw
Quoted 11 lines · Anthony Liguori

The current DMA routines are driven by a call in main_loop_wait() after every select. The effect of this is that the DMA runs at a 10ms frequency depending on whether IO is pending.

This patch converts the DMA code from using this implicit 10ms frequency to having an explicit 10ms frequency using a QEMUTimer. This means boards no longer have to stub out DMA_run() functions.

The only two architectures implementing DMA_run() are cris and i386. For cris, I converted it to a simple repeating timer. I've only compile tested this so I'd appreciate if you could test it Edgar (or point me to an image).

Hello Anthony,

You can find info regarding CRIS/ETRAX testing here:
http://lists.gnu.org/archive/html/qemu-devel/2008-09/msg00279.html

I tested the patch. It works but unfortunately DMA transfers to/from the ethernet block now seem to emulate very slowly.

Best regards

#2 lore raw
Quoted 5 lines

You can find info regarding CRIS/ETRAX testing here:
http://lists.gnu.org/archive/html/qemu-devel/2008-09/msg00279.html

I tested the patch. It works but unfortunately DMA transfers to/from the ethernet block now seem to emulate very slowly.

Is there a reason you're deferring the DMA transfers, rather than completing them immediately? In most cases you want to do the DMA as soon as both ends are ready, and there's no benefit artificially delaying things. Any delay is entirely arbitrary, and won't work reliably.

Paul

#3 lore raw
Quoted 10 lines · Paul Brook
Quoted 5 lines

You can find info regarding CRIS/ETRAX testing here:
http://lists.gnu.org/archive/html/qemu-devel/2008-09/msg00279.html

I tested the patch. It works but unfortunately DMA transfers to/from the ethernet block now seem to emulate very slowly.

Is there a reason you're deferring the DMA transfers, rather than completing them immediately? In most cases you want to do the DMA as soon as both ends are ready, and there's no benefit artificially delaying things. Any delay is entirely arbitrary, and won't work reliably.

Hello,

If you are refering to the etrax dma/ethernet, any delays are unintentional. I removed the poll based ethernet receive path, so that rx packets now go straight into the dma without waiting for DMA_run but unfortunately the timer based DMA_run still slows things down for etrax.

I'll try to look at it more when I get a free time slot..

Thanks