kernel - Refactor copyinstr and copystr
authorMatthew Dillon <dillon@apollo.backplane.com>
Sun, 23 Sep 2018 18:35:21 +0000 (11:35 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 25 Sep 2018 16:29:09 +0000 (09:29 -0700)
* Replace lodsb/stosb sequence with discrete mov's.  Remove related
  xchgq and cld.

Suggested-by: mjg
sys/platform/pc64/x86_64/support.s
test/sysperf/syscall4.c

index 354f21d..4bffa16 100644 (file)
@@ -671,7 +671,6 @@ END(std_subyte)
 ENTRY(std_copyinstr)
        movq    %rdx,%r8                        /* %r8 = maxlen */
        movq    %rcx,%r9                        /* %r9 = *len */
-       xchgq   %rdi,%rsi                       /* %rdi = from, %rsi = to */
        movq    PCPU(curthread),%rcx
        movq    TD_PCB(%rcx), %rcx
        movq    $cpystrflt,PCB_ONFAULT(%rcx)
@@ -680,7 +679,7 @@ ENTRY(std_copyinstr)
        movq    $VM_MAX_USER_ADDRESS,%rax
 
        /* make sure 'from' is within bounds */
-       subq    %rsi,%rax
+       subq    %rdi,%rax
        jbe     cpystrflt
 
        /* restrict maxlen to <= VM_MAX_USER_ADDRESS-from */
@@ -690,15 +689,16 @@ ENTRY(std_copyinstr)
        movq    %rax,%r8
 1:
        incq    %rdx
-       cld
 
 2:
        decq    %rdx
        jz      3f
 
-       lodsb
-       stosb
-       orb     %al,%al
+       movb    (%rdi),%al                      /* faster than lodsb+stosb */
+       movb    %al,(%rsi)
+       leaq    1(%rdi),%rdi
+       leaq    1(%rsi),%rsi
+       testb   %al,%al
        jnz     2b
 
        /* Success -- 0 byte reached */
@@ -738,15 +738,16 @@ END(std_copyinstr)
 ENTRY(copystr)
        movq    %rdx,%r8                        /* %r8 = maxlen */
 
-       xchgq   %rdi,%rsi
        incq    %rdx
-       cld
 1:
        decq    %rdx
        jz      4f
-       lodsb
-       stosb
-       orb     %al,%al
+
+       movb    (%rdi),%al                      /* faster than lodsb+stosb */
+       movb    %al,(%rsi)
+       leaq    1(%rdi),%rdi
+       leaq    1(%rsi),%rsi
+       testb   %al,%al
        jnz     1b
 
        /* Success -- 0 byte reached */
index 16c5000..935d630 100644 (file)
@@ -9,24 +9,29 @@
 int
 main(int ac, char **av)
 {
+    const char *path;
     long long count = 0;
     long long max;
-    int j;
     struct stat st;
+    int j;
 
     printf("timing standard stat() syscall\n");
+    if (ac > 1)
+       path = av[1];
+    else
+       path = ".";
 
     start_timing();
     while (stop_timing(0, NULL) == 0) {
        for (j = 0; j < 100; ++j)
-           stat(".", &st);
+           stat(path, &st);
        count += 100;
     }
     max = count;
     start_timing();
     for (count = 0; count < max; count += 100) {
        for (j = 0; j < 100; ++j)
-           stat(".", &st);
+           stat(path, &st);
     }
     stop_timing(count, "stat()");
     return(0);