Skip to content

Commit 68f4d5a

Browse files
Zhao YakuiH. Peter Anvin
authored andcommitted
x86, setup: Use string copy operation to optimze copy in kernel compression
The kernel decompression code parses the ELF header and then copies the segment to the corresponding destination. Currently it uses slow byte-copy code. This patch makes it use the string copy operations instead. In the test the copy performance can be improved very significantly after using the string copy operation mechanism. 1. The copy time can be reduced from 150ms to 20ms on one Atom machine 2. The copy time can be reduced about 80% on another machine The time is reduced from 7ms to 1.5ms when using 32-bit kernel. The time is reduced from 10ms to 2ms when using 64-bit kernel. Signed-off-by: Zhao Yakui <yakui.zhao@intel.com> LKML-Reference: <1286502453-7043-1-git-send-email-yakui.zhao@intel.com> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
1 parent cb655d0 commit 68f4d5a

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

  • arch/x86/boot/compressed

‎arch/x86/boot/compressed/misc.c‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,35 @@ void *memset(void *s, int c, size_t n)
229229
ss[i] = c;
230230
return s;
231231
}
232-
232+
#ifdef CONFIG_X86_32
233233
void *memcpy(void *dest, const void *src, size_t n)
234234
{
235-
int i;
236-
const char *s = src;
237-
char *d = dest;
235+
int d0, d1, d2;
236+
asm volatile(
237+
"rep ; movsl\n\t"
238+
"movl %4,%%ecx\n\t"
239+
"rep ; movsb\n\t"
240+
: "=&c" (d0), "=&D" (d1), "=&S" (d2)
241+
: "0" (n >> 2), "g" (n & 3), "1" (dest), "2" (src)
242+
: "memory");
238243

239-
for (i = 0; i < n; i++)
240-
d[i] = s[i];
241244
return dest;
242245
}
246+
#else
247+
void *memcpy(void *dest, const void *src, size_t n)
248+
{
249+
long d0, d1, d2;
250+
asm volatile(
251+
"rep ; movsq\n\t"
252+
"movq %4,%%rcx\n\t"
253+
"rep ; movsb\n\t"
254+
: "=&c" (d0), "=&D" (d1), "=&S" (d2)
255+
: "0" (n >> 3), "g" (n & 7), "1" (dest), "2" (src)
256+
: "memory");
243257

258+
return dest;
259+
}
260+
#endif
244261

245262
static void error(char *x)
246263
{

0 commit comments

Comments
 (0)