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

[Xen-devel] Re: [Xen-ia64-devel] [PATCH] Fix unaligned reference of QEMU



On Tue, 2007-08-21 at 06:23 -0600, Alex Williamson wrote:
> On Tue, 2007-08-21 at 14:58 +0800, Duan, Ronghui wrote:
> > Hi
> > 
> > In current changeset.,qemu copy data uses memcpy_words, which copies 4
> > bytes at once if the length is larger than 4. This causes unaligned
> > reference and leads to a performance downgrade. The issue met in
> > rtl8139 emulator. This patch fixes it.
> 
> Hi,
> 
>    I'd like to see this get fixed, but I'm not sure this is the right
> way to do it.  Originally, there was a simple memcpy() here.   The
> trouble started with this patch:
> 
> http://xenbits.xensource.com/xen-unstable.hg?rev/677731eb734d
> 
> This change required 8-byte alignment on 64 bit systems instead of the
> 4-byte claimed in the changelog, which resulted in this patch:
> 
> http://xenbits.xensource.com/xen-unstable.hg?rev/896b536d66c9
> 
> Now the problem appears to be that memcpy_words() is not isolated to
> only the USB traffic.  When I see the unaligned accesses, they seem to
> have some correlation with network traffic, and your benchmark results
> prove that.  I think we need figure out when to use memcpy_words to
> avoid the USB issue and when to use memcpy.  Maybe we can do that by
> looking at the alignment and using the best one, or maybe it's possible
> to distinguish data streams in exec-dm.  Thanks,

   Here's a fix that might work.  We simply test the alignment of source
and destination and choose which copy method to use.  If its aligned,
word copy, otherwise memcpy.  The assumption being that these magic USB
buffers that need alignment will do the right thing.  This actually
increases throughput more than 10x in a wget into an HVM domain
(~2.5MB/s vs ~30MB/s).  Keir, if this looks ok, could you please apply
to the mainline since this is common code?  Thanks,

        Alex

Signed-off-by: Alex Williamson <alex.williamson@xxxxxx>
---

diff -r 049d4baa9965 tools/ioemu/target-i386-dm/exec-dm.c
--- a/tools/ioemu/target-i386-dm/exec-dm.c      Thu Aug 16 13:46:50 2007 -0600
+++ b/tools/ioemu/target-i386-dm/exec-dm.c      Tue Aug 21 09:28:27 2007 -0600
@@ -470,6 +470,12 @@ static void memcpy_words(void *dst, void
 #else
 static void memcpy_words(void *dst, void *src, size_t n)
 {
+    /* word copies require proper alignment of src & dst */
+    if ((((unsigned long)dst | (unsigned long)src) & 0x3) != 0) {
+        memcpy(dst, src, n);
+        return;
+    }
+
     while (n >= sizeof(uint32_t)) {
         *((uint32_t *)dst) = *((uint32_t *)src);
         dst = ((uint32_t *)dst) + 1;



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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.