From 7a1c55c3807157e40e10fe442367265acd63e14c Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Thu, 15 Sep 2011 09:53:04 +0000 Subject: [PATCH] Microoptimize the return path for the fast syscalls on amd64. Arrange the code to have the fall-through path to follow the likely target. Do not use intermediate register to reload user %rsp. Proposed by: alc Reviewed by: alc, jhb Approved by: re (bz) MFC after: 2 weeks --- sys/amd64/amd64/exception.S | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sys/amd64/amd64/exception.S b/sys/amd64/amd64/exception.S index 9f0c69a09c9b..89ad638c7e3f 100644 --- a/sys/amd64/amd64/exception.S +++ b/sys/amd64/amd64/exception.S @@ -393,14 +393,8 @@ IDTVEC(fast_syscall) /* Check for and handle AST's on return to userland. */ movq PCPU(CURTHREAD),%rax testl $TDF_ASTPENDING | TDF_NEEDRESCHED,TD_FLAGS(%rax) - je 2f - sti - movq %rsp, %rdi - call ast - jmp 1b - - .align 16 -2: /* Restore preserved registers. */ + jne 2f + /* Restore preserved registers. */ MEXITCOUNT movq TF_RDI(%rsp),%rdi /* bonus; preserve arg 1 */ movq TF_RSI(%rsp),%rsi /* bonus: preserve arg 2 */ @@ -408,10 +402,16 @@ IDTVEC(fast_syscall) movq TF_RAX(%rsp),%rax /* return value 1 */ movq TF_RFLAGS(%rsp),%r11 /* original %rflags */ movq TF_RIP(%rsp),%rcx /* original %rip */ - movq TF_RSP(%rsp),%r9 /* user stack pointer */ - movq %r9,%rsp /* original %rsp */ + movq TF_RSP(%rsp),%rsp /* user stack pointer */ swapgs sysretq + +2: /* AST scheduled. */ + sti + movq %rsp,%rdi + call ast + jmp 1b + 3: /* Requested full context restore, use doreti for that. */ MEXITCOUNT jmp doreti