Skip to contentSkip to conversation

i386: use C code for current_thread_info()

PATCH In review Chuck Ebbert 5 participants 6 messages Jun 11, 2006 – Jun 12, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i386: use C code for current_thread_info()

Using C code for current_thread_info() lets the compiler optimize it. With gcc 4.0.2, kernel is smaller:

text data bss dec hex filename

 3645212         555556  312024 4512792  44dc18 2.6.17-rc6-nb-post/vmlinux
 3647276         555556  312024 4514856  44e428 2.6.17-rc6-nb/vmlinux

-------
-2064

include/asm-i386/thread_info.h +4 -6
@@ -84,17 +84,15 @@ struct thread_info {
 #define init_stack		(init_thread_union.stack)
 
 
+/* how to get the current stack pointer from C */
+register unsigned long current_stack_pointer asm("esp") __attribute_used__;
+
 /* how to get the thread information struct from C */
 static inline struct thread_info *current_thread_info(void)
 {
-	struct thread_info *ti;
-	__asm__("andl %%esp,%0; ":"=r" (ti) : "0" (~(THREAD_SIZE - 1)));
-	return ti;
+	return (struct thread_info *)(current_stack_pointer & ~(THREAD_SIZE - 1));
 }
 
-/* how to get the current stack pointer from C */
-register unsigned long current_stack_pointer asm("esp") __attribute_used__;
-
 /* thread information allocation */
 #ifdef CONFIG_DEBUG_STACK_USAGE
 #define alloc_thread_info(tsk)					\
Signature · 1 line
Chuck
#1 lore raw
Quoted 2 lines · Chuck Ebbert

Using C code for current_thread_info() lets the compiler optimize it.

Ok, me likee. I just worry that this might break some older gcc version. Have you checked with gcc-3.2 or something?

We've had that "current_stack_pointer" thing for a long while, but we only use it in the irq-stack path (where it's really very incidental: the whole use of the "previous_esp" thing is only for the oops tracing. Maybe there was some reason (like gcc generating bad code) for not using it earlier?

(Admittedly, a more likely reason is probably just nobody looking at it, but it sounds like we should check it out anyway, just in case)

Linus

#2 lore raw
In reply to Chuck Ebbert
Quoted 10 lines

Using C code for current_thread_info() lets the compiler optimize it. With gcc 4.0.2, kernel is smaller:

text data bss dec hex filename

3645212         555556  312024 4512792  44dc18 2.6.17-rc6-nb-post/vmlinux
3647276         555556  312024 4514856  44e428 2.6.17-rc6-nb/vmlinux

-------
-2064

If possible, can you or someone post the results for x86_64?

Jan Engelhardt

#3 lore raw
Quoted 3 lines

If possible, can you or someone post the results for x86_64?

Ignore this request - 'was a asm-i386 change ^_^

#4 lore raw
In reply to Jan Engelhardt
Quoted 10 lines · Jan Engelhardt
Quoted 8 lines

Using C code for current_thread_info() lets the compiler optimize it. With gcc 4.0.2, kernel is smaller:

text data bss dec hex filename

3645212         555556  312024 4512792  44dc18 2.6.17-rc6-nb-post/vmlinux
3647276         555556  312024 4514856  44e428 2.6.17-rc6-nb/vmlinux

-------
-2064

If possible, can you or someone post the results for x86_64?

Patch is for i386, x86_64's current_thread_info() is already C.

Signature · 5 lines
Cheers,
Alistair.

Third year Computer Science undergraduate.
1F2 55 South Clerk Street, Edinburgh, UK.
#5 lore raw
Quoted 10 lines · Alistair John Strachan
Quoted 9 lines · Jan Engelhardt
Quoted 8 lines

Using C code for current_thread_info() lets the compiler optimize it. With gcc 4.0.2, kernel is smaller:

text data bss dec hex filename

3645212         555556  312024 4512792  44dc18 2.6.17-rc6-nb-post/vmlinux
3647276         555556  312024 4514856  44e428 2.6.17-rc6-nb/vmlinux

-------
-2064

Quoted 3 lines
Quoted 1 line

If possible, can you or someone post the results for x86_64?

Patch is for i386, x86_64's current_thread_info() is already C.

Actually read_pda() is inline assembly. But so far gcc/binutils don't support %gs references in the way the kernel needs it directly, so it has to stay this way.

-Andi