From: Dan Magenheimer Subject: RE: [PATCH] x86: add SSE-based copy_page() Date: Wed, 12 Nov 2008 14:51:49 +0000 (GMT) Message-ID: References: <491AB1EC.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=Windows-1252 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <491AB1EC.76E4.0078.0@novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jan Beulich , xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Jan -- I assume the 12% faster is on a benchmark... Have you measured how much faster the copy_page_sse2 routine (standalond) is than the memcpy? Is it a factor of 2? Thanks, Dan > -----Original Message----- > From: Jan Beulich [mailto:jbeulich@novell.com] > Sent: Wednesday, November 12, 2008 2:38 AM > To: xen-devel@lists.xensource.com > Subject: [Xen-devel] [PATCH] x86: add SSE-based copy_page() >=20 >=20 > In top of the highmem asstance hypercalls added earlier, this provides > a performance improvement of another 12% (measured on Xeon E5345) for > the page copying case. >=20 > Signed-off-by: Jan Beulich >=20 > Index: 2008-10-27/xen/arch/x86/Makefile > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- 2008-10-27.orig/xen/arch/x86/Makefile=092008-11-11=20 > 16:19:45.000000000 +0100 > +++ 2008-10-27/xen/arch/x86/Makefile=092008-11-11=20 > 16:18:36.000000000 +0100 > @@ -11,6 +11,7 @@ subdir-$(x86_64) +=3D x86_64 > obj-y +=3D apic.o > obj-y +=3D bitops.o > obj-y +=3D clear_page.o > +obj-y +=3D copy_page.o > obj-y +=3D compat.o > obj-y +=3D delay.o > obj-y +=3D dmi_scan.o > Index: 2008-10-27/xen/arch/x86/copy_page.S > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- /dev/null=091970-01-01 00:00:00.000000000 +0000 > +++ 2008-10-27/xen/arch/x86/copy_page.S=092008-06-03=20 > 14:24:57.000000000 +0200 > @@ -0,0 +1,66 @@ > +#include > +#include > + > +#ifdef __i386__ > +#define src_reg %esi > +#define dst_reg %edi > +#define WORD_SIZE 4 > +#define tmp1_reg %eax > +#define tmp2_reg %edx > +#define tmp3_reg %ebx > +#define tmp4_reg %ebp > +#else > +#define src_reg %rsi > +#define dst_reg %rdi > +#define WORD_SIZE 8 > +#define tmp1_reg %r8 > +#define tmp2_reg %r9 > +#define tmp3_reg %r10 > +#define tmp4_reg %r11 > +#endif > + > +ENTRY(copy_page_sse2) > +#ifdef __i386__ > + push %ebx > + push %ebp > + push %esi > + push %edi > + mov 6*4(%esp), src_reg > + mov 5*4(%esp), dst_reg > +#endif > + mov $PAGE_SIZE/(4*WORD_SIZE)-3, %ecx > + > + prefetchnta 2*4*WORD_SIZE(src_reg) > + mov (src_reg), tmp1_reg > + mov WORD_SIZE(src_reg), tmp2_reg > + mov 2*WORD_SIZE(src_reg), tmp3_reg > + mov 3*WORD_SIZE(src_reg), tmp4_reg > + > +0: prefetchnta 3*4*WORD_SIZE(src_reg) > +1: add $4*WORD_SIZE, src_reg > + movnti tmp1_reg, (dst_reg) > + mov (src_reg), tmp1_reg > + dec %ecx > + movnti tmp2_reg, WORD_SIZE(dst_reg) > + mov WORD_SIZE(src_reg), tmp2_reg > + movnti tmp3_reg, 2*WORD_SIZE(dst_reg) > + mov 2*WORD_SIZE(src_reg), tmp3_reg > + movnti tmp4_reg, 3*WORD_SIZE(dst_reg) > + lea 4*WORD_SIZE(dst_reg), dst_reg > + mov 3*WORD_SIZE(src_reg), tmp4_reg > + jg 0b > + jpe 1b > + > + movnti tmp1_reg, (dst_reg) > + movnti tmp2_reg, WORD_SIZE(dst_reg) > + movnti tmp3_reg, 2*WORD_SIZE(dst_reg) > + movnti tmp4_reg, 3*WORD_SIZE(dst_reg) > + > +#ifdef __i386__ > + pop %edi > + pop %esi > + pop %ebp > + pop %ebx > +#endif > + sfence > + ret > Index: 2008-10-27/xen/arch/x86/domain.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- 2008-10-27.orig/xen/arch/x86/domain.c=092008-11-11=20 > 14:55:44.000000000 +0100 > +++ 2008-10-27/xen/arch/x86/domain.c=092008-11-11=20 > 16:24:48.000000000 +0100 > @@ -183,7 +183,8 @@ static int setup_compat_l4(struct vcpu * > /* This page needs to look like a pagetable so that it=20 > can be shadowed */ > pg->u.inuse.type_info =3D PGT_l4_page_table|PGT_validated|1; > =20 > - l4tab =3D copy_page(page_to_virt(pg), idle_pg_table); > + l4tab =3D page_to_virt(pg); > + copy_page(l4tab, idle_pg_table); > l4tab[0] =3D l4e_empty(); > l4tab[l4_table_offset(LINEAR_PT_VIRT_START)] =3D > l4e_from_page(pg, __PAGE_HYPERVISOR); > Index: 2008-10-27/xen/arch/x86/domain_build.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- 2008-10-27.orig/xen/arch/x86/domain_build.c=09 > 2008-11-11 16:19:45.000000000 +0100 > +++ 2008-10-27/xen/arch/x86/domain_build.c=092008-11-11=20 > 16:18:36.000000000 +0100 > @@ -467,8 +467,9 @@ int __init construct_dom0( > /* WARNING: The new domain must have its 'processor'=20 > field filled in! */ > l3start =3D l3tab =3D (l3_pgentry_t *)mpt_alloc; mpt_alloc=20 > +=3D PAGE_SIZE; > l2start =3D l2tab =3D (l2_pgentry_t *)mpt_alloc; mpt_alloc=20 > +=3D 4*PAGE_SIZE; > - memcpy(l2tab, idle_pg_table_l2, 4*PAGE_SIZE); > - for (i =3D 0; i < 4; i++) { > + for (i =3D 0; i < L3_PAGETABLE_ENTRIES; i++) { > + copy_page(l2tab + i * L2_PAGETABLE_ENTRIES, > + idle_pg_table_l2 + i * L2_PAGETABLE_ENTRIES); > l3tab[i] =3D l3e_from_paddr((u32)l2tab + i*PAGE_SIZE, L3_PROT); > l2tab[(LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT)+i] =3D > l2e_from_paddr((u32)l2tab + i*PAGE_SIZE,=20 > __PAGE_HYPERVISOR); > Index: 2008-10-27/xen/include/asm-x86/page.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- 2008-10-27.orig/xen/include/asm-x86/page.h=09 > 2008-11-11 16:19:45.000000000 +0100 > +++ 2008-10-27/xen/include/asm-x86/page.h=092008-11-11=20 > 16:18:36.000000000 +0100 > @@ -215,7 +215,10 @@ void clear_page_sse2(void *); > #define clear_page(_p) (cpu_has_xmm2 ? =20 > \ > clear_page_sse2((void *)(_p)) :=20 > \ > (void)memset((void *)(_p), 0,=20 > PAGE_SIZE)) > -#define copy_page(_t,_f) memcpy((void *)(_t), (void=20 > *)(_f), PAGE_SIZE) > +void copy_page_sse2(void *, const void *); > +#define copy_page(_t,_f) (cpu_has_xmm2 ? =20 > \ > + copy_page_sse2(_t, _f) : =20 > \ > + (void)memcpy(_t, _f, PAGE_SIZE)) > =20 > #define mfn_valid(mfn) ((mfn) < max_page) > =20 >=20 >=20 >=20 > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel >