Skip to contentSkip to conversation

x86-64: adjust ia32entry branches for better static prediction

PATCH In review Jan Beulich 4 participants 4 messages Oct 20, 2009 – Oct 26, 2009 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86-64: adjust ia32entry branches for better static prediction

Swap branch pairs so that the static branch prediction logic would consider the syscall-number-in-range case the taken path.

---
 arch/x86/ia32/ia32entry.S |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
arch/x86/ia32/ia32entry.S +9 -9
@@ -249,9 +249,9 @@ sysenter_tracesys:
 	call	syscall_trace_enter
 	LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
 	RESTORE_REST
-	cmpl	$(IA32_NR_syscalls-1),%eax
-	ja	int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
-	jmp	sysenter_do_call
+	cmpl	$IA32_NR_syscalls,%eax
+	jb	sysenter_do_call
+	jmp	int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
 	CFI_ENDPROC
 ENDPROC(ia32_sysenter_target)
 
@@ -368,9 +368,9 @@ cstar_tracesys:
 	LOAD_ARGS32 ARGOFFSET, 1  /* reload args from stack in case ptrace changed it */
 	RESTORE_REST
 	xchgl %ebp,%r9d
-	cmpl $(IA32_NR_syscalls-1),%eax
-	ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
-	jmp cstar_do_call
+	cmpl $IA32_NR_syscalls,%eax
+	jb cstar_do_call
+	jmp int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
 END(ia32_cstar_target)
 				
 ia32_badarg:
@@ -445,9 +445,9 @@ ia32_tracesys:			 
 	call syscall_trace_enter
 	LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
 	RESTORE_REST
-	cmpl $(IA32_NR_syscalls-1),%eax
-	ja  int_ret_from_sys_call	/* ia32_tracesys has set RAX(%rsp) */
-	jmp ia32_do_call
+	cmpl $IA32_NR_syscalls,%eax
+	jb ia32_do_call
+	jmp int_ret_from_sys_call	/* ia32_tracesys has set RAX(%rsp) */
 END(ia32_syscall)
 
 ia32_badsys:
#1 lore raw
Quoted 12 lines · Jan Beulich

Swap branch pairs so that the static branch prediction logic would consider the syscall-number-in-range case the taken path.

---
 arch/x86/ia32/ia32entry.S |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

arch/x86/ia32/ia32entry.S sysenter_tracesys: · line 255

Quoted 10 lines
arch/x86/ia32/ia32entry.S +3 -3
@@ -249,9 +249,9 @@ sysenter_tracesys:
 	call	syscall_trace_enter
 	LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
 	RESTORE_REST
-	cmpl	$(IA32_NR_syscalls-1),%eax
-	ja	int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
-	jmp	sysenter_do_call
+	cmpl	$IA32_NR_syscalls,%eax
+	jb	sysenter_do_call
+	jmp	int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
 	CFI_ENDPROC

on cmov enabled build, we could use cmov instruction to load eax with number that calls enosys_syscall(), to avoid loading -ENOSYS,RAX
and these branches...

#2 lore raw
Quoted 10 lines · Eric Dumazet
Quoted 10 lines
arch/x86/ia32/ia32entry.S +0 -3
@@ -249,9 +249,9 @@ sysenter_tracesys:
  	call	syscall_trace_enter
  	LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
  	RESTORE_REST
-	cmpl	$(IA32_NR_syscalls-1),%eax
-	ja	int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
-	jmp	sysenter_do_call
Quoted 9 lines

arch/x86/ia32/ia32entry.S sysenter_tracesys: · line 255

Quoted 4 lines
arch/x86/ia32/ia32entry.S +3 -0
+	cmpl	$IA32_NR_syscalls,%eax
+	jb	sysenter_do_call
+	jmp	int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
  	CFI_ENDPROC

on cmov enabled build, we could use cmov instruction to load eax with number that calls enosys_syscall(), to avoid loading -ENOSYS,RAX
and these branches...

It's x86-64, cmov is guaranteed.

-hpa

#3 lore raw
Quoted 21 lines · H. Peter Anvin
Quoted 10 lines · Eric Dumazet
Quoted 10 lines
arch/x86/ia32/ia32entry.S +0 -3
@@ -249,9 +249,9 @@ sysenter_tracesys:
  	call	syscall_trace_enter
  	LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
  	RESTORE_REST
-	cmpl	$(IA32_NR_syscalls-1),%eax
-	ja	int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
-	jmp	sysenter_do_call
Quoted 9 lines

arch/x86/ia32/ia32entry.S sysenter_tracesys: · line 255

Quoted 4 lines
arch/x86/ia32/ia32entry.S +3 -0
+	cmpl	$IA32_NR_syscalls,%eax
+	jb	sysenter_do_call
+	jmp	int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
  	CFI_ENDPROC

on cmov enabled build, we could use cmov instruction to load eax with number that calls enosys_syscall(), to avoid loading -ENOSYS,RAX
and these branches...

Quoted 1 line

It's x86-64, cmov is guaranteed.

But it's also not necessarily faster.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.