Author: mjg
Date: Thu Sep 20 13:29:43 2018
New Revision: 338828
URL: https://svnweb.freebsd.org/changeset/base/338828

Log:
  amd64: move fusufault after all users
  
  A lot of function have the following check:
          cmpq    %rax,%rdi                       /* verify address is valid */
          ja      fusufault
  
  The label is present earlier in kernel .text, which means this is a jump
  backwards. Absent any information in branch predictor, the cpu predicts it
  as taken. Since it is almost never taken in practice, this results in a
  completely avoidable misprediction.
  
  Move it past all consumers, so that it is predicted as not taken.
  
  Approved by:  re (kib)

Modified:
  head/sys/amd64/amd64/support.S

Modified: head/sys/amd64/amd64/support.S
==============================================================================
--- head/sys/amd64/amd64/support.S      Thu Sep 20 11:44:36 2018        
(r338827)
+++ head/sys/amd64/amd64/support.S      Thu Sep 20 13:29:43 2018        
(r338828)
@@ -755,16 +755,6 @@ ENTRY(fubyte_smap)
        ret
 END(fubyte_smap)
 
-       ALIGN_TEXT
-       /* Fault entry clears PSL.AC */
-fusufault:
-       movq    PCPU(CURPCB),%rcx
-       xorl    %eax,%eax
-       movq    %rax,PCB_ONFAULT(%rcx)
-       decq    %rax
-       POP_FRAME_POINTER
-       ret
-
 /*
  * Store a 64-bit word, a 32-bit word, a 16-bit word, or an 8-bit byte to
  * user memory.
@@ -915,6 +905,16 @@ ENTRY(subyte_smap)
        POP_FRAME_POINTER
        ret
 END(subyte_smap)
+
+       ALIGN_TEXT
+       /* Fault entry clears PSL.AC */
+fusufault:
+       movq    PCPU(CURPCB),%rcx
+       xorl    %eax,%eax
+       movq    %rax,PCB_ONFAULT(%rcx)
+       decq    %rax
+       POP_FRAME_POINTER
+       ret
 
 /*
  * copyinstr(from, to, maxlen, int *lencopied)
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to