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/
Home Products Support Community News


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

To: "Duan, Ronghui" <ronghui.duan@xxxxxxxxx>
Subject: [Xen-devel] Re: [Xen-ia64-devel] [PATCH] Fix unaligned reference of QEMU
From: Alex Williamson <alex.williamson@xxxxxx>
Date: Tue, 21 Aug 2007 09:44:38 -0600
Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>, xen-ia64-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Tue, 21 Aug 2007 08:45:17 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <1187698982.6810.99.camel@bling>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Organization: HP OSLO R&D
References: <82C666AA63DC75449C51EAD62E8B2BEC115E11@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> <1187698982.6810.99.camel@bling>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
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,


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
 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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] Re: [Xen-ia64-devel] [PATCH] Fix unaligned reference of QEMU, Alex Williamson <=