i386: use C code for current_thread_info()
In-Reply-To: <[email protected]>
Quoted 6 lines · Emmanuel Fleury
Quoted 4 lines
Looking at the generated code, it seems the compiler just makes dumb choices and tends to recompute
current_thread_info()in unlikely code paths even when there is no register pressure. 4.0.2 makes better choices.What size with gcc 4.1.2 ? (just curiosity)
The 3.3 vs 4.0 comparisons were with two different configs, so only relative gain/loss with asm vs. C could be compared.
I downloaded gcc 4.1.1 and compared to 4.0.2 with the exact same config, since I was curious how much better it might be overall.
gcc 4.0.2:
text data bss dec hex filename
3645212 555556 312024 4512792 44dc18 2.6.17-rc6-nb-C/vmlinux
3647276 555556 312024 4514856 44e428 2.6.17-rc6-nb-asm/vmlinux
-2064
gcc 4.1.1:
text data bss dec hex filename
3614686 520416 311672 4446774 43da36 2.6.17-rc6-nb-C/vmlinux
3616942 520416 311672 4449030 43e306 2.6.17-rc6-nb-asm/vmlinux
-2256
Kernel code starts out ~30K bytes smaller with gcc 4.1 and using C for current_thread_info() helps even more than with 4.0. Nice...
Maybe a patch that enables C code for gcc 4.0+ would work, since on 3.3 the asm code is better?
Signature · 1 line
Chuck
Quoted 29 lines · Chuck Ebbert
In-Reply-To: <[email protected]>
Quoted 6 lines · Emmanuel Fleury
Quoted 4 lines
Looking at the generated code, it seems the compiler just makes dumb choices and tends to recompute
current_thread_info()in unlikely code paths even when there is no register pressure. 4.0.2 makes better choices.What size with gcc 4.1.2 ? (just curiosity)
The 3.3 vs 4.0 comparisons were with two different configs, so only relative gain/loss with asm vs. C could be compared.
I downloaded gcc 4.1.1 and compared to 4.0.2 with the exact same config, since I was curious how much better it might be overall.
gcc 4.0.2:
text data bss dec hex filename
3645212 555556 312024 4512792 44dc18 2.6.17-rc6-nb-C/vmlinux
3647276 555556 312024 4514856 44e428 2.6.17-rc6-nb-asm/vmlinux
-2064gcc 4.1.1:
text data bss dec hex filename
3614686 520416 311672 4446774 43da36 2.6.17-rc6-nb-C/vmlinux
3616942 520416 311672 4449030 43e306 2.6.17-rc6-nb-asm/vmlinux
-2256
Quoted 5 lines
Kernel code starts out ~30K bytes smaller with gcc 4.1 and using C for
current_thread_info()helps even more than with 4.0. Nice...Maybe a patch that enables C code for gcc 4.0+ would work, since on 3.3 the asm code is better?
No.
gcc 3.3 is still supported, and it's important that the kernel runs correctly when compiled with this compiler (implying workarounds for compiler bugs).
But for best performance, people should always use the latest gcc. (And if there was a case where usage of the latest gcc would give a
worse performance, that would be a bug in gcc and/or the kernel that should be reported.)
So unless there's a _really_ significant regression with older gcc versions, adding #ifdef's for such micro optimizations is not worth it.
Quoted 1 line
Chuck
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedHi,
Quoted 2 lines · Chuck Ebbert
Kernel code starts out ~30K bytes smaller with gcc 4.1 and using C for
current_thread_info()helps even more than with 4.0. Nice...
Especially since current_thread_info() often has an AGI stall (read:
severe pipeline stall) since it often cannot properly intermingle with nearby opcodes due to lack of suitable ones, e.g. at a function prologue.
mov $0xffffe000,%eax
and %esp,%eax
are fundamentally incompatible due to having to wait for the address generation before the "and" can be executed.
This shows up during profiling quite noticeably (IIRC 8 hits vs. 1 to 2 hits on other places), which really hurts since this function is used basically *everywhere*.
As such whatever optimization we can gain (e.g. the compiler merging multiple current_thread_info() invocations) is very worthwhile. I've come up with this C variant recently, too, but I didn't think it would make too much of a difference, however it seems it's really useful when going towards newer gcc versions.
Andreas Mohr
Signature · 4 lines
No programming skills!? Why not help translate many Linux applications! https://launchpad.ubuntu.com/rosetta (or alternatively buy nicely packaged Linux distros/OSS software to help support Linux developers creating shiny new things for you?)