x86-64: remove locked instruction from switch_to()
authorBenjamin LaHaise <bcrl@kvack.org>
Sun, 11 Jan 2009 04:00:22 +0000 (23:00 -0500)
committerIngo Molnar <mingo@elte.hu>
Sun, 11 Jan 2009 04:05:33 +0000 (05:05 +0100)
Impact: micro-optimization

The patch below removes an unnecessary locked instruction from
switch_to().  TIF_FORK is only ever set in copy_thread() on initial
process creation, and gets cleared during the first scheduling of the
process.  As such, it is safe to use an unlocked test for the flag
within switch_to().

Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/include/asm/system.h
arch/x86/kernel/entry_64.S

index 8e626ea33a1a64d1565c10a0784200ef92ec9a31..fa47b1e6a86651872c98ce2e2c144f05ecda92d3 100644 (file)
@@ -96,15 +96,15 @@ do {                                                                        \
             "thread_return:\n\t"                                         \
             "movq %%gs:%P[pda_pcurrent],%%rsi\n\t"                       \
             "movq %P[thread_info](%%rsi),%%r8\n\t"                       \
-            LOCK_PREFIX "btr  %[tif_fork],%P[ti_flags](%%r8)\n\t"        \
             "movq %%rax,%%rdi\n\t"                                       \
-            "jc   ret_from_fork\n\t"                                     \
+            "testl  %[_tif_fork],%P[ti_flags](%%r8)\n\t"         \
+            "jnz   ret_from_fork\n\t"                                    \
             RESTORE_CONTEXT                                              \
             : "=a" (last)                                                \
             : [next] "S" (next), [prev] "D" (prev),                      \
               [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
               [ti_flags] "i" (offsetof(struct thread_info, flags)),      \
-              [tif_fork] "i" (TIF_FORK),                                 \
+              [_tif_fork] "i" (_TIF_FORK),                               \
               [thread_info] "i" (offsetof(struct task_struct, stack)),   \
               [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent))  \
             : "memory", "cc" __EXTRA_CLOBBER)
index e28c7a987793cbd25c628c7568fc15ca2c8c39f5..38dd37458e446c6e25f629859a36e64b5e7e67f2 100644 (file)
@@ -408,6 +408,8 @@ END(save_paranoid)
 ENTRY(ret_from_fork)
        DEFAULT_FRAME
 
+       LOCK ; btr $TIF_FORK,TI_flags(%r8)
+
        push kernel_eflags(%rip)
        CFI_ADJUST_CFA_OFFSET 8
        popf                                    # reset kernel eflags